1
0

Provider.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Christoph Wurst <christoph@winzerhof-wurst.at>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\TwoFactorBackupCodes\Activity;
  25. use InvalidArgumentException;
  26. use OCP\Activity\IEvent;
  27. use OCP\Activity\IManager;
  28. use OCP\Activity\IProvider;
  29. use OCP\IURLGenerator;
  30. use OCP\L10N\IFactory as L10nFactory;
  31. class Provider implements IProvider {
  32. /** @var L10nFactory */
  33. private $l10n;
  34. /** @var IURLGenerator */
  35. private $urlGenerator;
  36. /** @var IManager */
  37. private $activityManager;
  38. /**
  39. * @param L10nFactory $l10n
  40. * @param IURLGenerator $urlGenerator
  41. * @param IManager $activityManager
  42. */
  43. public function __construct(L10nFactory $l10n, IURLGenerator $urlGenerator, IManager $activityManager) {
  44. $this->urlGenerator = $urlGenerator;
  45. $this->activityManager = $activityManager;
  46. $this->l10n = $l10n;
  47. }
  48. public function parse($language, IEvent $event, IEvent $previousEvent = null) {
  49. if ($event->getApp() !== 'twofactor_backupcodes') {
  50. throw new InvalidArgumentException();
  51. }
  52. $l = $this->l10n->get('twofactor_backupcodes', $language);
  53. switch ($event->getSubject()) {
  54. case 'codes_generated':
  55. $event->setParsedSubject($l->t('You created two-factor backup codes for your account'));
  56. if ($this->activityManager->getRequirePNG()) {
  57. $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png')));
  58. } else {
  59. $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg')));
  60. }
  61. break;
  62. default:
  63. throw new InvalidArgumentException();
  64. }
  65. return $event;
  66. }
  67. }