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

EmailVerificationController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 76
rs 10
wmc 7
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A showEmailVerificationRequest() 0 4 1
A processEmailVerificationRequest() 0 21 2
B processEmailVerification() 0 27 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\Lang;
19
use Rinvex\Fort\Http\Requests\EmailVerification;
20
use Rinvex\Fort\Http\Controllers\AbstractController;
21
use Rinvex\Fort\Contracts\VerificationBrokerContract;
22
23
class EmailVerificationController extends AbstractController
24
{
25
    /**
26
     * Show the email verification request form.
27
     *
28
     * @return \Illuminate\Http\Response
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...
29
     */
30
    public function showEmailVerificationRequest()
31
    {
32
        return view('rinvex.fort::verification.email.request');
33
    }
34
35
    /**
36
     * Process the email verification request form.
37
     *
38
     * @param \Rinvex\Fort\Http\Requests\EmailVerification $request
39
     *
40
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
41
     */
42
    public function processEmailVerificationRequest(EmailVerification $request)
43
    {
44
        $result = app('rinvex.fort.verifier')
45
            ->broker($this->getBroker())
46
            ->sendVerificationLink($request->except('_token'));
47
48
        switch ($result) {
49
            case VerificationBrokerContract::LINK_SENT:
50
                return intend([
51
                    'intended' => route('home'),
52
                    'with'     => ['rinvex.fort.alert.success' => Lang::get($result)],
53
                ]);
54
55
            default:
56
                return intend([
57
                    'back'       => true,
58
                    'withInput'  => $request->only('email'),
59
                    'withErrors' => ['email' => Lang::get($result)],
60
                ]);
61
        }
62
    }
63
64
    /**
65
     * Process the email verification.
66
     *
67
     * @param \Rinvex\Fort\Http\Requests\EmailVerification $request
68
     *
69
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
70
     */
71
    public function processEmailVerification(EmailVerification $request)
72
    {
73
        $result = app('rinvex.fort.verifier')->broker($this->getBroker())->verify($request->except('_token'));
74
75
        switch ($result) {
76
            case VerificationBrokerContract::EMAIL_VERIFIED:
77
                return intend([
78
                    'intended' => route('home'),
79
                    'with'     => ['rinvex.fort.alert.success' => Lang::get($result)],
80
                ]);
81
82
            case VerificationBrokerContract::INVALID_USER:
83
                return intend([
84
                    'intended'   => route('rinvex.fort.verification.email'),
85
                    'withInput'  => $request->only('email'),
86
                    'withErrors' => ['email' => Lang::get($result)],
87
                ]);
88
89
            case VerificationBrokerContract::INVALID_TOKEN:
90
            default:
91
                return intend([
92
                    'intended'   => route('rinvex.fort.verification.email'),
93
                    'withInput'  => $request->only('email'),
94
                    'withErrors' => ['token' => Lang::get($result)],
95
                ]);
96
        }
97
    }
98
}
99