Completed
Pull Request — develop (#50)
by Marcus
01:43
created

ReauthenticationController::setSession()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Fort\Http\Controllers\Frontarea;
6
7
use Cortex\Fort\Traits\TwoFactorAuthenticatesUsers;
8
use Illuminate\Support\Facades\Hash;
9
use Illuminate\Http\Request;
10
use Cortex\Foundation\Http\Controllers\AuthenticatedController;
11
12
class ReauthenticationController extends AuthenticatedController
13
{
14
15
    use TwoFactorAuthenticatesUsers;
16
17
    /**
18
     * @param Request $request
19
     *
20
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
21
     */
22
    public function processPassword( Request $request ) {
23
24
        $session_name = session('cortex.fort.reauthentication.session_name');
25
        $redirect_url = session('cortex.fort.reauthentication.intended');
26
27
        if( Hash::check($request->input('password'), request()->user()->password) ) {
28
            $this->setSession($session_name);
29
30
            return intend([
31
                'intended' => url($redirect_url)
32
            ]);
33
        } else {
34
            return intend([
35
                'intended' => url($redirect_url),
36
                'withErrors' => ['password' => trans('cortex/fort::messages.auth.failed')
37
                ]
38
            ]);
39
        }
40
    }
41
42
    /**
43
     * @param Request $request
44
     *
45
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
46
     */
47
    public function processTwofactor( Request $request ) {
48
49
        $session_name = session('cortex.fort.reauthentication.session_name');
50
        $redirect_url = session('cortex.fort.reauthentication.intended');
51
52
        $guard = $this->getGuard();
53
        $token = $request->input('token');
54
        $user = $request->user($guard);
55
56
        if( $this->attemptTwoFactor($user, $token) ) {
0 ignored issues
show
Documentation introduced by
$token is of type string|array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
            $this->setSession($session_name);
58
59
            return intend([
60
                'intended' => url($redirect_url)
61
            ]);
62
        } else {
63
            return intend([
64
                'intended' => url($redirect_url),
65
                'withErrors' => ['token' => trans('cortex/fort::messages.verification.twofactor.invalid_token')],
66
            ]);
67
        }
68
    }
69
70
    /**
71
     * @param $session_name
72
     */
73
    protected  function setSession($session_name) {
0 ignored issues
show
Coding Style Naming introduced by
The parameter $session_name is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
74
        session()->put($session_name, time());
75
        session()->forget('cortex.fort.reauthentication.session_name');
76
        session()->forget('cortex.fort.reauthentication.intended');
77
        session()->forget('rinvex.fort.twofactor.totp');
78
    }
79
80
}
81