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

ForgotPasswordController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
eloc 38
c 0
b 0
f 0
dl 0
loc 87
ccs 0
cts 3
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B showLinkRequestForm() 0 57 8
A __construct() 0 3 1
1
<?php
2
3
namespace App\Http\Controllers\Auth;
4
5
use App\Http\Controllers\Controller;
6
use App\Jobs\SendPasswordForgottenEmail;
7
use App\Models\Settings;
8
use App\Models\User;
9
use DariusIII\Token\Facades\Token;
10
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
11
use Illuminate\Http\Request;
12
13
class ForgotPasswordController extends Controller
14
{
15
    /*
16
    |--------------------------------------------------------------------------
17
    | Password Reset Controller
18
    |--------------------------------------------------------------------------
19
    |
20
    | This controller is responsible for handling password reset emails and
21
    | includes a trait which assists in sending these notifications from
22
    | your application to your users. Feel free to explore this trait.
23
    |
24
    */
25
26
    use SendsPasswordResetEmails;
27
28
    /**
29
     * Create a new controller instance.
30
     *
31
     * @return void
32
     */
33
    public function __construct()
34
    {
35
        $this->middleware('guest');
36
    }
37
38
    /**
39
     * @param \Illuminate\Http\Request $request
40
     *
41
     * @throws \Exception
42
     */
43
    public function showLinkRequestForm(Request $request)
44
    {
45
        $sent = '';
46
        $email = request()->input('email') ?? '';
47
        $rssToken = request()->input('apikey') ?? '';
48
        if (empty($email) && empty($rssToken)) {
49
            app('smarty.view')->assign('error', 'Missing parameter(email and/or apikey to send password reset');
50
        } else {
51
            if (config('captcha.enabled') === true && (! empty(config('captcha.secret')) && ! empty(config('captcha.sitekey')))) {
52
                $this->validate($request, [
53
                    'g-recaptcha-response' => 'required|captcha',
54
                ]);
55
            }
56
            //
57
            // Check users exists and send an email
58
            //
59
            $ret = ! empty($rssToken) ? User::getByRssToken($rssToken) : User::getByEmail($email);
60
            if ($ret === null) {
61
                app('smarty.view')->assign('error', 'The email or apikey are not recognised.');
62
                $sent = true;
63
            } else {
64
                //
65
                // Generate a forgottenpassword guid, store it in the user table
66
                //
67
                $guid = Token::random(32);
68
                User::updatePassResetGuid($ret['id'], $guid);
69
                //
70
                // Send the email
71
                //
72
                $resetLink = url('/').'/resetpassword?guid='.$guid;
0 ignored issues
show
Bug introduced by
Are you sure url('/') of type Illuminate\Contracts\Routing\UrlGenerator|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

72
                $resetLink = /** @scrutinizer ignore-type */ url('/').'/resetpassword?guid='.$guid;
Loading history...
73
                SendPasswordForgottenEmail::dispatch($ret, $resetLink);
74
                $sent = true;
75
            }
76
        }
77
78
        $theme = Settings::settingValue('site.main.style');
79
80
        $title = 'Forgotten Password';
81
        $meta_title = 'Forgotten Password';
82
        $meta_keywords = 'forgotten,password,signup,registration';
83
        $meta_description = 'Forgotten Password';
84
85
        $content = app('smarty.view')->fetch($theme.'/forgottenpassword.tpl');
86
87
        app('smarty.view')->assign(
88
            [
89
                'content' => $content,
90
                'title' => $title,
91
                'meta_title' => $meta_title,
92
                'meta_keywords' => $meta_keywords,
93
                'meta_description' => $meta_description,
94
                'email'     => $email,
95
                'apikey'    => $rssToken,
96
                'sent'      => $sent,
97
            ]
98
        );
99
        app('smarty.view')->display($theme.'/basepage.tpl');
100
    }
101
}
102