1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\Base\app\Http\Controllers\Auth; |
4
|
|
|
|
5
|
|
|
use Backpack\Base\app\Http\Controllers\Controller; |
6
|
|
|
use Illuminate\Foundation\Auth\AuthenticatesUsers; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
|
9
|
|
|
class LoginController extends Controller |
10
|
|
|
{ |
11
|
|
|
protected $data = []; // the information we send to the view |
12
|
|
|
|
13
|
|
|
/* |
14
|
|
|
|-------------------------------------------------------------------------- |
15
|
|
|
| Login Controller |
16
|
|
|
|-------------------------------------------------------------------------- |
17
|
|
|
| |
18
|
|
|
| This controller handles authenticating users for the application and |
19
|
|
|
| redirecting them to your home screen. The controller uses a trait |
20
|
|
|
| to conveniently provide its functionality to your applications. |
21
|
|
|
| |
22
|
|
|
*/ |
23
|
|
|
use AuthenticatesUsers { |
24
|
|
|
logout as defaultLogout; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Create a new controller instance. |
29
|
|
|
* |
30
|
|
|
* @return void |
|
|
|
|
31
|
|
|
*/ |
32
|
|
|
public function __construct() |
33
|
|
|
{ |
34
|
|
|
$guard = backpack_guard_name(); |
35
|
|
|
|
36
|
|
|
$this->middleware("guest:$guard", ['except' => 'logout']); |
37
|
|
|
|
38
|
|
|
// ---------------------------------- |
39
|
|
|
// Use the admin prefix in all routes |
40
|
|
|
// ---------------------------------- |
41
|
|
|
|
42
|
|
|
// If not logged in redirect here. |
43
|
|
|
$this->loginPath = property_exists($this, 'loginPath') ? $this->loginPath |
|
|
|
|
44
|
|
|
: backpack_url('login'); |
45
|
|
|
|
46
|
|
|
// Redirect here after successful login. |
47
|
|
|
$this->redirectTo = property_exists($this, 'redirectTo') ? $this->redirectTo |
|
|
|
|
48
|
|
|
: backpack_url('dashboard'); |
49
|
|
|
|
50
|
|
|
// Redirect here after logout. |
51
|
|
|
$this->redirectAfterLogout = property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout |
|
|
|
|
52
|
|
|
: backpack_url(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Return custom username for authentication. |
57
|
|
|
* |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function username() |
61
|
|
|
{ |
62
|
|
|
return backpack_authentication_column(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Log the user out and redirect him to specific location. |
67
|
|
|
* |
68
|
|
|
* @param \Illuminate\Http\Request $request |
69
|
|
|
* |
70
|
|
|
* @return \Illuminate\Http\Response |
71
|
|
|
*/ |
72
|
|
|
public function logout(Request $request) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
// Do the default logout procedure |
75
|
|
|
$this->guard()->logout(); |
76
|
|
|
|
77
|
|
|
// And redirect to custom location |
78
|
|
|
return redirect($this->redirectAfterLogout); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Get the guard to be used during logout. |
83
|
|
|
* |
84
|
|
|
* @return \Illuminate\Contracts\Auth\StatefulGuard |
85
|
|
|
*/ |
86
|
|
|
protected function guard() |
87
|
|
|
{ |
88
|
|
|
return backpack_auth(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
// ------------------------------------------------------- |
92
|
|
|
// Laravel overwrites for loading backpack views |
93
|
|
|
// ------------------------------------------------------- |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Show the application login form. |
97
|
|
|
* |
98
|
|
|
* @return \Illuminate\Http\Response |
99
|
|
|
*/ |
100
|
|
|
public function showLoginForm() |
101
|
|
|
{ |
102
|
|
|
$this->data['title'] = trans('backpack::base.login'); // set the page title |
103
|
|
|
$this->data['username'] = $this->username(); |
104
|
|
|
|
105
|
|
|
return view('backpack::auth.login', $this->data); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
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.