|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package Dashboard |
|
5
|
|
|
* @author Ian Olson <[email protected]> |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @copyright 2015, Laraflock |
|
8
|
|
|
* @link https://github.com/laraflock |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Laraflock\Dashboard\Controllers; |
|
12
|
|
|
|
|
13
|
|
|
use Illuminate\Http\Request; |
|
14
|
|
|
use Laracasts\Flash\Flash; |
|
15
|
|
|
use Laraflock\Dashboard\Exceptions\AuthenticationException; |
|
16
|
|
|
use Laraflock\Dashboard\Exceptions\FormValidationException; |
|
17
|
|
|
use Laraflock\Dashboard\Exceptions\RolesException; |
|
18
|
|
|
use Laraflock\Dashboard\Repositories\Auth\AuthRepositoryInterface; |
|
19
|
|
|
|
|
20
|
|
|
class AuthController extends BaseDashboardController |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Auth interface. |
|
24
|
|
|
* |
|
25
|
|
|
* @var \Laraflock\Dashboard\Repositories\Auth\AuthRepositoryInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $authRepositoryInterface; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The constructor. |
|
31
|
|
|
* |
|
32
|
|
|
* @param \Laraflock\Dashboard\Repositories\Auth\AuthRepositoryInterface $authRepositoryInterface |
|
33
|
|
|
*/ |
|
34
|
21 |
|
public function __construct(AuthRepositoryInterface $authRepositoryInterface) |
|
35
|
|
|
{ |
|
36
|
21 |
|
$this->authRepositoryInterface = $authRepositoryInterface; |
|
37
|
|
|
|
|
38
|
21 |
|
$viewNamespace = config('laraflock.dashboard.viewNamespace'); |
|
39
|
|
|
|
|
40
|
21 |
|
view()->share(['viewNamespace' => $viewNamespace]); |
|
|
|
|
|
|
41
|
21 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Display login screen. |
|
45
|
|
|
* |
|
46
|
|
|
* @return \Illuminate\View\View |
|
47
|
|
|
*/ |
|
48
|
6 |
|
public function login() |
|
49
|
|
|
{ |
|
50
|
6 |
|
return $this->view('auth.login'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Authenticate and Validate login input. |
|
55
|
|
|
* |
|
56
|
|
|
* @param Request $request |
|
57
|
|
|
* |
|
58
|
|
|
* @return $this|\Illuminate\Http\RedirectResponse |
|
59
|
|
|
*/ |
|
60
|
4 |
View Code Duplication |
public function authentication(Request $request) |
|
|
|
|
|
|
61
|
|
|
{ |
|
62
|
|
|
try { |
|
63
|
4 |
|
$this->authRepositoryInterface->authenticate($request->all()); |
|
64
|
4 |
|
} catch (FormValidationException $e) { |
|
65
|
1 |
|
Flash::error($e->getMessage()); |
|
66
|
|
|
|
|
67
|
1 |
|
return redirect() |
|
68
|
1 |
|
->route('auth.login') |
|
69
|
1 |
|
->withErrors($e->getErrors()); |
|
70
|
1 |
|
} catch (AuthenticationException $e) { |
|
71
|
1 |
|
Flash::error($e->getMessage()); |
|
72
|
|
|
|
|
73
|
1 |
|
return redirect()->route('auth.login'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
2 |
|
return redirect()->route('dashboard.index'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Display registration screen. |
|
81
|
|
|
* |
|
82
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View |
|
83
|
|
|
*/ |
|
84
|
4 |
|
public function register() |
|
85
|
|
|
{ |
|
86
|
4 |
|
if (!config('laraflock.dashboard.registration')) { |
|
87
|
3 |
|
Flash::error(trans('dashboard::dashboard.flash.registration.not_active')); |
|
88
|
|
|
|
|
89
|
3 |
|
return redirect()->route('auth.login'); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
1 |
|
return $this->view('auth.register'); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Register the user. |
|
97
|
|
|
* |
|
98
|
|
|
* @param \Illuminate\Http\Request $request |
|
99
|
|
|
* |
|
100
|
|
|
* @return $this|\Illuminate\Http\RedirectResponse |
|
101
|
|
|
*/ |
|
102
|
5 |
|
public function registration(Request $request) |
|
103
|
|
|
{ |
|
104
|
5 |
|
if (!config('laraflock.dashboard.registration')) { |
|
105
|
1 |
|
Flash::error(trans('dashboard::dashboard.flash.registration.not_active')); |
|
106
|
|
|
|
|
107
|
1 |
|
return redirect()->route('auth.login'); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
try { |
|
111
|
4 |
|
$this->authRepositoryInterface->register($request->all()); |
|
112
|
4 |
|
} catch (FormValidationException $e) { |
|
113
|
1 |
|
Flash::error($e->getMessage()); |
|
114
|
|
|
|
|
115
|
1 |
|
return redirect() |
|
116
|
1 |
|
->route('auth.register') |
|
117
|
1 |
|
->withErrors($e->getErrors()) |
|
118
|
1 |
|
->withInput(); |
|
119
|
1 |
|
} catch (RolesException $e) { |
|
120
|
1 |
|
Flash::error($e->getMessage()); |
|
121
|
|
|
|
|
122
|
1 |
|
return redirect() |
|
123
|
1 |
|
->route('auth.register') |
|
124
|
1 |
|
->withInput(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
2 |
|
if (!config('laraflock.dashboard.activations')) { |
|
128
|
1 |
|
Flash::success(trans('dashboard::dashboard.flash.registration.activated')); |
|
129
|
|
|
|
|
130
|
1 |
|
return redirect()->route('auth.login'); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
1 |
|
Flash::success(trans('dashboard::dashboard.flash.registration.created')); |
|
134
|
|
|
|
|
135
|
1 |
|
return redirect()->route('auth.login'); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Display activate screen. |
|
140
|
|
|
* |
|
141
|
|
|
* @param \Illuminate\Http\Request $request |
|
142
|
|
|
* |
|
143
|
|
|
* @return $this|\Illuminate\Http\RedirectResponse |
|
144
|
|
|
*/ |
|
145
|
1 |
|
public function activate(Request $request) |
|
146
|
|
|
{ |
|
147
|
1 |
|
if (!$email = $request->get('email')) { |
|
148
|
1 |
|
$email = null; |
|
149
|
1 |
|
} |
|
150
|
|
|
|
|
151
|
1 |
|
if (!$code = $request->get('code')) { |
|
152
|
1 |
|
$code = null; |
|
153
|
1 |
|
} |
|
154
|
|
|
|
|
155
|
1 |
|
if (!config('laraflock.dashboard.activations')) { |
|
156
|
1 |
|
Flash::error(trans('dashboard::dashboard.flash.activation.not_active')); |
|
157
|
|
|
|
|
158
|
1 |
|
return redirect()->route('auth.login'); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
return $this->view('auth.activate')->with(['email' => $email, 'code' => $code]); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Activate a user. |
|
166
|
|
|
* |
|
167
|
|
|
* @param \Illuminate\Http\Request $request |
|
168
|
|
|
* |
|
169
|
|
|
* @return $this |
|
170
|
|
|
*/ |
|
171
|
5 |
|
public function activation(Request $request) |
|
172
|
|
|
{ |
|
173
|
5 |
|
if (!config('laraflock.dashboard.activations')) { |
|
174
|
1 |
|
Flash::error(trans('dashboard::dashboard.flash.activation.not_active')); |
|
175
|
|
|
|
|
176
|
1 |
|
return redirect()->route('auth.login'); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
try { |
|
180
|
4 |
|
$this->authRepositoryInterface->activate($request->all()); |
|
181
|
4 |
|
} catch (FormValidationException $e) { |
|
182
|
1 |
|
Flash::error($e->getMessage()); |
|
183
|
|
|
|
|
184
|
1 |
|
return redirect() |
|
185
|
1 |
|
->route('auth.activate') |
|
186
|
1 |
|
->withErrors($e->getErrors()) |
|
187
|
1 |
|
->withInput(); |
|
188
|
2 |
|
} catch (AuthenticationException $e) { |
|
189
|
2 |
|
Flash::error($e->getMessage()); |
|
190
|
|
|
|
|
191
|
2 |
|
return redirect() |
|
192
|
2 |
|
->route('auth.activate') |
|
193
|
2 |
|
->withInput(); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
2 |
|
Flash::success(trans('dashboard::dashboard.flash.activation.success')); |
|
197
|
|
|
|
|
198
|
2 |
|
return redirect()->route('auth.login'); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* Unauthorized view. |
|
203
|
|
|
* |
|
204
|
|
|
* @return \Illuminate\View\View |
|
205
|
|
|
*/ |
|
206
|
|
|
public function unauthorized() |
|
207
|
|
|
{ |
|
208
|
|
|
return $this->view('auth.unauthorized'); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Trigger logout of session. |
|
213
|
|
|
* |
|
214
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
215
|
|
|
*/ |
|
216
|
1 |
|
public function logout() |
|
217
|
|
|
{ |
|
218
|
1 |
|
$this->authRepositoryInterface->logout(); |
|
219
|
|
|
|
|
220
|
1 |
|
return redirect()->route('auth.login'); |
|
221
|
|
|
} |
|
222
|
|
|
} |
|
223
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: