|
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) |
|
45
|
|
|
{ |
|
46
|
|
|
if ($request->missing('guid')) { |
|
47
|
|
|
return redirect()->route('password.request')->withErrors(['error' => 'No reset code provided.']); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$ret = User::getByPassResetGuid($request->input('guid')); |
|
51
|
|
|
if ($ret === null) { |
|
52
|
|
|
return redirect()->route('password.request')->withErrors(['error' => 'Bad reset code provided.']); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
// Check if user is soft deleted |
|
56
|
|
|
$user = User::withTrashed()->find($ret['id']); |
|
57
|
|
|
if ($user && $user->trashed()) { |
|
58
|
|
|
return redirect()->route('password.request')->withErrors(['error' => 'This account has been deactivated.']); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
// Reset the password, inform the user, send out the email |
|
62
|
|
|
User::updatePassResetGuid($ret['id'], ''); |
|
63
|
|
|
$newpass = User::generatePassword(); |
|
64
|
|
|
User::updatePassword($ret['id'], $newpass); |
|
65
|
|
|
|
|
66
|
|
|
SendPasswordResetEmail::dispatch($ret, $newpass); |
|
67
|
|
|
|
|
68
|
|
|
return redirect()->route('login') |
|
69
|
|
|
->with('message', 'Your password has been reset to <strong>'.$newpass.'</strong> and sent to your e-mail address.') |
|
70
|
|
|
->with('message_type', 'success'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function showResetForm(Request $request, $token = null) |
|
74
|
|
|
{ |
|
75
|
|
|
return view('auth.passwords.reset')->with([ |
|
76
|
|
|
'token' => $token, |
|
77
|
|
|
'email' => $request->email, |
|
78
|
|
|
]); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|