Passed
Push — master ( 0d0850...93133b )
by Morris
08:35
created
lib/private/Authentication/Listeners/RemoteWipeEmailListener.php 1 patch
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -39,133 +39,133 @@
 block discarded – undo
39 39
 
40 40
 class RemoteWipeEmailListener implements IEventListener {
41 41
 
42
-	/** @var IMailer */
43
-	private $mailer;
44
-
45
-	/** @var IUserManager */
46
-	private $userManager;
47
-
48
-	/** @var IL10N */
49
-	private $l10n;
50
-
51
-	/** @var ILogger */
52
-	private $logger;
53
-
54
-	public function __construct(IMailer $mailer,
55
-								IUserManager $userManager,
56
-								IL10nFactory $l10nFactory,
57
-								ILogger $logger) {
58
-		$this->mailer = $mailer;
59
-		$this->userManager = $userManager;
60
-		$this->l10n = $l10nFactory->get('core');
61
-		$this->logger = $logger;
62
-	}
63
-
64
-	/**
65
-	 * @param Event $event
66
-	 */
67
-	public function handle(Event $event): void {
68
-		if ($event instanceof RemoteWipeStarted) {
69
-			$uid = $event->getToken()->getUID();
70
-			$user = $this->userManager->get($uid);
71
-			if ($user === null) {
72
-				$this->logger->warning("not sending a wipe started email because user <$uid> does not exist (anymore)");
73
-				return;
74
-			}
75
-			if ($user->getEMailAddress() === null) {
76
-				$this->logger->info("not sending a wipe started email because user <$uid> has no email set");
77
-				return;
78
-			}
79
-
80
-			try {
81
-				$this->mailer->send(
82
-					$this->getWipingStartedMessage($event, $user)
83
-				);
84
-			} catch (Exception $e) {
85
-				$this->logger->logException($e, [
86
-					'message' => "Could not send remote wipe started email to <$uid>",
87
-					'level' => ILogger::ERROR,
88
-				]);
89
-			}
90
-		} else if ($event instanceof RemoteWipeFinished) {
91
-			$uid = $event->getToken()->getUID();
92
-			$user = $this->userManager->get($uid);
93
-			if ($user === null) {
94
-				$this->logger->warning("not sending a wipe finished email because user <$uid> does not exist (anymore)");
95
-				return;
96
-			}
97
-			if ($user->getEMailAddress() === null) {
98
-				$this->logger->info("not sending a wipe finished email because user <$uid> has no email set");
99
-				return;
100
-			}
101
-
102
-			try {
103
-				$this->mailer->send(
104
-					$this->getWipingFinishedMessage($event, $user)
105
-				);
106
-			} catch (Exception $e) {
107
-				$this->logger->logException($e, [
108
-					'message' => "Could not send remote wipe finished email to <$uid>",
109
-					'level' => ILogger::ERROR,
110
-				]);
111
-			}
112
-		}
113
-	}
114
-
115
-	private function getWipingStartedMessage(RemoteWipeStarted $event, IUser $user): IMessage {
116
-		$message = $this->mailer->createMessage();
117
-		$emailTemplate = $this->mailer->createEMailTemplate('auth.RemoteWipeStarted');
118
-		$plainHeading = $this->l10n->t('Wiping of device %s has started', [$event->getToken()->getName()]);
119
-		$htmlHeading = $this->l10n->t('Wiping of device »%s« has started', [$event->getToken()->getName()]);
120
-		$emailTemplate->setSubject(
121
-			$this->l10n->t(
122
-				'»%s« started remote wipe',
123
-				[
124
-					substr($event->getToken()->getName(), 0, 15)
125
-				]
126
-			)
127
-		);
128
-		$emailTemplate->addHeader();
129
-		$emailTemplate->addHeading(
130
-			$htmlHeading,
131
-			$plainHeading
132
-		);
133
-		$emailTemplate->addBodyText(
134
-			$this->l10n->t('Device or application »%s« has started the remote wipe process. You will receive another email once the process has finished', [$event->getToken()->getName()])
135
-		);
136
-		$emailTemplate->addFooter();
137
-		$message->setTo([$user->getEMailAddress()]);
138
-		$message->useTemplate($emailTemplate);
139
-
140
-		return $message;
141
-	}
142
-
143
-	private function getWipingFinishedMessage(RemoteWipeFinished $event, IUser $user): IMessage {
144
-		$message = $this->mailer->createMessage();
145
-		$emailTemplate = $this->mailer->createEMailTemplate('auth.RemoteWipeFinished');
146
-		$plainHeading = $this->l10n->t('Wiping of device %s has finished', [$event->getToken()->getName()]);
147
-		$htmlHeading = $this->l10n->t('Wiping of device »%s« has finished', [$event->getToken()->getName()]);
148
-		$emailTemplate->setSubject(
149
-			$this->l10n->t(
150
-				'»%s« finished remote wipe',
151
-				[
152
-					substr($event->getToken()->getName(), 0, 15)
153
-				]
154
-			)
155
-		);
156
-		$emailTemplate->addHeader();
157
-		$emailTemplate->addHeading(
158
-			$htmlHeading,
159
-			$plainHeading
160
-		);
161
-		$emailTemplate->addBodyText(
162
-			$this->l10n->t('Device or application »%s« has finished the remote wipe process.', [$event->getToken()->getName()])
163
-		);
164
-		$emailTemplate->addFooter();
165
-		$message->setTo([$user->getEMailAddress()]);
166
-		$message->useTemplate($emailTemplate);
167
-
168
-		return $message;
169
-	}
42
+    /** @var IMailer */
43
+    private $mailer;
44
+
45
+    /** @var IUserManager */
46
+    private $userManager;
47
+
48
+    /** @var IL10N */
49
+    private $l10n;
50
+
51
+    /** @var ILogger */
52
+    private $logger;
53
+
54
+    public function __construct(IMailer $mailer,
55
+                                IUserManager $userManager,
56
+                                IL10nFactory $l10nFactory,
57
+                                ILogger $logger) {
58
+        $this->mailer = $mailer;
59
+        $this->userManager = $userManager;
60
+        $this->l10n = $l10nFactory->get('core');
61
+        $this->logger = $logger;
62
+    }
63
+
64
+    /**
65
+     * @param Event $event
66
+     */
67
+    public function handle(Event $event): void {
68
+        if ($event instanceof RemoteWipeStarted) {
69
+            $uid = $event->getToken()->getUID();
70
+            $user = $this->userManager->get($uid);
71
+            if ($user === null) {
72
+                $this->logger->warning("not sending a wipe started email because user <$uid> does not exist (anymore)");
73
+                return;
74
+            }
75
+            if ($user->getEMailAddress() === null) {
76
+                $this->logger->info("not sending a wipe started email because user <$uid> has no email set");
77
+                return;
78
+            }
79
+
80
+            try {
81
+                $this->mailer->send(
82
+                    $this->getWipingStartedMessage($event, $user)
83
+                );
84
+            } catch (Exception $e) {
85
+                $this->logger->logException($e, [
86
+                    'message' => "Could not send remote wipe started email to <$uid>",
87
+                    'level' => ILogger::ERROR,
88
+                ]);
89
+            }
90
+        } else if ($event instanceof RemoteWipeFinished) {
91
+            $uid = $event->getToken()->getUID();
92
+            $user = $this->userManager->get($uid);
93
+            if ($user === null) {
94
+                $this->logger->warning("not sending a wipe finished email because user <$uid> does not exist (anymore)");
95
+                return;
96
+            }
97
+            if ($user->getEMailAddress() === null) {
98
+                $this->logger->info("not sending a wipe finished email because user <$uid> has no email set");
99
+                return;
100
+            }
101
+
102
+            try {
103
+                $this->mailer->send(
104
+                    $this->getWipingFinishedMessage($event, $user)
105
+                );
106
+            } catch (Exception $e) {
107
+                $this->logger->logException($e, [
108
+                    'message' => "Could not send remote wipe finished email to <$uid>",
109
+                    'level' => ILogger::ERROR,
110
+                ]);
111
+            }
112
+        }
113
+    }
114
+
115
+    private function getWipingStartedMessage(RemoteWipeStarted $event, IUser $user): IMessage {
116
+        $message = $this->mailer->createMessage();
117
+        $emailTemplate = $this->mailer->createEMailTemplate('auth.RemoteWipeStarted');
118
+        $plainHeading = $this->l10n->t('Wiping of device %s has started', [$event->getToken()->getName()]);
119
+        $htmlHeading = $this->l10n->t('Wiping of device »%s« has started', [$event->getToken()->getName()]);
120
+        $emailTemplate->setSubject(
121
+            $this->l10n->t(
122
+                '»%s« started remote wipe',
123
+                [
124
+                    substr($event->getToken()->getName(), 0, 15)
125
+                ]
126
+            )
127
+        );
128
+        $emailTemplate->addHeader();
129
+        $emailTemplate->addHeading(
130
+            $htmlHeading,
131
+            $plainHeading
132
+        );
133
+        $emailTemplate->addBodyText(
134
+            $this->l10n->t('Device or application »%s« has started the remote wipe process. You will receive another email once the process has finished', [$event->getToken()->getName()])
135
+        );
136
+        $emailTemplate->addFooter();
137
+        $message->setTo([$user->getEMailAddress()]);
138
+        $message->useTemplate($emailTemplate);
139
+
140
+        return $message;
141
+    }
142
+
143
+    private function getWipingFinishedMessage(RemoteWipeFinished $event, IUser $user): IMessage {
144
+        $message = $this->mailer->createMessage();
145
+        $emailTemplate = $this->mailer->createEMailTemplate('auth.RemoteWipeFinished');
146
+        $plainHeading = $this->l10n->t('Wiping of device %s has finished', [$event->getToken()->getName()]);
147
+        $htmlHeading = $this->l10n->t('Wiping of device »%s« has finished', [$event->getToken()->getName()]);
148
+        $emailTemplate->setSubject(
149
+            $this->l10n->t(
150
+                '»%s« finished remote wipe',
151
+                [
152
+                    substr($event->getToken()->getName(), 0, 15)
153
+                ]
154
+            )
155
+        );
156
+        $emailTemplate->addHeader();
157
+        $emailTemplate->addHeading(
158
+            $htmlHeading,
159
+            $plainHeading
160
+        );
161
+        $emailTemplate->addBodyText(
162
+            $this->l10n->t('Device or application »%s« has finished the remote wipe process.', [$event->getToken()->getName()])
163
+        );
164
+        $emailTemplate->addFooter();
165
+        $message->setTo([$user->getEMailAddress()]);
166
+        $message->useTemplate($emailTemplate);
167
+
168
+        return $message;
169
+    }
170 170
 
171 171
 }
Please login to merge, or discard this patch.
core/Application.php 2 patches
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -51,125 +51,125 @@
 block discarded – undo
51 51
  */
52 52
 class Application extends App {
53 53
 
54
-	public function __construct() {
55
-		parent::__construct('core');
56
-
57
-		$container = $this->getContainer();
58
-
59
-		$container->registerService('defaultMailAddress', function () {
60
-			return Util::getDefaultEmailAddress('lostpassword-noreply');
61
-		});
62
-
63
-		$server = $container->getServer();
64
-		/** @var IEventDispatcher $eventDispatcher */
65
-		$eventDispatcher = $server->query(IEventDispatcher::class);
66
-
67
-		$notificationManager = $server->getNotificationManager();
68
-		$notificationManager->registerNotifier(function () use ($server) {
69
-			return new RemoveLinkSharesNotifier(
70
-				$server->getL10NFactory()
71
-			);
72
-		}, function () {
73
-			return [
74
-				'id' => 'core',
75
-				'name' => 'core',
76
-			];
77
-		});
78
-		$notificationManager->registerNotifier(function () use ($server) {
79
-			return $server->query(AuthenticationNotifier::class);
80
-		}, function () {
81
-			return [
82
-				'id' => 'auth',
83
-				'name' => 'authentication notifier',
84
-			];
85
-		});
86
-
87
-		$eventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
88
-			function (GenericEvent $event) use ($container) {
89
-				/** @var MissingIndexInformation $subject */
90
-				$subject = $event->getSubject();
91
-
92
-				$schema = new SchemaWrapper($container->query(IDBConnection::class));
93
-
94
-				if ($schema->hasTable('share')) {
95
-					$table = $schema->getTable('share');
96
-
97
-					if (!$table->hasIndex('share_with_index')) {
98
-						$subject->addHintForMissingSubject($table->getName(), 'share_with_index');
99
-					}
100
-					if (!$table->hasIndex('parent_index')) {
101
-						$subject->addHintForMissingSubject($table->getName(), 'parent_index');
102
-					}
103
-					if (!$table->hasIndex('owner_index')) {
104
-						$subject->addHintForMissingSubject($table->getName(), 'owner_index');
105
-					}
106
-					if (!$table->hasIndex('initiator_index')) {
107
-						$subject->addHintForMissingSubject($table->getName(), 'initiator_index');
108
-					}
109
-				}
110
-
111
-				if ($schema->hasTable('filecache')) {
112
-					$table = $schema->getTable('filecache');
113
-
114
-					if (!$table->hasIndex('fs_mtime')) {
115
-						$subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
116
-					}
117
-				}
118
-
119
-				if ($schema->hasTable('twofactor_providers')) {
120
-					$table = $schema->getTable('twofactor_providers');
121
-
122
-					if (!$table->hasIndex('twofactor_providers_uid')) {
123
-						$subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
124
-					}
125
-				}
126
-
127
-				if ($schema->hasTable('login_flow_v2')) {
128
-					$table = $schema->getTable('login_flow_v2');
129
-
130
-					if (!$table->hasIndex('poll_token')) {
131
-						$subject->addHintForMissingSubject($table->getName(), 'poll_token');
132
-					}
133
-					if (!$table->hasIndex('login_token')) {
134
-						$subject->addHintForMissingSubject($table->getName(), 'login_token');
135
-					}
136
-					if (!$table->hasIndex('timestamp')) {
137
-						$subject->addHintForMissingSubject($table->getName(), 'timestamp');
138
-					}
139
-				}
140
-
141
-				if ($schema->hasTable('whats_new')) {
142
-					$table = $schema->getTable('whats_new');
143
-
144
-					if (!$table->hasIndex('version')) {
145
-						$subject->addHintForMissingSubject($table->getName(), 'version');
146
-					}
147
-				}
148
-
149
-				if ($schema->hasTable('cards')) {
150
-					$table = $schema->getTable('cards');
151
-
152
-					if (!$table->hasIndex('cards_abid')) {
153
-						$subject->addHintForMissingSubject($table->getName(), 'cards_abid');
154
-					}
155
-				}
156
-
157
-				if ($schema->hasTable('cards_properties')) {
158
-					$table = $schema->getTable('cards_properties');
159
-
160
-					if (!$table->hasIndex('cards_prop_abid')) {
161
-						$subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid');
162
-					}
163
-				}
164
-			}
165
-		);
166
-
167
-		$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
168
-		$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
169
-		$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
170
-		$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
171
-		$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
172
-		$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
173
-	}
54
+    public function __construct() {
55
+        parent::__construct('core');
56
+
57
+        $container = $this->getContainer();
58
+
59
+        $container->registerService('defaultMailAddress', function () {
60
+            return Util::getDefaultEmailAddress('lostpassword-noreply');
61
+        });
62
+
63
+        $server = $container->getServer();
64
+        /** @var IEventDispatcher $eventDispatcher */
65
+        $eventDispatcher = $server->query(IEventDispatcher::class);
66
+
67
+        $notificationManager = $server->getNotificationManager();
68
+        $notificationManager->registerNotifier(function () use ($server) {
69
+            return new RemoveLinkSharesNotifier(
70
+                $server->getL10NFactory()
71
+            );
72
+        }, function () {
73
+            return [
74
+                'id' => 'core',
75
+                'name' => 'core',
76
+            ];
77
+        });
78
+        $notificationManager->registerNotifier(function () use ($server) {
79
+            return $server->query(AuthenticationNotifier::class);
80
+        }, function () {
81
+            return [
82
+                'id' => 'auth',
83
+                'name' => 'authentication notifier',
84
+            ];
85
+        });
86
+
87
+        $eventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
88
+            function (GenericEvent $event) use ($container) {
89
+                /** @var MissingIndexInformation $subject */
90
+                $subject = $event->getSubject();
91
+
92
+                $schema = new SchemaWrapper($container->query(IDBConnection::class));
93
+
94
+                if ($schema->hasTable('share')) {
95
+                    $table = $schema->getTable('share');
96
+
97
+                    if (!$table->hasIndex('share_with_index')) {
98
+                        $subject->addHintForMissingSubject($table->getName(), 'share_with_index');
99
+                    }
100
+                    if (!$table->hasIndex('parent_index')) {
101
+                        $subject->addHintForMissingSubject($table->getName(), 'parent_index');
102
+                    }
103
+                    if (!$table->hasIndex('owner_index')) {
104
+                        $subject->addHintForMissingSubject($table->getName(), 'owner_index');
105
+                    }
106
+                    if (!$table->hasIndex('initiator_index')) {
107
+                        $subject->addHintForMissingSubject($table->getName(), 'initiator_index');
108
+                    }
109
+                }
110
+
111
+                if ($schema->hasTable('filecache')) {
112
+                    $table = $schema->getTable('filecache');
113
+
114
+                    if (!$table->hasIndex('fs_mtime')) {
115
+                        $subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
116
+                    }
117
+                }
118
+
119
+                if ($schema->hasTable('twofactor_providers')) {
120
+                    $table = $schema->getTable('twofactor_providers');
121
+
122
+                    if (!$table->hasIndex('twofactor_providers_uid')) {
123
+                        $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
124
+                    }
125
+                }
126
+
127
+                if ($schema->hasTable('login_flow_v2')) {
128
+                    $table = $schema->getTable('login_flow_v2');
129
+
130
+                    if (!$table->hasIndex('poll_token')) {
131
+                        $subject->addHintForMissingSubject($table->getName(), 'poll_token');
132
+                    }
133
+                    if (!$table->hasIndex('login_token')) {
134
+                        $subject->addHintForMissingSubject($table->getName(), 'login_token');
135
+                    }
136
+                    if (!$table->hasIndex('timestamp')) {
137
+                        $subject->addHintForMissingSubject($table->getName(), 'timestamp');
138
+                    }
139
+                }
140
+
141
+                if ($schema->hasTable('whats_new')) {
142
+                    $table = $schema->getTable('whats_new');
143
+
144
+                    if (!$table->hasIndex('version')) {
145
+                        $subject->addHintForMissingSubject($table->getName(), 'version');
146
+                    }
147
+                }
148
+
149
+                if ($schema->hasTable('cards')) {
150
+                    $table = $schema->getTable('cards');
151
+
152
+                    if (!$table->hasIndex('cards_abid')) {
153
+                        $subject->addHintForMissingSubject($table->getName(), 'cards_abid');
154
+                    }
155
+                }
156
+
157
+                if ($schema->hasTable('cards_properties')) {
158
+                    $table = $schema->getTable('cards_properties');
159
+
160
+                    if (!$table->hasIndex('cards_prop_abid')) {
161
+                        $subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid');
162
+                    }
163
+                }
164
+            }
165
+        );
166
+
167
+        $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
168
+        $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
169
+        $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
170
+        $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
171
+        $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
172
+        $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
173
+    }
174 174
 
175 175
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 
57 57
 		$container = $this->getContainer();
58 58
 
59
-		$container->registerService('defaultMailAddress', function () {
59
+		$container->registerService('defaultMailAddress', function() {
60 60
 			return Util::getDefaultEmailAddress('lostpassword-noreply');
61 61
 		});
62 62
 
@@ -65,19 +65,19 @@  discard block
 block discarded – undo
65 65
 		$eventDispatcher = $server->query(IEventDispatcher::class);
66 66
 
67 67
 		$notificationManager = $server->getNotificationManager();
68
-		$notificationManager->registerNotifier(function () use ($server) {
68
+		$notificationManager->registerNotifier(function() use ($server) {
69 69
 			return new RemoveLinkSharesNotifier(
70 70
 				$server->getL10NFactory()
71 71
 			);
72
-		}, function () {
72
+		}, function() {
73 73
 			return [
74 74
 				'id' => 'core',
75 75
 				'name' => 'core',
76 76
 			];
77 77
 		});
78
-		$notificationManager->registerNotifier(function () use ($server) {
78
+		$notificationManager->registerNotifier(function() use ($server) {
79 79
 			return $server->query(AuthenticationNotifier::class);
80
-		}, function () {
80
+		}, function() {
81 81
 			return [
82 82
 				'id' => 'auth',
83 83
 				'name' => 'authentication notifier',
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 		});
86 86
 
87 87
 		$eventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
88
-			function (GenericEvent $event) use ($container) {
88
+			function(GenericEvent $event) use ($container) {
89 89
 				/** @var MissingIndexInformation $subject */
90 90
 				$subject = $event->getSubject();
91 91
 
Please login to merge, or discard this patch.