2
2
/**
3
3
* sysPass
4
4
*
5
- * @author nuxsmin
6
- * @link https://syspass.org
5
+ * @author nuxsmin
6
+ * @link https://syspass.org
7
7
* @copyright 2012-2019, Rubén Domínguez nuxsmin@$syspass.org
8
8
*
9
9
* This file is part of sysPass.
24
24
25
25
namespace SP \Modules \Web \Controllers ;
26
26
27
+ use Defuse \Crypto \Exception \CryptoException ;
28
+ use Defuse \Crypto \Exception \EnvironmentIsBrokenException ;
29
+ use DI \DependencyException ;
30
+ use DI \NotFoundException ;
31
+ use Exception ;
27
32
use SP \Core \Events \Event ;
28
33
use SP \Core \Events \EventMessage ;
34
+ use SP \Core \Exceptions \ConstraintException ;
35
+ use SP \Core \Exceptions \InvalidArgumentException ;
36
+ use SP \Core \Exceptions \NoSuchPropertyException ;
37
+ use SP \Core \Exceptions \QueryException ;
29
38
use SP \Core \Messages \MailMessage ;
30
39
use SP \Http \JsonResponse ;
31
40
use SP \Modules \Web \Controllers \Traits \JsonTrait ;
35
44
use SP \Modules \Web \Plugins \Authenticator \Services \AuthenticatorService ;
36
45
use SP \Modules \Web \Plugins \Authenticator \Util \PluginContext ;
37
46
use SP \Plugin \PluginManager ;
47
+ use SP \Repositories \NoSuchItemException ;
38
48
use SP \Repositories \Track \TrackRequest ;
39
49
use SP \Services \Mail \MailService ;
50
+ use SP \Services \ServiceException ;
40
51
use SP \Services \Track \TrackService ;
41
52
use SP \Services \User \UserLoginResponse ;
42
53
@@ -119,7 +130,7 @@ public function saveAction()
119
130
JsonResponse::JSON_ERROR ,
120
131
$ e ->getMessage ()
121
132
);
122
- } catch (\ Exception $ e ) {
133
+ } catch (Exception $ e ) {
123
134
processException ($ e );
124
135
125
136
$ this ->eventDispatcher ->notifyEvent ('exception ' , new Event ($ e ));
@@ -139,7 +150,7 @@ private function addTracking()
139
150
{
140
151
try {
141
152
$ this ->trackService ->add ($ this ->trackRequest );
142
- } catch (\ Exception $ e ) {
153
+ } catch (Exception $ e ) {
143
154
processException ($ e );
144
155
}
145
156
}
@@ -149,7 +160,7 @@ private function addTracking()
149
160
* @param AuthenticatorData $authenticatorData
150
161
*
151
162
* @return bool
152
- * @throws \ Exception
163
+ * @throws Exception
153
164
*/
154
165
private function checkRecoveryCode ($ pin , AuthenticatorData $ authenticatorData )
155
166
{
@@ -172,7 +183,7 @@ private function checkRecoveryCode($pin, AuthenticatorData $authenticatorData)
172
183
* @param AuthenticatorData $authenticatorData
173
184
*
174
185
* @return bool
175
- * @throws \ Exception
186
+ * @throws Exception
176
187
*/
177
188
private function checkPin ($ pin , AuthenticatorData $ authenticatorData )
178
189
{
@@ -193,13 +204,13 @@ private function checkPin($pin, AuthenticatorData $authenticatorData)
193
204
* @param AuthenticatorData $authenticatorData
194
205
*
195
206
* @return bool
196
- * @throws \Defuse\Crypto\Exception\ CryptoException
197
- * @throws \Defuse\Crypto\Exception\ EnvironmentIsBrokenException
198
- * @throws \SP\Core\Exceptions\ ConstraintException
199
- * @throws \SP\Core\Exceptions\ NoSuchPropertyException
200
- * @throws \SP\Core\Exceptions\ QueryException
201
- * @throws \SP\Repositories\ NoSuchItemException
202
- * @throws \SP\Services\ ServiceException
207
+ * @throws CryptoException
208
+ * @throws EnvironmentIsBrokenException
209
+ * @throws ConstraintException
210
+ * @throws NoSuchPropertyException
211
+ * @throws QueryException
212
+ * @throws NoSuchItemException
213
+ * @throws ServiceException
203
214
*/
204
215
private function save2FAStatus (AuthenticatorData $ authenticatorData )
205
216
{
@@ -216,6 +227,15 @@ private function save2FAStatus(AuthenticatorData $authenticatorData)
216
227
217
228
$ this ->plugin ->saveData ($ this ->userData ->getId (), $ authenticatorData );
218
229
230
+ $ this ->eventDispatcher ->notifyEvent ('authenticator.edit.enable ' ,
231
+ new Event ($ this , EventMessage::factory ()
232
+ ->addDescription (_t ('authenticator ' , '2FA Enabled ' ))
233
+ ->addDetail (__ ('User ' ), $ this ->userData ->getLogin ())
234
+ ->addExtra ('userId ' , $ this ->userData ->getId ())
235
+ ->addExtra ('expireDays ' , $ authenticatorData ->getExpireDays ())
236
+ )
237
+ );
238
+
219
239
return $ this ->returnJsonResponse (
220
240
JsonResponse::JSON_SUCCESS ,
221
241
_t ('authenticator ' , '2FA Enabled ' )
@@ -227,6 +247,14 @@ private function save2FAStatus(AuthenticatorData $authenticatorData)
227
247
) {
228
248
$ this ->authenticatorService ->deletePluginUserData ($ this ->userData ->getId ());
229
249
250
+ $ this ->eventDispatcher ->notifyEvent ('authenticator.edit.disable ' ,
251
+ new Event ($ this , EventMessage::factory ()
252
+ ->addDescription (_t ('authenticator ' , '2FA Disabled ' ))
253
+ ->addDetail (__ ('User ' ), $ this ->userData ->getLogin ())
254
+ ->addExtra ('userId ' , $ this ->userData ->getId ())
255
+ )
256
+ );
257
+
230
258
return $ this ->returnJsonResponse (
231
259
JsonResponse::JSON_SUCCESS ,
232
260
_t ('authenticator ' , '2FA Disabled ' )
@@ -298,7 +326,7 @@ public function checkCodeAction()
298
326
JsonResponse::JSON_ERROR ,
299
327
$ e ->getMessage ()
300
328
);
301
- } catch (\ Exception $ e ) {
329
+ } catch (Exception $ e ) {
302
330
processException ($ e );
303
331
304
332
$ this ->eventDispatcher ->notifyEvent ('exception ' , new Event ($ e ));
@@ -335,13 +363,21 @@ private function sendResetEmail(AuthenticatorData $authenticatorData)
335
363
$ this ->userData ->getEmail (),
336
364
$ message );
337
365
366
+ $ this ->eventDispatcher ->notifyEvent ('authenticator.send.recoverycode ' ,
367
+ new Event ($ this , EventMessage::factory ()
368
+ ->addDescription (_t ('authenticator ' , '2FA Code Recovery ' ))
369
+ ->addDetail (__ ('User ' ), $ this ->userData ->getLogin ())
370
+ ->addExtra ('userId ' , $ this ->userData ->getId ())
371
+ )
372
+ );
373
+
338
374
return true ;
339
375
}
340
376
341
377
return false ;
342
378
} catch (AuthenticatorException $ e ) {
343
379
throw $ e ;
344
- } catch (\ Exception $ e ) {
380
+ } catch (Exception $ e ) {
345
381
processException ($ e );
346
382
347
383
$ this ->eventDispatcher ->notifyEvent ('exception ' , new Event ($ e ));
@@ -367,7 +403,10 @@ public function showRecoveryCodesAction()
367
403
if (count ($ codes ) > 0 ) {
368
404
$ this ->eventDispatcher ->notifyEvent ('authenticator.show.recoverycode ' ,
369
405
new Event ($ this , EventMessage::factory ()
370
- ->addDescription (_t ('authenticator ' , 'Recovery codes displayed ' )))
406
+ ->addDescription (_t ('authenticator ' , 'Recovery codes displayed ' ))
407
+ ->addDetail (__ ('User ' ), $ this ->userData ->getLogin ())
408
+ ->addExtra ('userId ' , $ this ->userData ->getId ())
409
+ )
371
410
);
372
411
373
412
return $ this ->returnJsonResponseData ($ codes );
@@ -377,7 +416,7 @@ public function showRecoveryCodesAction()
377
416
_t ('authenticator ' , 'There aren \'t any recovery codes available ' )
378
417
);
379
418
}
380
- } catch (\ Exception $ e ) {
419
+ } catch (Exception $ e ) {
381
420
processException ($ e );
382
421
383
422
$ this ->eventDispatcher ->notifyEvent ('exception ' , new Event ($ e ));
@@ -398,9 +437,9 @@ public function checkVersionAction()
398
437
}
399
438
400
439
/**
401
- * @throws \DI\ DependencyException
402
- * @throws \DI\ NotFoundException
403
- * @throws \SP\Core\Exceptions\ InvalidArgumentException
440
+ * @throws DependencyException
441
+ * @throws NotFoundException
442
+ * @throws InvalidArgumentException
404
443
*/
405
444
protected function initialize ()
406
445
{
0 commit comments