Passed
Push — master ( 72576e...ceb7cb )
by Paul
04:15
created

Http/Controllers/Auth/VerificationController.php (5 issues)

1
<?php
2
3
namespace Devpri\Tinre\Http\Controllers\Auth;
4
5
use Devpri\Tinre\Http\Controllers\Controller;
6
use Illuminate\Auth\Access\AuthorizationException;
7
use Illuminate\Http\Request;
8
use Illuminate\Http\Response;
9
10
class VerificationController extends Controller
11
{
12
    /*
13
    |--------------------------------------------------------------------------
14
    | Email Verification Controller
15
    |--------------------------------------------------------------------------
16
    |
17
    | This controller is responsible for handling email verification for any
18
    | user that recently registered with the application. Emails may also
19
    | be re-sent if the user didn't receive the original email message.
20
    |
21
    */
22
23
    /**
24
     * Where to redirect users after verification.
25
     */
26 1
    public function redirectTo()
27
    {
28 1
        return route('dashboard');
29
    }
30
31
    /**
32
     * Create a new controller instance.
33
     *
34
     * @return void
35
     */
36 1
    public function __construct()
37
    {
38 1
        $this->middleware('auth');
39 1
        $this->middleware('signed')->only('verify');
40 1
        $this->middleware('throttle:6,1')->only('verify', 'resend');
41 1
    }
42
43
    /**
44
     * Show the email verification notice.
45
     *
46
     * @param  \Illuminate\Http\Request  $request
47
     * @return \Illuminate\Http\Response
48
     */
49
    public function show(Request $request)
50
    {
51
        return $request->user()->hasVerifiedEmail()
0 ignored issues
show
Bug Best Practice introduced by
The expression return $request->user()-...w('tinre::auth.verify') returns the type Illuminate\Http\Redirect...se|Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
52
            ? redirect($this->redirectTo())
53
            : view('tinre::auth.verify');
54
    }
55
56
    /**
57
     * Mark the authenticated user's email address as verified.
58
     *
59
     * @param  \Illuminate\Http\Request  $request
60
     * @return \Illuminate\Http\Response
61
     *
62
     * @throws \Illuminate\Auth\Access\AuthorizationException
63
     */
64 1
    public function verify(Request $request)
65
    {
66 1
        if (! hash_equals((string) $request->route('id'), (string) $request->user()->getKey())) {
67
            throw new AuthorizationException;
68
        }
69
70 1
        if (! hash_equals((string) $request->route('hash'), sha1($request->user()->getEmailForVerification()))) {
71
            throw new AuthorizationException;
72
        }
73
74 1
        if ($request->user()->hasVerifiedEmail()) {
75
            return $request->wantsJson()
0 ignored issues
show
Bug Best Practice introduced by
The expression return $request->wantsJs...ct($this->redirectTo()) also could return the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
76
                ? new Response('', 204)
77
                : redirect($this->redirectTo());
78
        }
79
80 1
        $request->user()->markEmailAsVerified();
81
82 1
        return $request->wantsJson()
0 ignored issues
show
Bug Best Practice introduced by
The expression return $request->wantsJs... email was verified!')) also could return the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
83
            ? new Response('', 204)
84 1
            : redirect($this->redirectTo())->with('status', __('The email was verified!'));
85
    }
86
87
    /**
88
     * Resend the email verification notification.
89
     *
90
     * @param  \Illuminate\Http\Request  $request
91
     * @return \Illuminate\Http\Response
92
     */
93
    public function resend(Request $request)
94
    {
95
        if ($request->user()->hasVerifiedEmail()) {
96
            return $request->wantsJson()
0 ignored issues
show
Bug Best Practice introduced by
The expression return $request->wantsJs...ct($this->redirectTo()) also could return the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
97
                ? new Response('', 204)
98
                : redirect($this->redirectTo());
99
        }
100
101
        $request->user()->sendEmailVerificationNotification();
102
103
        return $request->wantsJson()
0 ignored issues
show
Bug Best Practice introduced by
The expression return $request->wantsJs...)->with('resent', true) also could return the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
104
            ? new Response('', 202)
105
            : back()->with('resent', true);
106
    }
107
}
108