1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Auth; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
use Illuminate\Foundation\Auth\AuthenticatesUsers; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
|
9
|
|
|
class LoginController extends Controller |
10
|
|
|
{ |
11
|
|
|
/* |
12
|
|
|
|-------------------------------------------------------------------------- |
13
|
|
|
| Login Controller |
14
|
|
|
|-------------------------------------------------------------------------- |
15
|
|
|
| |
16
|
|
|
| This controller handles authenticating users for the application and |
17
|
|
|
| redirecting them to your home screen. The controller uses a trait |
18
|
|
|
| to conveniently provide its functionality to your applications. |
19
|
|
|
| |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
use AuthenticatesUsers { |
23
|
|
|
attemptLogin as attemptLoginAtAuthenticatesUsers; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Show the application's login form. |
28
|
|
|
* |
29
|
|
|
* @return \Illuminate\Http\Response |
30
|
|
|
*/ |
31
|
|
|
public function showLoginForm() |
32
|
|
|
{ |
33
|
|
|
return view('adminlte::auth.login'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Where to redirect users after login. |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $redirectTo = '/home'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Create a new controller instance. |
45
|
|
|
* |
46
|
|
|
* @return void |
|
|
|
|
47
|
|
|
*/ |
48
|
|
|
public function __construct() |
49
|
|
|
{ |
50
|
|
|
$this->middleware('guest', ['except' => 'logout']); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Returns field name to use at login. |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function username() |
59
|
|
|
{ |
60
|
|
|
return config('auth.providers.users.field','email'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Attempt to log the user into the application. |
65
|
|
|
* |
66
|
|
|
* @param \Illuminate\Http\Request $request |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
|
|
protected function attemptLogin(Request $request) |
70
|
|
|
{ |
71
|
|
|
if ($this->username() === 'email') return $this->attemptLoginAtAuthenticatesUsers($request); |
72
|
|
|
if ( ! $this->attemptLoginAtAuthenticatesUsers($request)) { |
73
|
|
|
return $this->attempLoginUsingUsernameAsAnEmail($request); |
74
|
|
|
} |
75
|
|
|
return false; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Attempt to log the user into application using username as an email. |
80
|
|
|
* |
81
|
|
|
* @param \Illuminate\Http\Request $request |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
|
|
protected function attempLoginUsingUsernameAsAnEmail(Request $request) |
85
|
|
|
{ |
86
|
|
|
return $this->guard()->attempt( |
87
|
|
|
['email' => $request->input('username'), 'password' => $request->input('password')], |
88
|
|
|
$request->has('remember')); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.