|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* NOTICE OF LICENSE |
|
5
|
|
|
* |
|
6
|
|
|
* Part of the Rinvex Fort Package. |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to The MIT License (MIT) |
|
9
|
|
|
* that is bundled with this package in the LICENSE file. |
|
10
|
|
|
* |
|
11
|
|
|
* Package: Rinvex Fort Package |
|
12
|
|
|
* License: The MIT License (MIT) |
|
13
|
|
|
* Link: https://rinvex.com |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
declare(strict_types=1); |
|
17
|
|
|
|
|
18
|
|
|
namespace Rinvex\Fort\Console\Commands; |
|
19
|
|
|
|
|
20
|
|
|
use Illuminate\Console\Command; |
|
21
|
|
|
use Illuminate\Console\DetectsApplicationNamespace; |
|
22
|
|
|
|
|
23
|
|
|
class MakeAuthCommand extends Command |
|
24
|
|
|
{ |
|
25
|
|
|
use DetectsApplicationNamespace; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The name and signature of the console command. |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $signature = 'make:auth {--views : Only scaffold the authentication views}'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* The console command description. |
|
36
|
|
|
* |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $description = 'Scaffold basic login and registration views and routes'; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* The controllers that need to be exported. |
|
43
|
|
|
* |
|
44
|
|
|
* @var array |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $controllers = [ |
|
47
|
|
|
|
|
48
|
|
|
'Backend/AbilitiesController', |
|
49
|
|
|
'Backend/DashboardController', |
|
50
|
|
|
'Backend/RolesController', |
|
51
|
|
|
'Backend/UsersController', |
|
52
|
|
|
|
|
53
|
|
|
'Frontend/AccountSettingsController', |
|
54
|
|
|
'Frontend/AccountSessionsController', |
|
55
|
|
|
'Frontend/AuthenticationController', |
|
56
|
|
|
'Frontend/EmailVerificationController', |
|
57
|
|
|
'Frontend/PasswordResetController', |
|
58
|
|
|
'Frontend/PhoneVerificationController', |
|
59
|
|
|
'Frontend/RegistrationController', |
|
60
|
|
|
'Frontend/SocialAuthenticationController', |
|
61
|
|
|
'Frontend/TwoFactorSettingsController', |
|
62
|
|
|
|
|
63
|
|
|
'AbstractController', |
|
64
|
|
|
'AuthenticatedController', |
|
65
|
|
|
'AuthorizedController', |
|
66
|
|
|
|
|
67
|
|
|
]; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* The requests that need to be exported. |
|
71
|
|
|
* |
|
72
|
|
|
* @var array |
|
73
|
|
|
*/ |
|
74
|
|
|
protected $requests = [ |
|
75
|
|
|
|
|
76
|
|
|
'Frontend/EmailVerificationRequest', |
|
77
|
|
|
'Frontend/PasswordResetRequest', |
|
78
|
|
|
'Frontend/PasswordResetSendRequest', |
|
79
|
|
|
'Frontend/PhoneVerificationRequest', |
|
80
|
|
|
'Frontend/PhoneVerificationSendRequest', |
|
81
|
|
|
'Frontend/UserAuthenticationRequest', |
|
82
|
|
|
|
|
83
|
|
|
]; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* The views that need to be exported. |
|
87
|
|
|
* |
|
88
|
|
|
* @var array |
|
89
|
|
|
*/ |
|
90
|
|
|
protected $views = [ |
|
91
|
|
|
|
|
92
|
|
|
'backend/abilities/form.blade', |
|
93
|
|
|
'backend/abilities/index.blade', |
|
94
|
|
|
'backend/common/confirm-modal.blade', |
|
95
|
|
|
'backend/common/layout.blade', |
|
96
|
|
|
'backend/common/layout-example.blade', |
|
97
|
|
|
'backend/common/pagination.blade', |
|
98
|
|
|
'backend/dashboard/home.blade', |
|
99
|
|
|
'backend/roles/form.blade', |
|
100
|
|
|
'backend/roles/index.blade', |
|
101
|
|
|
'backend/users/form.blade', |
|
102
|
|
|
'backend/users/index.blade', |
|
103
|
|
|
|
|
104
|
|
|
'frontend/account/sessions.blade', |
|
105
|
|
|
'frontend/account/settings.blade', |
|
106
|
|
|
'frontend/account/twofactor.blade', |
|
107
|
|
|
'frontend/alerts/error.blade', |
|
108
|
|
|
'frontend/alerts/success.blade', |
|
109
|
|
|
'frontend/alerts/warning.blade', |
|
110
|
|
|
'frontend/authentication/login.blade', |
|
111
|
|
|
'frontend/authentication/register.blade', |
|
112
|
|
|
'frontend/common/confirm-modal.blade', |
|
113
|
|
|
'frontend/common/layout.blade', |
|
114
|
|
|
'frontend/common/layout-example.blade', |
|
115
|
|
|
'frontend/passwordreset/request.blade', |
|
116
|
|
|
'frontend/passwordreset/reset.blade', |
|
117
|
|
|
'frontend/verification/email-request.blade', |
|
118
|
|
|
'frontend/verification/phone-request.blade', |
|
119
|
|
|
'frontend/verification/phone-token.blade', |
|
120
|
|
|
|
|
121
|
|
|
]; |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* The language files that need to be exported. |
|
125
|
|
|
* |
|
126
|
|
|
* @var array |
|
127
|
|
|
*/ |
|
128
|
|
|
protected $langs = [ |
|
129
|
|
|
|
|
130
|
|
|
'en/common.php', |
|
131
|
|
|
'en/emails.php', |
|
132
|
|
|
'en/messages.php', |
|
133
|
|
|
'en/twofactor.php', |
|
134
|
|
|
|
|
135
|
|
|
]; |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Execute the console command. |
|
139
|
|
|
* |
|
140
|
|
|
* @return void |
|
141
|
|
|
*/ |
|
142
|
|
|
public function fire() |
|
143
|
|
|
{ |
|
144
|
|
|
$this->exportViews(); |
|
145
|
|
|
$this->exportLangs(); |
|
146
|
|
|
|
|
147
|
|
|
if (! $this->option('views')) { |
|
148
|
|
|
$this->exportControllers(); |
|
149
|
|
|
$this->exportRequests(); |
|
150
|
|
|
$this->exportRoutes(); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
$this->info('Authentication scaffolding generated successfully.'); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Export the views. |
|
158
|
|
|
* |
|
159
|
|
|
* @return void |
|
160
|
|
|
*/ |
|
161
|
|
|
protected function exportViews() |
|
162
|
|
|
{ |
|
163
|
|
|
foreach ($this->views as $view) { |
|
164
|
|
|
$viewFile = resource_path('views/'.$view.'.php'); |
|
165
|
|
|
|
|
166
|
|
|
if (! is_dir($viewDir = dirname($viewFile))) { |
|
167
|
|
|
mkdir($viewDir, 0755, true); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
copy( |
|
171
|
|
|
__DIR__.'/../../../resources/stubs/views/'.$view.'.stub', |
|
172
|
|
|
$viewFile |
|
173
|
|
|
); |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Export the language files. |
|
179
|
|
|
* |
|
180
|
|
|
* @return void |
|
181
|
|
|
*/ |
|
182
|
|
|
protected function exportLangs() |
|
183
|
|
|
{ |
|
184
|
|
|
foreach ($this->langs as $lang) { |
|
185
|
|
|
$langFile = resource_path('lang/'.$lang); |
|
186
|
|
|
|
|
187
|
|
|
if (! is_dir($langDir = dirname($langFile))) { |
|
188
|
|
|
mkdir($langDir, 0755, true); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
copy( |
|
192
|
|
|
__DIR__.'/../../../resources/stubs/language/'.$lang, |
|
193
|
|
|
$langFile |
|
194
|
|
|
); |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Export the controllers. |
|
200
|
|
|
* |
|
201
|
|
|
* @return void |
|
202
|
|
|
*/ |
|
203
|
|
|
protected function exportControllers() |
|
204
|
|
|
{ |
|
205
|
|
|
foreach ($this->controllers as $controller) { |
|
206
|
|
|
$controllerFile = app_path('Http/Controllers/'.$controller.'.php'); |
|
207
|
|
|
|
|
208
|
|
|
if (! is_dir($controllerDir = dirname($controllerFile))) { |
|
209
|
|
|
mkdir($controllerDir, 0755, true); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
file_put_contents( |
|
213
|
|
|
$controllerFile, |
|
214
|
|
|
$this->compileClassStub(__DIR__.'/../../../resources/stubs/controllers/'.$controller.'.stub') |
|
215
|
|
|
); |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* Export the requests. |
|
221
|
|
|
* |
|
222
|
|
|
* @return void |
|
223
|
|
|
*/ |
|
224
|
|
|
protected function exportRequests() |
|
225
|
|
|
{ |
|
226
|
|
|
foreach ($this->requests as $request) { |
|
227
|
|
|
$requestFile = app_path('Http/Requests/'.$request.'.php'); |
|
228
|
|
|
|
|
229
|
|
|
if (! is_dir($requestDir = dirname($requestFile))) { |
|
230
|
|
|
mkdir($requestDir, 0755, true); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
file_put_contents( |
|
234
|
|
|
$requestFile, |
|
235
|
|
|
$this->compileClassStub(__DIR__.'/../../../resources/stubs/requests/'.$request.'.stub') |
|
236
|
|
|
); |
|
237
|
|
|
} |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Export the routes. |
|
242
|
|
|
* |
|
243
|
|
|
* @return void |
|
244
|
|
|
*/ |
|
245
|
|
|
protected function exportRoutes() |
|
246
|
|
|
{ |
|
247
|
|
|
file_put_contents( |
|
248
|
|
|
base_path('routes/web.rinvex.fort.php'), |
|
249
|
|
|
file_get_contents(__DIR__.'/../../../resources/stubs/routes/web.rinvex.fort.stub') |
|
250
|
|
|
); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* Compiles the class stub. |
|
255
|
|
|
* |
|
256
|
|
|
* @param string $stub |
|
257
|
|
|
* |
|
258
|
|
|
* @return string |
|
259
|
|
|
*/ |
|
260
|
|
|
protected function compileClassStub($stub) |
|
261
|
|
|
{ |
|
262
|
|
|
return str_replace('{{namespace}}', $this->getAppNamespace(), file_get_contents($stub)); |
|
263
|
|
|
} |
|
264
|
|
|
} |
|
265
|
|
|
|