1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* NOTICE OF LICENSE |
5
|
|
|
* |
6
|
|
|
* Part of the Rinvex Fort Package. |
7
|
|
|
* |
8
|
|
|
* This source file is subject to The MIT License (MIT) |
9
|
|
|
* that is bundled with this package in the LICENSE file. |
10
|
|
|
* |
11
|
|
|
* Package: Rinvex Fort Package |
12
|
|
|
* License: The MIT License (MIT) |
13
|
|
|
* Link: https://rinvex.com |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Rinvex\Fort\Handlers; |
17
|
|
|
|
18
|
|
|
use Illuminate\Http\Request; |
19
|
|
|
use Rinvex\Fort\Models\Role; |
20
|
|
|
use Rinvex\Fort\Models\User; |
21
|
|
|
use Illuminate\Auth\Events\Lockout; |
22
|
|
|
use Illuminate\Contracts\Events\Dispatcher; |
23
|
|
|
use Illuminate\Contracts\Container\Container; |
24
|
|
|
use Illuminate\Contracts\Auth\Authenticatable; |
25
|
|
|
use Rinvex\Fort\Notifications\RegistrationSuccessNotification; |
26
|
|
|
use Rinvex\Fort\Notifications\VerificationSuccessNotification; |
27
|
|
|
use Rinvex\Fort\Notifications\AuthenticationLockoutNotification; |
28
|
|
|
|
29
|
|
|
class GenericHandler |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* The container instance. |
33
|
|
|
* |
34
|
|
|
* @var \Illuminate\Container\Container |
35
|
|
|
*/ |
36
|
|
|
protected $app; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Create a new fort event listener instance. |
40
|
|
|
* |
41
|
|
|
* @param \Illuminate\Contracts\Container\Container $app |
42
|
|
|
*/ |
43
|
|
|
public function __construct(Container $app) |
44
|
|
|
{ |
45
|
|
|
$this->app = $app; |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Register the listeners for the subscriber. |
50
|
|
|
* |
51
|
|
|
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher |
52
|
|
|
*/ |
53
|
|
|
public function subscribe(Dispatcher $dispatcher) |
54
|
|
|
{ |
55
|
|
|
$dispatcher->listen(Lockout::class, __CLASS__.'@authLockout'); |
56
|
|
|
$dispatcher->listen('rinvex.fort.register.success', __CLASS__.'@registerSuccess'); |
57
|
|
|
$dispatcher->listen('rinvex.fort.register.social.success', __CLASS__.'@registerSocialSuccess'); |
58
|
|
|
$dispatcher->listen('rinvex.fort.emailverification.success', __CLASS__.'@emailVerificationSuccess'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Listen to the authentication lockout event. |
63
|
|
|
* |
64
|
|
|
* @param \Illuminate\Http\Request $request |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function authLockout(Request $request) |
69
|
|
|
{ |
70
|
|
|
if (config('rinvex.fort.throttle.lockout_email')) { |
71
|
|
|
$user = get_login_field($loginfield = $request->get('loginfield')) == 'email' ? User::where('email', $loginfield)->first() : User::where('username', $loginfield)->first(); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$user->notify(new AuthenticationLockoutNotification($request)); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Listen to the register success event. |
79
|
|
|
* |
80
|
|
|
* @param \Illuminate\Contracts\Auth\Authenticatable $user |
81
|
|
|
* |
82
|
|
|
* @return void |
83
|
|
|
*/ |
84
|
|
|
public function registerSuccess(Authenticatable $user) |
85
|
|
|
{ |
86
|
|
|
// Send welcome email |
87
|
|
|
if (config('rinvex.fort.registration.welcome_email')) { |
88
|
|
|
$user->notify(new RegistrationSuccessNotification()); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
// Attach default role to the registered user |
92
|
|
|
if ($default = $this->app['config']->get('rinvex.fort.registration.default_role')) { |
93
|
|
|
if ($role = Role::where('slug', $default)->first()) { |
94
|
|
|
$user->roles()->attach($role); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Listen to the register social success event. |
101
|
|
|
* |
102
|
|
|
* @param \Illuminate\Contracts\Auth\Authenticatable $user |
103
|
|
|
* |
104
|
|
|
* @return void |
105
|
|
|
*/ |
106
|
|
|
public function registerSocialSuccess(Authenticatable $user) |
107
|
|
|
{ |
108
|
|
|
// Send welcome email |
109
|
|
|
if (config('rinvex.fort.registration.welcome_email')) { |
110
|
|
|
$user->notify(new RegistrationSuccessNotification(true)); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
// Attach default role to the registered user |
114
|
|
|
if ($default = $this->app['config']->get('rinvex.fort.registration.default_role')) { |
115
|
|
|
if ($role = Role::where('slug', $default)->first()) { |
116
|
|
|
$user->roles()->attach($role); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Listen to the email verification success. |
123
|
|
|
* |
124
|
|
|
* @param \Illuminate\Contracts\Auth\Authenticatable $user |
125
|
|
|
* |
126
|
|
|
* @return void |
127
|
|
|
*/ |
128
|
|
|
public function emailVerificationSuccess(Authenticatable $user) |
129
|
|
|
{ |
130
|
|
|
if (config('rinvex.fort.emailverification.success_notification')) { |
131
|
|
|
$user->notify(new VerificationSuccessNotification($user->active)); |
|
|
|
|
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
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.