-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathLoginController.php
113 lines (100 loc) · 3.04 KB
/
LoginController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace App\Domains\Auth\Http\Controllers\Frontend\Auth;
use App\Domains\Auth\Events\User\UserLoggedIn;
use App\Rules\Captcha;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\Request;
use LangleyFoxall\LaravelNISTPasswordRules\PasswordRules;
/**
* Class LoginController.
*/
class LoginController
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @return string
*/
public function redirectPath()
{
return route(homeRoute());
}
/**
* Show the application's login form.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function showLoginForm()
{
return view('frontend.auth.login');
}
/**
* Validate the user login request.
*
* @param \Illuminate\Http\Request $request
* @return void
*
* @throws \Illuminate\Validation\ValidationException
*/
protected function validateLogin(Request $request)
{
$request->validate([
$this->username() => ['required', 'max:255', 'string'],
'password' => array_merge(['max:100'], PasswordRules::login()),
'g-recaptcha-response' => ['required_if:captcha_status,true', new Captcha],
], [
'g-recaptcha-response.required_if' => __('validation.required', ['attribute' => 'captcha']),
]);
}
/**
* Overidden for 2FA
* https://github.com/DarkGhostHunter/Laraguard#protecting-the-login.
*
* Attempt to log the user into the application.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function attemptLogin(Request $request)
{
try {
return $this->guard()->attempt(
$this->credentials($request),
$request->filled('remember')
);
} catch (HttpResponseException $exception) {
$this->incrementLoginAttempts($request);
throw $exception;
}
}
/**
* The user has been authenticated.
*
* @param Request $request
* @param $user
* @return mixed
*/
protected function authenticated(Request $request, $user)
{
if (! $user->isActive()) {
auth()->logout();
return redirect()->route('frontend.auth.login')->withFlashDanger(__('Your account has been deactivated.'));
}
event(new UserLoggedIn($user));
if (config('boilerplate.access.user.single_login')) {
auth()->logoutOtherDevices($request->password);
}
}
}