|
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\Listeners; |
|
27
|
|
|
|
|
28
|
|
|
use OC\Authentication\Events\ARemoteWipeEvent; |
|
29
|
|
|
use OC\Authentication\Events\RemoteWipeFinished; |
|
30
|
|
|
use OC\Authentication\Events\RemoteWipeStarted; |
|
31
|
|
|
use OC\Authentication\Token\IToken; |
|
32
|
|
|
use OCP\AppFramework\Utility\ITimeFactory; |
|
33
|
|
|
use OCP\EventDispatcher\Event; |
|
34
|
|
|
use OCP\EventDispatcher\IEventListener; |
|
35
|
|
|
use OCP\Notification\IManager as INotificationManager; |
|
36
|
|
|
|
|
37
|
|
|
class RemoteWipeNotificationsListener implements IEventListener { |
|
38
|
|
|
|
|
39
|
|
|
/** @var INotificationManager */ |
|
40
|
|
|
private $notificationManager; |
|
41
|
|
|
|
|
42
|
|
|
/** @var ITimeFactory */ |
|
43
|
|
|
private $timeFactory; |
|
44
|
|
|
|
|
45
|
|
|
public function __construct(INotificationManager $notificationManager, |
|
46
|
|
|
ITimeFactory $timeFactory) { |
|
47
|
|
|
$this->notificationManager = $notificationManager; |
|
48
|
|
|
$this->timeFactory = $timeFactory; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function handle(Event $event): void { |
|
52
|
|
|
if ($event instanceof RemoteWipeStarted) { |
|
53
|
|
|
$this->sendNotification('remote_wipe_start', $event->getToken()); |
|
54
|
|
|
} else if ($event instanceof RemoteWipeFinished) { |
|
55
|
|
|
$this->sendNotification('remote_wipe_finish', $event->getToken()); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
private function sendNotification(string $event, IToken $token): void { |
|
60
|
|
|
$notification = $this->notificationManager->createNotification(); |
|
61
|
|
|
$notification->setApp('auth') |
|
62
|
|
|
->setUser($token->getUID()) |
|
63
|
|
|
->setDateTime($this->timeFactory->getDateTime()) |
|
64
|
|
|
->setObject('token', $token->getId()) |
|
65
|
|
|
->setSubject($event, [ |
|
66
|
|
|
'name' => $token->getName(), |
|
67
|
|
|
]); |
|
68
|
|
|
$this->notificationManager->notify($notification); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|