1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Auth\Handlers; |
6
|
|
|
|
7
|
|
|
use Illuminate\Auth\Events\Login; |
8
|
|
|
use Illuminate\Auth\Events\Lockout; |
9
|
|
|
use Illuminate\Auth\Events\Registered; |
10
|
|
|
use Illuminate\Contracts\Events\Dispatcher; |
11
|
|
|
use Illuminate\Contracts\Container\Container; |
12
|
|
|
use Cortex\Auth\Notifications\RegistrationSuccessNotification; |
13
|
|
|
use Cortex\Auth\Notifications\AuthenticationLockoutNotification; |
14
|
|
|
|
15
|
|
|
class GenericHandler |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* The container instance. |
19
|
|
|
* |
20
|
|
|
* @var \Illuminate\Container\Container |
21
|
|
|
*/ |
22
|
|
|
protected $app; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Create a new GenericHandler instance. |
26
|
|
|
* |
27
|
|
|
* @param \Illuminate\Contracts\Container\Container $app |
28
|
|
|
*/ |
29
|
|
|
public function __construct(Container $app) |
30
|
|
|
{ |
31
|
|
|
$this->app = $app; |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Register the listeners for the subscriber. |
36
|
|
|
* |
37
|
|
|
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher |
38
|
|
|
*/ |
39
|
|
|
public function subscribe(Dispatcher $dispatcher) |
40
|
|
|
{ |
41
|
|
|
$dispatcher->listen(Login::class, __CLASS__.'@login'); |
42
|
|
|
$dispatcher->listen(Lockout::class, __CLASS__.'@lockout'); |
43
|
|
|
$dispatcher->listen(Registered::class, __CLASS__.'@registered'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Listen to the authentication lockout event. |
48
|
|
|
* |
49
|
|
|
* @param \Illuminate\Auth\Events\Lockout $event |
50
|
|
|
* |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function lockout(Lockout $event): void |
54
|
|
|
{ |
55
|
|
|
if (config('cortex.auth.emails.throttle_lockout')) { |
56
|
|
|
switch ($event->request->route('accessarea')) { |
57
|
|
|
case 'managerarea': |
58
|
|
|
$model = app('cortex.auth.manager'); |
59
|
|
|
break; |
60
|
|
|
case 'adminarea': |
61
|
|
|
$model = app('cortex.auth.admin'); |
62
|
|
|
break; |
63
|
|
|
case 'frontarea': |
64
|
|
|
case 'tenantarea': |
65
|
|
|
default: |
66
|
|
|
$model = app('cortex.auth.member'); |
67
|
|
|
break; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$user = get_login_field($loginfield = $event->request->get('loginfield')) === 'email' |
71
|
|
|
? $model::where('email', $loginfield)->first() |
72
|
|
|
: $model::where('username', $loginfield)->first(); |
73
|
|
|
|
74
|
|
|
! $user || $user->notify(new AuthenticationLockoutNotification($event->request->ip(), $event->request->server('HTTP_USER_AGENT'))); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Listen to the authentication login event. |
80
|
|
|
* |
81
|
|
|
* @param \Illuminate\Auth\Events\Login $event |
82
|
|
|
* |
83
|
|
|
* @return void |
84
|
|
|
*/ |
85
|
|
|
public function login(Login $event): void |
86
|
|
|
{ |
87
|
|
|
config('cortex.auth.persistence') !== 'single' || $event->user->sessions()->delete(); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Listen to the register success event. |
92
|
|
|
* |
93
|
|
|
* @param \Illuminate\Auth\Events\Registered $event |
94
|
|
|
* |
95
|
|
|
* @return void |
96
|
|
|
*/ |
97
|
|
|
public function registered(Registered $event): void |
98
|
|
|
{ |
99
|
|
|
! config('cortex.auth.emails.welcome') || $event->user->notify(new RegistrationSuccessNotification()); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.