Completed
Push — master ( 1c99c3...427db9 )
by Abdelrahman
02:46
created

PhoneVerificationRequest::forbiddenResponse()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 16
nop 0
dl 0
loc 19
rs 8.8571
c 0
b 0
f 0
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\Requests\Frontend;
17
18
use Illuminate\Support\Facades\Auth;
19
use Rinvex\Support\Http\Requests\FormRequest;
20
21
class PhoneVerificationRequest extends FormRequest
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function forbiddenResponse()
27
    {
28
        $user        = Auth::guard()->user();
29
        $attemptUser = Auth::guard()->attemptUser();
30
31
        return $user && ! $user->country ? intend([
32
            // Logged in user, no country, phone verification attempt (account update)
33
            'route'      => 'rinvex.fort.frontend.user.settings',
34
            'withErrors' => ['country' => trans('rinvex/fort::frontend/messages.account.country_required')],
35
        ]) : ($attemptUser && ! $attemptUser->country ? intend([
36
            // Login attempt, no country, enabled Two-Factor
37
            'route'      => 'rinvex.fort.frontend.auth.login',
38
            'withErrors' => ['rinvex.fort.auth.country' => trans('rinvex/fort::frontend/messages.verification.twofactor.phone.country_required')],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 146 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...
39
        ]) : intend([
40
            // No login attempt, no user instance, phone verification attempt
41
            'route'      => 'rinvex.fort.frontend.auth.login',
42
            'withErrors' => ['rinvex.fort.auth.required' => trans('rinvex/fort::frontend/messages.auth.session.required')],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 123 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...
43
        ]));
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function response(array $errors)
50
    {
51
        // If we've got errors, remember Two-Factor persistence
52
        Auth::guard()->rememberTwoFactor();
53
54
        return parent::response($errors);
55
    }
56
57
    /**
58
     * Determine if the user is authorized to make this request.
59
     *
60
     * @return bool
61
     */
62
    public function authorize()
63
    {
64
        $user      = Auth::guard()->user() ?: Auth::guard()->attemptUser();
65
        $providers = config('rinvex.fort.twofactor.providers');
66
67
        return ! $user || ! $user->country || ! in_array('phone', $providers) ? false : true;
68
    }
69
70
    /**
71
     * Get the validation rules that apply to the request.
72
     *
73
     * @return array
74
     */
75
    public function rules()
76
    {
77
        return $this->isMethod('post') ? [
78
            'token' => 'required|numeric',
79
        ] : [];
80
    }
81
}
82