1
|
|
|
<?php namespace WITR\Http\Controllers\Auth; |
2
|
|
|
|
3
|
|
|
use WITR\Http\Controllers\Controller; |
4
|
|
|
use Illuminate\Contracts\Auth\Guard; |
5
|
|
|
use Illuminate\Contracts\Auth\Registrar; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
|
8
|
|
|
class AuthController extends Controller { |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The Guard implementation. |
12
|
|
|
* |
13
|
|
|
* @var Guard |
14
|
|
|
*/ |
15
|
|
|
protected $auth; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Create a new authentication controller instance. |
19
|
|
|
* |
20
|
|
|
* @param \Illuminate\Contracts\Auth\Guard $auth |
21
|
|
|
* @param \Illuminate\Contracts\Auth\Registrar $registrar |
|
|
|
|
22
|
|
|
* @return void |
|
|
|
|
23
|
|
|
*/ |
24
|
|
|
public function __construct(Guard $auth) |
25
|
|
|
{ |
26
|
|
|
$this->auth = $auth; |
27
|
|
|
|
28
|
|
|
$this->middleware('guest', ['except' => 'logout']); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Show the application login form. |
33
|
|
|
* |
34
|
|
|
* @return \Illuminate\Http\Response |
35
|
|
|
*/ |
36
|
|
|
public function login() |
37
|
|
|
{ |
38
|
|
|
return view('auth.login'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Handle a login request to the application. |
43
|
|
|
* |
44
|
|
|
* @param \Illuminate\Http\Request $request |
45
|
|
|
* @return \Illuminate\Http\Response |
46
|
|
|
*/ |
47
|
|
|
public function authenticate(Request $request) |
48
|
|
|
{ |
49
|
|
|
$this->validate($request, [ |
50
|
|
|
'email' => 'required', 'password' => 'required', |
51
|
|
|
]); |
52
|
|
|
|
53
|
|
|
$credentials = $request->only('email', 'password'); |
54
|
|
|
|
55
|
|
|
if ($this->auth->attempt($credentials, $request->has('remember'))) |
56
|
|
|
{ |
57
|
|
|
return redirect()->intended($this->redirectPath()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return redirect($this->loginPath()) |
61
|
|
|
->withInput($request->only('email')) |
62
|
|
|
->withErrors([ |
63
|
|
|
'email' => 'These credentials do not match our records.', |
64
|
|
|
]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Log the user out of the application. |
69
|
|
|
* |
70
|
|
|
* @return \Illuminate\Http\Response |
71
|
|
|
*/ |
72
|
|
|
public function logout() |
73
|
|
|
{ |
74
|
|
|
$this->auth->logout(); |
75
|
|
|
|
76
|
|
|
return redirect('/'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get the post register / login redirect path. |
81
|
|
|
* |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
public function redirectPath() |
85
|
|
|
{ |
86
|
|
|
if (property_exists($this, 'redirectPath')) |
87
|
|
|
{ |
88
|
|
|
return $this->redirectPath; |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home'; |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get the path to the login route. |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function loginPath() |
100
|
|
|
{ |
101
|
|
|
return property_exists($this, 'loginPath') ? $this->loginPath : '/auth/login'; |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.