|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LaravelFlare\Flare\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Illuminate\Contracts\Auth\Guard; |
|
7
|
|
|
use LaravelFlare\Flare\Admin\AdminManager; |
|
8
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
|
9
|
|
|
use LaravelFlare\Flare\Permissions\Permissions; |
|
10
|
|
|
use LaravelFlare\Flare\Admin\Widgets\WidgetAdminManager; |
|
11
|
|
|
use LaravelFlare\Flare\Traits\Http\Controllers\AuthenticatesAndResetsPasswords; |
|
12
|
|
|
|
|
13
|
|
|
class AdminController extends FlareController |
|
14
|
|
|
{ |
|
15
|
|
|
use AuthenticatesAndResetsPasswords, DispatchesJobs; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Auth. |
|
19
|
|
|
* |
|
20
|
|
|
* @var Guard |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $auth; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* __construct. |
|
26
|
|
|
* |
|
27
|
|
|
* @param Guard $auth |
|
28
|
|
|
* @param AdminManager $adminManager |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(Guard $auth, AdminManager $adminManager) |
|
31
|
|
|
{ |
|
32
|
|
|
parent::__construct($adminManager); |
|
33
|
|
|
|
|
34
|
|
|
$this->auth = $auth; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Show the Dashboard. |
|
39
|
|
|
* |
|
40
|
|
|
* @return \Illuminate\Http\Response |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getDashboard() |
|
43
|
|
|
{ |
|
44
|
|
|
$view = 'admin.dashboard'; |
|
45
|
|
|
|
|
46
|
|
|
if (!view()->exists($view)) { |
|
|
|
|
|
|
47
|
|
|
$view = 'flare::'.$view; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return view($view, ['widgetAdminManager' => (new WidgetAdminManager())]); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Show the login form. |
|
55
|
|
|
* |
|
56
|
|
|
* @return \Illuminate\Http\Response |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getLogin() |
|
59
|
|
|
{ |
|
60
|
|
|
return view('flare::admin.login'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Processes the login form. |
|
65
|
|
|
* |
|
66
|
|
|
* @param Request $request |
|
67
|
|
|
* |
|
68
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
69
|
|
|
*/ |
|
70
|
|
|
public function postLogin(Request $request) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->validate($request, ['email' => 'required|email', 'password' => 'required']); |
|
73
|
|
|
|
|
74
|
|
|
$credentials = $request->only('email', 'password'); |
|
75
|
|
|
|
|
76
|
|
|
if ($this->auth->attempt($credentials, $request->has('remember'))) { |
|
|
|
|
|
|
77
|
|
|
return $this->loginRedirect(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return redirect(route('flare::login')) |
|
81
|
|
|
->withInput($request->only('email', 'remember')) |
|
82
|
|
|
->withErrors([ |
|
83
|
|
|
'email' => $this->getFailedLoginMessage(), |
|
84
|
|
|
]); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Log the user. |
|
89
|
|
|
* |
|
90
|
|
|
* @return \Illuminate\Http\RedirectReponse |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getLogout() |
|
93
|
|
|
{ |
|
94
|
|
|
$this->auth->logout(); |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
return redirect('/'); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Display the form to request a password reset link. |
|
101
|
|
|
* |
|
102
|
|
|
* @return \Illuminate\Http\Response |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getEmail() |
|
105
|
|
|
{ |
|
106
|
|
|
return view('flare::admin.password'); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Display the form to request a password reset link. |
|
111
|
|
|
* |
|
112
|
|
|
* @return \Illuminate\Http\Response |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getReset() |
|
115
|
|
|
{ |
|
116
|
|
|
return view('flare::admin.reset'); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Performs the login redirect action. |
|
121
|
|
|
* |
|
122
|
|
|
* If the authenticated user has admin permissions |
|
123
|
|
|
* then they will be redirected into the admin |
|
124
|
|
|
* panel.If they do no, they will be sent |
|
125
|
|
|
* to the homepage of the website. |
|
126
|
|
|
* |
|
127
|
|
|
* @return \Illuminate\Http\RedirectReponse |
|
128
|
|
|
*/ |
|
129
|
|
|
protected function loginRedirect() |
|
130
|
|
|
{ |
|
131
|
|
|
if (Permissions::check()) { |
|
132
|
|
|
return redirect()->intended(\Flare::adminUrl()); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
return redirect('/'); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Method is called when the appropriate controller |
|
140
|
|
|
* method is unable to be found or called. |
|
141
|
|
|
* |
|
142
|
|
|
* @param array $parameters |
|
143
|
|
|
* |
|
144
|
|
|
* @return \Illuminate\Http\Response |
|
145
|
|
|
*/ |
|
146
|
|
|
public function missingMethod($parameters = array()) |
|
147
|
|
|
{ |
|
148
|
|
|
return view('flare::admin.404', []); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: