Completed
Push — master ( 03b333...573f2e )
by Abdelrahman
02:45
created

PhoneVerificationController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 91
rs 10
wmc 8
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A showPhoneVerificationRequest() 0 7 1
A processPhoneVerificationRequest() 0 11 2
A showPhoneVerification() 0 9 1
B processPhoneVerification() 0 30 4
1
<?php
2
3
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Rinvex Fort Package.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Rinvex Fort Package
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
namespace Rinvex\Fort\Http\Controllers\Frontend;
17
18
use Illuminate\Support\Facades\Auth;
19
use Illuminate\Support\Facades\Lang;
20
use Rinvex\Fort\Guards\SessionGuard;
21
use Rinvex\Fort\Http\Requests\PhoneVerification;
22
use Rinvex\Fort\Http\Controllers\AbstractController;
23
use Rinvex\Fort\Http\Requests\PhoneVerificationRequest;
24
25
class PhoneVerificationController extends AbstractController
26
{
27
    /**
28
     * Show the phone verification request form.
29
     *
30
     * @param \Rinvex\Fort\Http\Requests\PhoneVerificationRequest $request
31
     *
32
     * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
33
     */
34
    public function showPhoneVerificationRequest(PhoneVerificationRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
35
    {
36
        // If Two-Factor authentication failed, remember Two-Factor persistence
37
        Auth::guard($this->getGuard())->rememberTwoFactor();
38
39
        return view('rinvex.fort::verification.phone.request');
40
    }
41
42
    /**
43
     * Process the phone verification request form.
44
     *
45
     * @param \Rinvex\Fort\Http\Requests\PhoneVerificationRequest $request
46
     *
47
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
48
     */
49
    public function processPhoneVerificationRequest(PhoneVerificationRequest $request)
50
    {
51
        $status = app('rinvex.fort.verifier')
52
            ->broker($this->getBroker())
53
            ->sendPhoneVerification(Auth::guard($this->getGuard())->user(), $request->get('method')) ? 'sent' : 'failed';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
54
55
        return intend([
56
            'intended' => route('rinvex.fort.verification.phone.verify'),
57
            'with'     => ['rinvex.fort.alert.success' => Lang::get('rinvex.fort::message.verification.phone.'.$status)],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
58
        ]);
59
    }
60
61
    /**
62
     * Show the phone verification form.
63
     *
64
     * @param \Rinvex\Fort\Http\Requests\PhoneVerification $request
65
     *
66
     * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
67
     */
68
    public function showPhoneVerification(PhoneVerification $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
69
    {
70
        // If Two-Factor authentication failed, remember Two-Factor persistence
71
        Auth::guard($this->getGuard())->rememberTwoFactor();
72
73
        $methods = session('rinvex.fort.twofactor.methods');
74
75
        return view('rinvex.fort::verification.phone.token', compact('methods'));
76
    }
77
78
    /**
79
     * Process the phone verification form.
80
     *
81
     * @param \Rinvex\Fort\Http\Requests\PhoneVerification $request
82
     *
83
     * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use \Illuminate\Http\Redirec...inate\Http\JsonResponse.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
84
     */
85
    public function processPhoneVerification(PhoneVerification $request)
86
    {
87
        $token  = $request->get('token');
88
        $result = Auth::guard($this->getGuard())->attemptTwoFactor(Auth::guard($this->getGuard())->user(), $token);
89
90
        switch ($result) {
91
            case SessionGuard::AUTH_PHONE_VERIFIED:
92
                return intend([
93
                    'intended' => route('rinvex.fort.account.page'),
94
                    'with'     => ['rinvex.fort.alert.success' => Lang::get($result)],
95
                ]);
96
97
            case SessionGuard::AUTH_LOGIN:
98
                return intend([
99
                    'intended' => route('home'),
100
                    'with'     => ['rinvex.fort.alert.success' => Lang::get($result)],
101
                ]);
102
103
            case SessionGuard::AUTH_TWOFACTOR_FAILED:
104
            default:
105
                // If Two-Factor authentication failed, remember Two-Factor persistence
106
                Auth::guard($this->getGuard())->rememberTwoFactor();
107
108
                return intend([
109
                    'back'       => true,
110
                    'withInput'  => $request->only(['token']),
111
                    'withErrors' => ['token' => Lang::get($result)],
112
                ]);
113
        }
114
    }
115
}
116