ResetPasswordController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A redirectTo() 0 3 1
A guard() 0 3 1
A __construct() 0 3 1
A broker() 0 3 1
A reset() 0 17 2
A showResetForm() 0 3 1
1
<?php
2
3
namespace Thinktomorrow\Chief\App\Http\Controllers\Auth;
4
5
use Illuminate\Foundation\Auth\ResetsPasswords;
6
use Illuminate\Http\Request;
7
use Illuminate\Support\Facades\Auth;
8
use Illuminate\Support\Facades\Password;
9
use Thinktomorrow\Chief\Admin\Authorization\ChiefPasswordBroker;
10
use Thinktomorrow\Chief\Admin\Authorization\ChiefPasswordBrokerResolver;
11
use Thinktomorrow\Chief\App\Http\Controllers\Controller;
12
13
class ResetPasswordController extends Controller
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;
0 ignored issues
show
introduced by
The trait Illuminate\Foundation\Auth\ResetsPasswords requires some properties which are not provided by Thinktomorrow\Chief\App\...ResetPasswordController: $email, $redirectTo
Loading history...
27
28
    public function __construct()
29
    {
30
        $this->middleware('chief-guest');
31
    }
32
33
    public function showResetForm(Request $request, $token = null)
34
    {
35
        return view('chief::admin.auth.passwords.reset')->with(['token' => $token, 'email' => $request->email]);
36
    }
37
38
    /**
39
     * @return \Illuminate\Contracts\Auth\Guard|\Illuminate\Contracts\Auth\StatefulGuard
40
     */
41
    protected function guard()
42
    {
43
        return Auth::guard('chief');
44
    }
45
46
    protected function broker()
47
    {
48
        return (new ChiefPasswordBrokerResolver(app()))->resolve();
49
    }
50
51
    public function redirectTo(): string
52
    {
53
        return route('chief.back.dashboard');
54
    }
55
56
    // Override the reset method because chief uses different lang keys and
57
    // laravel internals expects this to be of a specific value.
58
    /**
59
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
60
     */
61
    public function reset(Request $request)
62
    {
63
        $request->validate($this->rules(), $this->validationErrorMessages());
64
65
        // Here we will attempt to reset the user's password. If it is successful we
66
        // will update the password on an actual user model and persist it to the
67
        // database. Otherwise we will parse the error and return the response.
68
        $response = $this->broker()->reset($this->credentials($request), function ($user, $password) {
69
            $this->resetPassword($user, $password);
70
        });
71
72
        // If the password was successfully reset, we will redirect the user back to
73
        // the application's home authenticated view. If there is an error we can
74
        // redirect them back to where they came from with their error message.
75
        return $response == ChiefPasswordBroker::PASSWORD_RESET
76
            ? $this->sendResetResponse($request, $response)
77
            : $this->sendResetFailedResponse($request, $response);
78
    }
79
}
80