|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Front; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use App\Services\Auth\Front\User; |
|
7
|
|
|
use Illuminate\Contracts\Validation\Validator; |
|
8
|
|
|
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; |
|
9
|
|
|
use Illuminate\Foundation\Auth\ThrottlesLogins; |
|
10
|
|
|
use Illuminate\Http\Request; |
|
11
|
|
|
|
|
12
|
|
|
class AuthController extends Controller |
|
13
|
|
|
{ |
|
14
|
|
|
use AuthenticatesAndRegistersUsers, ThrottlesLogins; |
|
15
|
|
|
|
|
16
|
|
|
protected $guard = 'front'; |
|
17
|
|
|
protected $loginView = 'front.auth.login'; |
|
18
|
|
|
protected $registerView = 'front.auth.register'; |
|
19
|
|
|
|
|
20
|
|
|
public function redirectPath() : string |
|
21
|
|
|
{ |
|
22
|
|
|
return current_user()->getHomeUrl(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
View Code Duplication |
protected function authenticated(Request $request, User $user) |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
if (! $user->isActive()) { |
|
28
|
|
|
auth()->guard('front')->logout(); |
|
29
|
|
|
|
|
30
|
|
|
return $this->sendInactiveAccountResponse($request); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
return redirect()->intended($this->redirectPath()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
protected function getFailedLoginMessage() : string |
|
37
|
|
|
{ |
|
38
|
|
|
return fragment('auth.failed'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
View Code Duplication |
protected function sendInactiveAccountResponse($request) |
|
|
|
|
|
|
42
|
|
|
{ |
|
43
|
|
|
return redirect()->back() |
|
44
|
|
|
->withInput($request->only($this->loginUsername(), 'remember')) |
|
45
|
|
|
->withErrors([ |
|
46
|
|
|
$this->loginUsername() => fragment('auth.notActivatedError'), |
|
47
|
|
|
]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
protected function validator(array $input) : Validator |
|
51
|
|
|
{ |
|
52
|
|
|
return validator($input, [ |
|
53
|
|
|
'first_name' => 'required', |
|
54
|
|
|
'last_name' => 'required', |
|
55
|
|
|
'address' => 'required', |
|
56
|
|
|
'postal' => 'required', |
|
57
|
|
|
'city' => 'required', |
|
58
|
|
|
'country' => 'required', |
|
59
|
|
|
'telephone' => 'required', |
|
60
|
|
|
'email' => 'required|email|unique:users_front,email', |
|
61
|
|
|
'password' => 'required|confirmed|min:8', |
|
62
|
|
|
]); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
protected function create(array $input) : User |
|
66
|
|
|
{ |
|
67
|
|
|
return User::register($input); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.