Passed
Push — dev ( 9d591d...c59ba0 )
by Darko
22:01
created

ResetPasswordController::reset()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 51
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
eloc 33
c 0
b 0
f 0
dl 0
loc 51
ccs 0
cts 0
cp 0
rs 9.392
cc 4
nc 6
nop 1
crap 20

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Settings;
8
use App\Models\User;
9
use Illuminate\Foundation\Auth\ResetsPasswords;
10
use Illuminate\Http\Request;
11
12
class ResetPasswordController extends Controller
13
{
14
    /*
15
    |--------------------------------------------------------------------------
16
    | Password Reset Controller
17
    |--------------------------------------------------------------------------
18
    |
19
    | This controller is responsible for handling password reset requests
20
    | and uses a simple trait to include this behavior. You're free to
21
    | explore this trait and override any methods you wish to tweak.
22
    |
23
    */
24
25
    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\Auth\ResetPasswordController.
Loading history...
26
27
    /**
28
     * Where to redirect users after resetting their password.
29
     *
30
     * @var string
31
     */
32
    protected $redirectTo = '/';
33
34
    /**
35
     * Create a new controller instance.
36
     *
37
     * @return void
38
     */
39
    public function __construct()
40
    {
41
        $this->middleware('guest');
42
    }
43
44
    /**
45
     * @param \Illuminate\Http\Request $request
46
     *
47
     * @throws \Exception
48
     */
49
    public function reset(Request $request)
50
    {
51
        $error = '';
52
        $confirmed = '';
53
        $onscreen = '';
54
        if ($request->missing('guid')) {
55
            $error = 'No reset code provided.';
56
        }
57
58
        if ($error === '') {
59
            $ret = User::getByPassResetGuid($request->input('guid'));
60
            if ($ret === null) {
61
                $error = 'Bad reset code provided.';
62
            } else {
63
64
                //
65
                // reset the password, inform the user, send out the email
66
                //
67
                User::updatePassResetGuid($ret['id'], '');
68
                $newpass = User::generatePassword();
69
                User::updatePassword($ret['id'], $newpass);
70
71
                $onscreen = 'Your password has been reset to <strong>'.$newpass.'</strong> and sent to your e-mail address.';
72
                SendPasswordResetEmail::dispatch($ret, $newpass);
73
                $confirmed = true;
74
            }
75
        }
76
77
        $theme = Settings::settingValue('site.main.style');
78
79
        $title = 'Forgotten Password';
80
        $meta_title = 'Forgotten Password';
81
        $meta_keywords = 'forgotten,password,signup,registration';
82
        $meta_description = 'Forgotten Password';
83
84
        $content = app('smarty.view')->fetch($theme.'/forgottenpassword.tpl');
85
86
        app('smarty.view')->assign(
87
                [
88
                    'content' => $content,
89
                    'title' => $title,
90
                    'meta_title' => $meta_title,
91
                    'meta_keywords' => $meta_keywords,
92
                    'meta_description' => $meta_description,
93
                    'email' => $ret['email'] ?? '',
94
                    'confirmed' => $confirmed,
95
                    'error' => $error,
96
                    'notice' => $onscreen,
97
                ]
98
            );
99
        app('smarty.view')->display($theme.'/basepage.tpl');
100
    }
101
}
102