1
|
|
|
<?php namespace Cerbero\Auth\Http\Controllers; |
2
|
|
|
|
3
|
|
|
use Cerbero\Auth\Jobs\LoginJob; |
4
|
|
|
use Cerbero\Auth\Jobs\LogoutJob; |
5
|
|
|
use Cerbero\Auth\Jobs\RegisterJob; |
6
|
|
|
use Cerbero\Auth\Jobs\RecoverJob; |
7
|
|
|
use Cerbero\Auth\Jobs\ResetJob; |
8
|
|
|
use Cerbero\Auth\Http\Requests\LoginRequest; |
9
|
|
|
use Cerbero\Auth\Http\Requests\RecoverRequest; |
10
|
|
|
use Cerbero\Auth\Http\Requests\RegisterRequest; |
11
|
|
|
use Cerbero\Auth\Http\Requests\ResetRequest; |
12
|
|
|
use Cerbero\Auth\Services\Dispatcher\DispatcherInterface; |
13
|
|
|
use Illuminate\Routing\Controller; |
14
|
|
|
|
15
|
|
|
class AuthController extends Controller { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Andrea Marco Sartori |
19
|
|
|
* @var Cerbero\Auth\Services\Dispatcher\DispatcherInterface $bus Bus dispatcher. |
20
|
|
|
*/ |
21
|
|
|
protected $bus; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author Andrea Marco Sartori |
25
|
|
|
* @var array $loginPipes List of pipes for the login process. |
26
|
|
|
*/ |
27
|
|
|
protected $loginPipes = ['DispatchEvent', 'Throttle']; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @author Andrea Marco Sartori |
31
|
|
|
* @var array $logoutPipes List of pipes for the logout process. |
32
|
|
|
*/ |
33
|
|
|
protected $logoutPipes = ['DispatchEvent']; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @author Andrea Marco Sartori |
37
|
|
|
* @var array $registerPipes List of pipes for the register process. |
38
|
|
|
*/ |
39
|
|
|
protected $registerPipes = ['DispatchEvent', 'Login', 'Notify', 'Hash']; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @author Andrea Marco Sartori |
43
|
|
|
* @var array $recoverPipes List of pipes for the password recover process. |
44
|
|
|
*/ |
45
|
|
|
protected $recoverPipes = ['DispatchEvent', 'Notify', 'Store']; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @author Andrea Marco Sartori |
49
|
|
|
* @var array $resetPipes List of pipes for the password reset process. |
50
|
|
|
*/ |
51
|
|
|
protected $resetPipes = ['DispatchEvent']; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Set the dependencies. |
55
|
|
|
* |
56
|
|
|
* @author Andrea Marco Sartori |
57
|
|
|
* @param Cerbero\Auth\Services\Dispatcher\DispatcherInterface $bus |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
public function __construct(DispatcherInterface $bus) |
61
|
|
|
{ |
62
|
|
|
$this->bus = $bus; |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Display the login page. |
67
|
|
|
* |
68
|
|
|
* @author Andrea Marco Sartori |
69
|
|
|
* @return Illuminate\Http\Response |
70
|
|
|
*/ |
71
|
|
|
public function showLogin() |
72
|
|
|
{ |
73
|
|
|
$login = config('_auth.login.view'); |
74
|
|
|
|
75
|
|
|
return view($login); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Log the user in. |
80
|
|
|
* |
81
|
|
|
* @author Andrea Marco Sartori |
82
|
|
|
* @return Illuminate\Http\RedirectResponse |
83
|
|
|
*/ |
84
|
|
|
public function login(LoginRequest $request) |
85
|
|
|
{ |
86
|
|
|
$this->bus->pipeThrough($this->pipesOf('login'))->dispatchFrom(LoginJob::class, $request); |
87
|
|
|
|
88
|
|
|
return redirect()->route(config('_auth.login.redirect')); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Retrieve the pipes of a given process. |
93
|
|
|
* |
94
|
|
|
* @author Andrea Marco Sartori |
95
|
|
|
* @param string $process |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
|
|
protected function pipesOf($process) |
99
|
|
|
{ |
100
|
|
|
$Process = ucfirst($process); |
101
|
|
|
|
102
|
|
|
return array_map(function($pipe) use($Process) |
103
|
|
|
{ |
104
|
|
|
return "Cerbero\Auth\Pipes\\{$Process}\\{$pipe}"; |
105
|
|
|
|
106
|
|
|
}, $this->{"{$process}Pipes"}); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Log the user out. |
111
|
|
|
* |
112
|
|
|
* @author Andrea Marco Sartori |
113
|
|
|
* @return Illuminate\Http\RedirectResponse |
114
|
|
|
*/ |
115
|
|
|
public function logout() |
116
|
|
|
{ |
117
|
|
|
$this->bus->pipeThrough($this->pipesOf('logout'))->dispatchNow(new LogoutJob); |
118
|
|
|
|
119
|
|
|
return redirect()->route(config('_auth.logout.redirect')); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Display the registration page. |
124
|
|
|
* |
125
|
|
|
* @author Andrea Marco Sartori |
126
|
|
|
* @return Illuminate\Http\Response |
127
|
|
|
*/ |
128
|
|
|
public function showRegister() |
129
|
|
|
{ |
130
|
|
|
$register = config('_auth.register.view'); |
131
|
|
|
|
132
|
|
|
return view($register); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Register the user. |
137
|
|
|
* |
138
|
|
|
* @author Andrea Marco Sartori |
139
|
|
|
* @return Illuminate\Http\RedirectResponse |
140
|
|
|
*/ |
141
|
|
|
public function register(RegisterRequest $request) |
142
|
|
|
{ |
143
|
|
|
$this->bus->pipeThrough($this->pipesOf('register'))->dispatchFrom(RegisterJob::class, $request); |
144
|
|
|
|
145
|
|
|
return redirect()->route(config('_auth.register.redirect'))->withSuccess(trans('auth::register.success')); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Display the recover page. |
150
|
|
|
* |
151
|
|
|
* @author Andrea Marco Sartori |
152
|
|
|
* @return Illuminate\Http\Response |
153
|
|
|
*/ |
154
|
|
|
public function showRecover() |
155
|
|
|
{ |
156
|
|
|
$recover = config('_auth.recover.view'); |
157
|
|
|
|
158
|
|
|
return view($recover); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Remember the user password. |
163
|
|
|
* |
164
|
|
|
* @author Andrea Marco Sartori |
165
|
|
|
* @return Illuminate\Http\RedirectResponse |
166
|
|
|
*/ |
167
|
|
|
public function recover(RecoverRequest $request) |
168
|
|
|
{ |
169
|
|
|
$this->bus->pipeThrough($this->pipesOf('recover'))->dispatchFrom(RecoverJob::class, $request); |
170
|
|
|
|
171
|
|
|
return back()->withSuccess(trans('auth::recover.success')); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Display the reset page. |
176
|
|
|
* |
177
|
|
|
* @author Andrea Marco Sartori |
178
|
|
|
* @return Illuminate\Http\Response |
179
|
|
|
*/ |
180
|
|
|
public function showReset($token) |
181
|
|
|
{ |
182
|
|
|
$reset = config('_auth.reset.view'); |
183
|
|
|
|
184
|
|
|
return view($reset); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Reset the user password. |
189
|
|
|
* |
190
|
|
|
* @author Andrea Marco Sartori |
191
|
|
|
* @return Illuminate\Http\RedirectResponse |
192
|
|
|
*/ |
193
|
|
|
public function reset(ResetRequest $request, $token) |
194
|
|
|
{ |
195
|
|
|
$this->bus->pipeThrough($this->pipesOf('reset'))->dispatchFrom(ResetJob::class, $request, compact('token')); |
196
|
|
|
|
197
|
|
|
return redirect()->route('login.index')->withSuccess(trans('auth::reset.success')); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
} |
201
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..