VerifyUserController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 6
dl 0
loc 92
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A confirm() 0 22 3
A resendConfirmationCode() 0 6 1
A resendVerify() 0 4 1
A resendConfirmCodeforAuthUser() 0 10 1
1
<?php
2
3
namespace App\Http\Controllers\Auth;
4
5
use App\Events\UserCreationRequestSent;
6
use App\Http\Requests\ResendConfirmationRequest;
7
use Illuminate\Http\Request;
8
use App\Repositories\UserRepository;
9
use Illuminate\Contracts\Events\Dispatcher;
10
use App\Http\Controllers\Controller;
11
use Auth;
12
use Log;
13
14
class VerifyUserController extends Controller
15
{
16
    /**
17
     * @var UserRepository;
18
     */
19
    private $users;
20
21
    /**
22
     * @var Dispatcher
23
     */
24
    private $events;
25
26
    /**
27
     * VerifyUserController constructor.
28
     * @param UserRepository $users
29
     * @param Dispatcher $events
30
     */
31
    public function __construct(UserRepository $users, Dispatcher $events)
32
    {
33
        $this->users = $users;
34
        $this->events = $events;
35
    }
36
    
37
    /**
38
     * Confirm the account.
39
     *
40
     * @param Request $request
41
     * @param $code
42
     * @return mixed
43
     */
44
    public function confirm(Request $request, $code)
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...
45
    {
46
        $user = $this->users->getByConfirmationCode($code);
47
48
        if ($user) {
49
            if (! $user->confirmed) {
50
                
51
                $this->users->confirmate($user);
52
                
53
                return redirect()->guest('login')
54
                    ->with('status', 'You have successfully confirm your account.');
55
            } else {
56
                $message = 'You have already confirm the account.';
57
58
                return redirect()->route('get_login')->with('message', $message);
59
            }
60
        } else {
61
            $message = 'Invalid confirmation code.';
62
63
            abort('404', $message);
64
        }
65
    }
66
67
    /**
68
     * @param ResendConfirmationRequest $request
69
     * @return mixed
70
     */
71
    public function resendConfirmationCode(ResendConfirmationRequest $request)
72
    {
73
        $this->resendConfirmCodeforAuthUser($request);
74
75
        return redirect()->back()->withSuccess('Confirmation code was sent.');
76
    }
77
78
    /**
79
     * Resend verify form.
80
     *
81
     * @param ResendConfirmationRequest $request
82
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
83
     */
84
    public function resendVerify(ResendConfirmationRequest $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...
85
    {
86
        return view('auth.resend_verify');
87
    }
88
89
    /**
90
     * Resend confirmation code.
91
     *
92
     * @param ResendConfirmationRequest $request
93
     * @return void.
0 ignored issues
show
Documentation introduced by
The doc-type void. could not be parsed: Unknown type name "void." at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
94
     */
95
    private function resendConfirmCodeforAuthUser(ResendConfirmationRequest $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...
96
    {
97
        $user = \Auth::user();
98
99
        $user->confirmation_code = str_random(30);
100
101
        $user->save();
102
103
        $this->events->fire(new UserCreationRequestSent($user));
104
    }
105
}