1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @copyright 2019 Christoph Wurst <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @author 2019 Christoph Wurst <[email protected]> |
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 OC\Authentication\Notifications; |
27
|
|
|
|
28
|
|
|
use InvalidArgumentException; |
29
|
|
|
use OCP\L10N\IFactory as IL10nFactory; |
30
|
|
|
use OCP\Notification\INotification; |
31
|
|
|
use OCP\Notification\INotifier; |
32
|
|
|
|
33
|
|
|
class Notifier implements INotifier { |
34
|
|
|
|
35
|
|
|
/** @var IL10nFactory */ |
36
|
|
|
private $factory; |
37
|
|
|
|
38
|
|
|
public function __construct(IL10nFactory $l10nFactory) { |
39
|
|
|
$this->factory = $l10nFactory; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @inheritDoc |
44
|
|
|
*/ |
45
|
|
|
public function prepare(INotification $notification, string $languageCode): INotification { |
46
|
|
|
if ($notification->getApp() !== 'auth') { |
47
|
|
|
// Not my app => throw |
48
|
|
|
throw new InvalidArgumentException(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// Read the language from the notification |
52
|
|
|
$l = $this->factory->get('lib', $languageCode); |
53
|
|
|
|
54
|
|
|
switch ($notification->getSubject()) { |
55
|
|
|
case 'remote_wipe_start': |
56
|
|
|
$notification->setParsedSubject( |
57
|
|
|
$l->t('Remote wipe started') |
58
|
|
|
)->setParsedMessage( |
59
|
|
|
$l->t('A remote wipe was started on device %s', $notification->getSubjectParameters()) |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
return $notification; |
63
|
|
|
case 'remote_wipe_finish': |
64
|
|
|
$notification->setParsedSubject( |
65
|
|
|
$l->t('Remote wipe finished') |
66
|
|
|
)->setParsedMessage( |
67
|
|
|
$l->t('The remote wipe on %s has finished', $notification->getSubjectParameters()) |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
return $notification; |
71
|
|
|
default: |
72
|
|
|
// Unknown subject => Unknown notification => throw |
73
|
|
|
throw new InvalidArgumentException(); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Identifier of the notifier, only use [a-z0-9_] |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
* @since 17.0.0 |
82
|
|
|
*/ |
83
|
|
|
public function getID(): string { |
84
|
|
|
return 'auth'; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Human readable name describing the notifier |
89
|
|
|
* |
90
|
|
|
* @return string |
91
|
|
|
* @since 17.0.0 |
92
|
|
|
*/ |
93
|
|
|
public function getName(): string { |
94
|
|
|
return $this->factory->get('lib')->t('Authentication'); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|