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