ResetPasswordController   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 35
dl 0
loc 134
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A sendResetFailedResponse() 0 3 1
A sendResetResponse() 0 3 1
A showResetForm() 0 18 4
A rules() 0 6 1
A credentials() 0 7 1
1
<?php
2
3
namespace App\Http\Controllers\Frontend\Auth;
4
5
use App\Http\Controllers\Controller;
6
use App\Models\Access\User\User;
7
use App\Repositories\Frontend\Access\User\UserRepository;
8
use Illuminate\Foundation\Auth\ResetsPasswords;
9
use Illuminate\Http\Request;
10
use Illuminate\Support\Str;
11
12
/**
13
 * Class ResetPasswordController.
14
 */
15
class ResetPasswordController extends Controller
16
{
17
    use ResetsPasswords;
0 ignored issues
show
Bug introduced by
The trait Illuminate\Foundation\Auth\ResetsPasswords requires the property $email which is not provided by App\Http\Controllers\Fro...ResetPasswordController.
Loading history...
18
19
    /**
20
     * @var UserRepository
21
     */
22
    protected $user;
23
24
    protected $redirectTo = '/dashboard';
25
26
    /**
27
     * ChangePasswordController constructor.
28
     *
29
     * @param UserRepository $user
30
     */
31
    public function __construct(UserRepository $user)
32
    {
33
        $this->user = $user;
34
    }
35
36
    /**
37
     * Where to redirect users after resetting password.
38
     *
39
     * @return string
40
     */
41
    public function redirectPath()
42
    {
43
        return route('frontend.user.dashboard');
44
    }
45
46
    /**
47
     * Reset the given user's password.
48
     *
49
     * @param  User $user
50
     * @param  string $password
51
     *
52
     * @return void
53
     */
54
    protected function resetPassword($user, $password)
55
    {
56
        $user->forceFill([
57
        'password'       => bcrypt($password),
58
        'remember_token' => Str::random(60),
59
        'confirmed'      => 1,
60
        ])
61
         ->save();
62
63
        $this->guard()
64
         ->login($user);
65
    }
66
67
    /**
68
     * Display the password reset view for the given token.
69
     *
70
     * If no token is present, display the link request form.
71
     *
72
     * @param string|null $token
73
     *
74
     * @return \Illuminate\Http\Response
75
     */
76
    public function showResetForm($token = null)
77
    {
78
        if (! $token) {
79
            return redirect()->route('frontend.auth.password.email');
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...d.auth.password.email') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
80
        }
81
82
        $user = $this->user->findByPasswordResetToken($token);
83
84
        if ($user && app()->make('auth.password.broker')->tokenExists($user, $token)) {
85
            return view('frontend.auth.passwords.reset')
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('frontend.au...thName($user->nickname) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
86
                ->withToken($token)
87
                ->withEmail($user->email)
88
                ->withName($user->nickname);
89
        }
90
91
        return redirect()
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...ssword.reset_problem')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
92
            ->route('frontend.auth.password.email')
93
            ->withFlashDanger(trans('exceptions.frontend.auth.password.reset_problem'));
94
    }
95
96
    /**
97
     * Get the password reset validation rules.
98
     *
99
     * @return array
100
     */
101
    protected function rules()
102
    {
103
        return [
104
        'token'    => 'required',
105
        'nickname' => 'required',
106
        'password' => 'required|confirmed|min:6',
107
        ];
108
    }
109
110
    /**
111
     * Get the password reset credentials from the request.
112
     *
113
     * @param  \Illuminate\Http\Request $request
114
     *
115
     * @return array
116
     */
117
    protected function credentials(Request $request)
118
    {
119
        return $request->only(
120
            'nickname',
121
            'password',
122
            'password_confirmation',
123
            'token'
124
        );
125
    }
126
127
    /**
128
     * Get the response for a failed password reset.
129
     *
130
     * @param  \Illuminate\Http\Request
131
     * @param  string $response
132
     *
133
     * @return \Illuminate\Http\RedirectResponse
134
     */
135
    protected function sendResetFailedResponse(Request $request, $response)
136
    {
137
        return redirect()->back()->withInput($request->only('nickname'))->withErrors(['nickname' => trans($response)]);
138
    }
139
140
    /**
141
     * Get the response for a successful password reset.
142
     *
143
     * @param  string  $response
144
     * @return \Illuminate\Http\RedirectResponse
145
     */
146
    protected function sendResetResponse($response)
147
    {
148
        return redirect()->route(homeRoute())->withFlashSuccess(trans($response));
149
    }
150
}
151