1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Rinvex\Fort\Handlers; |
6
|
|
|
|
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use Illuminate\Auth\Events\Login; |
9
|
|
|
use Illuminate\Auth\Events\Lockout; |
10
|
|
|
use Illuminate\Contracts\Events\Dispatcher; |
11
|
|
|
use Illuminate\Contracts\Container\Container; |
12
|
|
|
use Illuminate\Contracts\Auth\Authenticatable; |
13
|
|
|
use Rinvex\Fort\Notifications\RegistrationSuccessNotification; |
14
|
|
|
use Rinvex\Fort\Notifications\AuthenticationLockoutNotification; |
15
|
|
|
|
16
|
|
|
class GenericHandler |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* The container instance. |
20
|
|
|
* |
21
|
|
|
* @var \Illuminate\Container\Container |
22
|
|
|
*/ |
23
|
|
|
protected $app; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Create a new fort event listener instance. |
27
|
|
|
* |
28
|
|
|
* @param \Illuminate\Contracts\Container\Container $app |
29
|
|
|
*/ |
30
|
|
|
public function __construct(Container $app) |
31
|
|
|
{ |
32
|
|
|
$this->app = $app; |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Register the listeners for the subscriber. |
37
|
|
|
* |
38
|
|
|
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher |
39
|
|
|
*/ |
40
|
|
|
public function subscribe(Dispatcher $dispatcher) |
41
|
|
|
{ |
42
|
|
|
$dispatcher->listen(Login::class, __CLASS__.'@authLogin'); |
43
|
|
|
$dispatcher->listen(Lockout::class, __CLASS__.'@authLockout'); |
44
|
|
|
$dispatcher->listen('rinvex.fort.register.success', __CLASS__.'@registerSuccess'); |
45
|
|
|
$dispatcher->listen('rinvex.fort.register.social.success', __CLASS__.'@registerSocialSuccess'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Listen to the authentication lockout event. |
50
|
|
|
* |
51
|
|
|
* @param \Illuminate\Http\Request $request |
52
|
|
|
* |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
|
|
public function authLockout(Request $request): void |
56
|
|
|
{ |
57
|
|
|
if (config('rinvex.fort.throttle.lockout_email')) { |
58
|
|
|
$user = get_login_field($loginfield = $request->get('loginfield')) === 'email' ? app('rinvex.fort.user')->where('email', $loginfield)->first() : app('rinvex.fort.user')->where('username', $loginfield)->first(); |
|
|
|
|
59
|
|
|
|
60
|
|
|
$user->notify(new AuthenticationLockoutNotification($request)); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Listen to the authentication login event. |
66
|
|
|
* |
67
|
|
|
* @param \Illuminate\Auth\Events\Login $event |
68
|
|
|
* |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
|
|
public function authLogin(Login $event): void |
72
|
|
|
{ |
73
|
|
|
! config('rinvex.fort.persistence') === 'single' || $event->user->sessions()->delete(); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Listen to the register success event. |
78
|
|
|
* |
79
|
|
|
* @param \Illuminate\Contracts\Auth\Authenticatable $user |
80
|
|
|
* |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
|
|
public function registerSuccess(Authenticatable $user): void |
84
|
|
|
{ |
85
|
|
|
// Send welcome email |
86
|
|
|
if (config('rinvex.fort.registration.welcome_email')) { |
87
|
|
|
$user->notify(new RegistrationSuccessNotification()); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Listen to the register social success event. |
93
|
|
|
* |
94
|
|
|
* @param \Illuminate\Contracts\Auth\Authenticatable $user |
95
|
|
|
* |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
|
|
public function registerSocialSuccess(Authenticatable $user): void |
99
|
|
|
{ |
100
|
|
|
// Send welcome email |
101
|
|
|
if (config('rinvex.fort.registration.welcome_email')) { |
102
|
|
|
$user->notify(new RegistrationSuccessNotification(true)); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
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.