Provider.php 2.5 KB

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