|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2017 Roger Szabo <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Joas Schilling <[email protected]> |
|
6
|
|
|
* @author Roeland Jago Douma <[email protected]> |
|
7
|
|
|
* @author Roger Szabo <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* @license GNU AGPL version 3 or any later version |
|
10
|
|
|
* |
|
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
14
|
|
|
* License, or (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU Affero General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace OCA\User_LDAP\Notification; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
use OCP\L10N\IFactory; |
|
30
|
|
|
use OCP\Notification\INotification; |
|
31
|
|
|
use OCP\Notification\INotifier; |
|
32
|
|
|
|
|
33
|
|
|
class Notifier implements INotifier { |
|
34
|
|
|
|
|
35
|
|
|
/** @var IFactory */ |
|
36
|
|
|
protected $l10nFactory; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param IFactory $l10nFactory |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(\OCP\L10N\IFactory $l10nFactory) { |
|
42
|
|
|
$this->l10nFactory = $l10nFactory; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Identifier of the notifier, only use [a-z0-9_] |
|
47
|
|
|
* |
|
48
|
|
|
* @return string |
|
49
|
|
|
* @since 17.0.0 |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getID(): string { |
|
52
|
|
|
return 'user_ldap'; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Human readable name describing the notifier |
|
57
|
|
|
* |
|
58
|
|
|
* @return string |
|
59
|
|
|
* @since 17.0.0 |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getName(): string { |
|
62
|
|
|
return $this->l10nFactory->get('user_ldap')->t('LDAP User backend'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param INotification $notification |
|
67
|
|
|
* @param string $languageCode The code of the language that should be used to prepare the notification |
|
68
|
|
|
* @return INotification |
|
69
|
|
|
* @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
70
|
|
|
*/ |
|
71
|
|
|
public function prepare(INotification $notification, string $languageCode): INotification { |
|
72
|
|
|
if ($notification->getApp() !== 'user_ldap') { |
|
73
|
|
|
// Not my app => throw |
|
74
|
|
|
throw new \InvalidArgumentException(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
// Read the language from the notification |
|
78
|
|
|
$l = $this->l10nFactory->get('user_ldap', $languageCode); |
|
79
|
|
|
|
|
80
|
|
|
switch ($notification->getSubject()) { |
|
81
|
|
|
// Deal with known subjects |
|
82
|
|
|
case 'pwd_exp_warn_days': |
|
83
|
|
|
$params = $notification->getSubjectParameters(); |
|
84
|
|
|
$days = (int) $params[0]; |
|
85
|
|
|
if ($days === 2) { |
|
86
|
|
|
$notification->setParsedSubject($l->t('Your password will expire tomorrow.')); |
|
87
|
|
|
} else if ($days === 1) { |
|
88
|
|
|
$notification->setParsedSubject($l->t('Your password will expire today.')); |
|
89
|
|
|
} else { |
|
90
|
|
|
$notification->setParsedSubject($l->n( |
|
91
|
|
|
'Your password will expire within %n day.', |
|
92
|
|
|
'Your password will expire within %n days.', |
|
93
|
|
|
$days |
|
94
|
|
|
)); |
|
95
|
|
|
} |
|
96
|
|
|
return $notification; |
|
97
|
|
|
|
|
98
|
|
|
default: |
|
99
|
|
|
// Unknown subject => Unknown notification => throw |
|
100
|
|
|
throw new \InvalidArgumentException(); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|