Passed
Push — dev6 ( 38538a...e3b17c )
by Ron
20:02
created

ResetPasswordSubmitController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 1
b 0
f 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 23 3
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