SecurityProvider.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\Activity;
  8. use OCP\Activity\Exceptions\UnknownActivityException;
  9. use OCP\Activity\IEvent;
  10. use OCP\Activity\IManager;
  11. use OCP\Activity\IProvider;
  12. use OCP\IURLGenerator;
  13. use OCP\L10N\IFactory as L10nFactory;
  14. class SecurityProvider implements IProvider {
  15. public function __construct(
  16. private L10nFactory $l10n,
  17. private IURLGenerator $urlGenerator,
  18. private IManager $activityManager,
  19. ) {
  20. }
  21. public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
  22. if ($event->getType() !== 'security') {
  23. throw new UnknownActivityException();
  24. }
  25. $l = $this->l10n->get('settings', $language);
  26. switch ($event->getSubject()) {
  27. case 'twofactor_success':
  28. $params = $event->getSubjectParameters();
  29. $event->setParsedSubject($l->t('You successfully logged in using two-factor authentication (%1$s)', [
  30. $params['provider'],
  31. ]));
  32. if ($this->activityManager->getRequirePNG()) {
  33. $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png')));
  34. } else {
  35. $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg')));
  36. }
  37. break;
  38. case 'twofactor_failed':
  39. $params = $event->getSubjectParameters();
  40. $event->setParsedSubject($l->t('A login attempt using two-factor authentication failed (%1$s)', [
  41. $params['provider'],
  42. ]));
  43. if ($this->activityManager->getRequirePNG()) {
  44. $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png')));
  45. } else {
  46. $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg')));
  47. }
  48. break;
  49. case 'remote_wipe_start':
  50. $params = $event->getSubjectParameters();
  51. $event->setParsedSubject($l->t('Remote wipe was started on %1$s', [
  52. $params['name'],
  53. ]));
  54. if ($this->activityManager->getRequirePNG()) {
  55. $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.png')));
  56. } else {
  57. $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.svg')));
  58. }
  59. break;
  60. case 'remote_wipe_finish':
  61. $params = $event->getSubjectParameters();
  62. $event->setParsedSubject($l->t('Remote wipe has finished on %1$s', [
  63. $params['name'],
  64. ]));
  65. if ($this->activityManager->getRequirePNG()) {
  66. $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.png')));
  67. } else {
  68. $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.svg')));
  69. }
  70. break;
  71. default:
  72. throw new UnknownActivityException();
  73. }
  74. return $event;
  75. }
  76. }