1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yajra\CMS\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\User; |
6
|
|
|
use Illuminate\Foundation\Auth\AuthenticatesUsers; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
|
9
|
|
|
class AuthController extends Controller |
10
|
|
|
{ |
11
|
|
|
use AuthenticatesUsers; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Where to redirect users after login / registration. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $redirectPath = '/administrator'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Authentication guard. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $guard = 'administrator'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Administrator login view. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $loginView = 'admin::auth.login'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Where to redirect users after logout. |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $redirectAfterLogout = '/administrator'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Create a new authentication controller instance. |
43
|
|
|
*/ |
44
|
|
|
public function __construct() |
45
|
|
|
{ |
46
|
|
|
$this->middleware('guest', ['except' => 'logout']); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Show the application's login form. |
51
|
|
|
* |
52
|
|
|
* @return \Illuminate\Http\Response |
53
|
|
|
*/ |
54
|
|
|
public function showLoginForm() |
55
|
|
|
{ |
56
|
|
|
return view($this->loginView); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Handle event when the user was authenticated. |
61
|
|
|
* |
62
|
|
|
* @param \Illuminate\Http\Request $request |
63
|
|
|
* @param \App\User $user |
64
|
|
|
* @return \Illuminate\Http\RedirectResponse |
65
|
|
|
*/ |
66
|
|
|
public function authenticated(Request $request, User $user) |
67
|
|
|
{ |
68
|
|
|
if ($user->blocked || ! $user->confirmed) { |
69
|
|
|
if ($user->blocked) { |
70
|
|
|
$message = 'Your account is currently banned from accessing the site!'; |
71
|
|
|
} else { |
72
|
|
|
$message = 'Your account is not yet activated!'; |
73
|
|
|
} |
74
|
|
|
auth($this->getGuard())->logout(); |
75
|
|
|
flash()->error($message); |
76
|
|
|
|
77
|
|
|
return redirect()->to('administrator/login')->withErrors($message); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return redirect()->intended($this->redirectPath); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get the needed authorization credentials from the request. |
85
|
|
|
* |
86
|
|
|
* @param \Illuminate\Http\Request $request |
87
|
|
|
* @return array |
88
|
|
|
*/ |
89
|
|
|
protected function credentials(Request $request) |
90
|
|
|
{ |
91
|
|
|
$options = config('site.login.backend.options', [ |
92
|
|
|
'administrator' => true, |
93
|
|
|
]); |
94
|
|
|
|
95
|
|
|
return array_merge($request->only($this->username(), 'password'), $options); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get auth guard. |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
protected function getGuard() |
104
|
|
|
{ |
105
|
|
|
return $this->guard; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|