1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelFlare\Flare\Http\Controllers\Edge; |
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 Illuminate\Foundation\Auth\ResetsPasswords; |
10
|
|
|
use LaravelFlare\Flare\Permissions\Permissions; |
11
|
|
|
use Illuminate\Foundation\Auth\ThrottlesLogins; |
12
|
|
|
use Illuminate\Foundation\Auth\AuthenticatesUsers; |
13
|
|
|
use LaravelFlare\Flare\Http\Controllers\FlareController; |
14
|
|
|
use LaravelFlare\Flare\Admin\Widgets\WidgetAdminManager; |
15
|
|
|
|
16
|
|
View Code Duplication |
class AdminController extends FlareController |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
use AuthenticatesUsers { |
19
|
|
|
AuthenticatesUsers::redirectPath insteadof ResetsPasswords; |
20
|
|
|
AuthenticatesUsers::getGuard insteadof ResetsPasswords; |
21
|
|
|
} |
22
|
|
|
use ResetsPasswords; |
23
|
|
|
use ThrottlesLogins; |
24
|
|
|
use DispatchesJobs; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Auth. |
28
|
|
|
* |
29
|
|
|
* @var Guard |
30
|
|
|
*/ |
31
|
|
|
protected $auth; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* __construct. |
35
|
|
|
* |
36
|
|
|
* @param Guard $auth |
37
|
|
|
* @param AdminManager $adminManager |
38
|
|
|
*/ |
39
|
|
|
public function __construct(Guard $auth, AdminManager $adminManager) |
40
|
|
|
{ |
41
|
|
|
parent::__construct($adminManager); |
42
|
|
|
|
43
|
|
|
$this->auth = $auth; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Show the Dashboard. |
48
|
|
|
* |
49
|
|
|
* @return \Illuminate\Http\Response |
50
|
|
|
*/ |
51
|
|
|
public function getDashboard() |
52
|
|
|
{ |
53
|
|
|
$view = 'admin.dashboard'; |
54
|
|
|
|
55
|
|
|
if (!view()->exists($view)) { |
|
|
|
|
56
|
|
|
$view = 'flare::'.$view; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return view($view, ['widgets' => (new WidgetAdminManager())]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Show the login form. |
64
|
|
|
* |
65
|
|
|
* @return \Illuminate\Http\Response |
66
|
|
|
*/ |
67
|
|
|
public function getLogin() |
68
|
|
|
{ |
69
|
|
|
return view('flare::admin.login'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Log the user. |
74
|
|
|
* |
75
|
|
|
* @return \Illuminate\Http\RedirectReponse |
76
|
|
|
*/ |
77
|
|
|
public function getLogout() |
78
|
|
|
{ |
79
|
|
|
$this->auth->logout(); |
|
|
|
|
80
|
|
|
|
81
|
|
|
return redirect('/'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Display the form to request a password reset link. |
86
|
|
|
* |
87
|
|
|
* @return \Illuminate\Http\Response |
88
|
|
|
*/ |
89
|
|
|
public function getEmail() |
90
|
|
|
{ |
91
|
|
|
return view('flare::admin.password'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Display the form to request a password reset link. |
96
|
|
|
* |
97
|
|
|
* @return \Illuminate\Http\Response |
98
|
|
|
*/ |
99
|
|
|
public function getReset() |
100
|
|
|
{ |
101
|
|
|
return view('flare::admin.reset'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Performs the login redirect action. |
106
|
|
|
* |
107
|
|
|
* If the authenticated user has admin permissions |
108
|
|
|
* then they will be redirected into the admin |
109
|
|
|
* panel. If they do no, they will be sent |
110
|
|
|
* to the homepage of the website. |
111
|
|
|
* |
112
|
|
|
* @return \Illuminate\Http\RedirectReponse |
113
|
|
|
*/ |
114
|
|
|
protected function loginRedirect() |
115
|
|
|
{ |
116
|
|
|
if (Permissions::check()) { |
117
|
|
|
return redirect()->intended(\Flare::adminUrl()); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return redirect('/'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Method is called when the appropriate controller |
125
|
|
|
* method is unable to be found or called. |
126
|
|
|
* |
127
|
|
|
* @param array $parameters |
128
|
|
|
* |
129
|
|
|
* @return \Illuminate\Http\Response |
130
|
|
|
*/ |
131
|
|
|
public function missingMethod($parameters = array()) |
132
|
|
|
{ |
133
|
|
|
return view('flare::admin.404', []); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.