|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Auth; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Support\Facades\Hash; |
|
8
|
|
|
use Illuminate\Support\Facades\Password; |
|
9
|
|
|
use Illuminate\Auth\Events\PasswordReset; |
|
10
|
|
|
|
|
11
|
|
|
use App\Http\Controllers\Controller; |
|
12
|
|
|
use App\Http\Requests\Auth\ResetTokenRequest; |
|
13
|
|
|
|
|
14
|
|
|
class ResetPasswordSubmitController extends Controller |
|
15
|
|
|
{ |
|
16
|
|
|
public function __construct() |
|
17
|
|
|
{ |
|
18
|
|
|
// To help prevent bots, we will not allow more than 50 Reset attempts within a two hour period |
|
19
|
|
|
$this->middleware('throttle:50,120'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Submit the Reset Password via token request |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __invoke(ResetTokenRequest $request) |
|
26
|
|
|
{ |
|
27
|
|
|
$status = Password::reset( |
|
28
|
|
|
$request->only('email', 'password', 'password_confirmation', 'token'), function($user, $password) |
|
29
|
|
|
{ |
|
30
|
|
|
// Determine the new expiration date |
|
31
|
|
|
$expires = config('auth.passwords.settings.expire') ? Carbon::now()->addDays(config('auth.passwords.settings.expire')) : null; |
|
32
|
|
|
|
|
33
|
|
|
$user->forceFill([ |
|
34
|
|
|
'password' => Hash::make($password), |
|
35
|
|
|
'password_expires' => $expires, |
|
36
|
|
|
]); |
|
37
|
|
|
|
|
38
|
|
|
$user->save(); |
|
39
|
|
|
event(new PasswordReset($user)); |
|
40
|
|
|
} |
|
41
|
|
|
); |
|
42
|
|
|
|
|
43
|
|
|
return $status == Password::PASSWORD_RESET |
|
44
|
|
|
? redirect()->route('login.index')->with([ |
|
45
|
|
|
'message' => 'Password Successfully Updated', |
|
46
|
|
|
'type' => 'success' |
|
47
|
|
|
]) : back()->withErrors(['email' => [__($status)]]); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|