1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Auth; |
4
|
|
|
|
5
|
|
|
use Illuminate\Routing\Controllers\HasMiddleware; |
6
|
|
|
use Illuminate\Routing\Controllers\Middleware; |
7
|
|
|
use App\Http\Controllers\Controller; |
8
|
|
|
use App\Jobs\SendPasswordResetEmail; |
9
|
|
|
use App\Models\User; |
10
|
|
|
use Illuminate\Foundation\Auth\ResetsPasswords; |
11
|
|
|
use Illuminate\Http\Request; |
12
|
|
|
|
13
|
|
|
class ResetPasswordController extends Controller implements HasMiddleware |
14
|
|
|
{ |
15
|
|
|
/* |
16
|
|
|
|-------------------------------------------------------------------------- |
17
|
|
|
| Password Reset Controller |
18
|
|
|
|-------------------------------------------------------------------------- |
19
|
|
|
| |
20
|
|
|
| This controller is responsible for handling password reset requests |
21
|
|
|
| and uses a simple trait to include this behavior. You're free to |
22
|
|
|
| explore this trait and override any methods you wish to tweak. |
23
|
|
|
| |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
use ResetsPasswords; |
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Where to redirect users after resetting their password. |
30
|
|
|
*/ |
31
|
|
|
protected string $redirectTo = '/'; |
32
|
|
|
|
33
|
|
|
public static function middleware(): array |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
|
|
'guest', |
37
|
|
|
]; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @throws \Exception |
42
|
|
|
*/ |
43
|
|
|
public function reset(Request $request): void |
44
|
|
|
{ |
45
|
|
|
$error = ''; |
46
|
|
|
$confirmed = ''; |
47
|
|
|
$onscreen = ''; |
48
|
|
|
if ($request->missing('guid')) { |
49
|
|
|
$error = 'No reset code provided.'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ($error === '') { |
53
|
|
|
$ret = User::getByPassResetGuid($request->input('guid')); |
54
|
|
|
if ($ret === null) { |
55
|
|
|
$error = 'Bad reset code provided.'; |
56
|
|
|
} else { |
57
|
|
|
// |
58
|
|
|
// reset the password, inform the user, send out the email |
59
|
|
|
// |
60
|
|
|
User::updatePassResetGuid($ret['id'], ''); |
61
|
|
|
$newpass = User::generatePassword(); |
62
|
|
|
User::updatePassword($ret['id'], $newpass); |
63
|
|
|
|
64
|
|
|
$onscreen = 'Your password has been reset to <strong>'.$newpass.'</strong> and sent to your e-mail address.'; |
65
|
|
|
SendPasswordResetEmail::dispatch($ret, $newpass); |
66
|
|
|
$confirmed = true; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$theme = 'Gentele'; |
71
|
|
|
|
72
|
|
|
$title = 'Forgotten Password'; |
73
|
|
|
$meta_title = 'Forgotten Password'; |
74
|
|
|
$meta_keywords = 'forgotten,password,signup,registration'; |
75
|
|
|
$meta_description = 'Forgotten Password'; |
76
|
|
|
|
77
|
|
|
$content = app('smarty.view')->fetch($theme.'/forgottenpassword.tpl'); |
78
|
|
|
|
79
|
|
|
app('smarty.view')->assign( |
80
|
|
|
[ |
81
|
|
|
'content' => $content, |
82
|
|
|
'title' => $title, |
83
|
|
|
'meta_title' => $meta_title, |
84
|
|
|
'meta_keywords' => $meta_keywords, |
85
|
|
|
'meta_description' => $meta_description, |
86
|
|
|
'email' => $ret['email'] ?? '', |
87
|
|
|
'confirmed' => $confirmed, |
88
|
|
|
'error' => $error, |
89
|
|
|
'notice' => $onscreen, |
90
|
|
|
] |
91
|
|
|
); |
92
|
|
|
app('smarty.view')->display($theme.'/basepage.tpl'); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|