You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Provider.php 2.3KB

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