33namespace App \Http \Controllers \Auth ;
44
55use App \Http \Controllers \Controller ;
6- use Illuminate \Auth \Access \AuthorizationException ;
7- use Illuminate \Auth \Events \Verified ;
6+ use App \Providers \RouteServiceProvider ;
87use Illuminate \Foundation \Auth \VerifiesEmails ;
98use Illuminate \Http \Request ;
10- use Illuminate \Http \Response ;
11- use Illuminate \Support \Facades \Auth ;
129
1310class VerificationController extends Controller
1411{
@@ -19,89 +16,59 @@ class VerificationController extends Controller
1916 |
2017 | This controller is responsible for handling email verification for any
2118 | user that recently registered with the application. Emails may also
22- | be resent if the user did not receive the original email message.
19+ | be re-sent if the user didn't receive the original email message.
2320 |
2421 */
2522
26- use VerifiesEmails;
23+ use VerifiesEmails {
24+ resend as traitResend;
25+ verify as traitVerify;
26+ }
2727
2828 /**
2929 * Where to redirect users after verification.
3030 *
3131 * @var string
3232 */
33- protected $ redirectTo = ' /dashboard ' ;
33+ protected $ redirectTo = RouteServiceProvider:: HOME ;
3434
3535 /**
36- * Mark the authenticated user's email address as verified.
37- *
38- * @param \Illuminate\Http\Request $request
39- * @return \Illuminate\Http\Response
36+ * Create a new controller instance.
4037 *
41- * @throws \Illuminate\Auth\Access\AuthorizationException
38+ * @return void
4239 */
43- public function verify ( Request $ request )
40+ public function __construct ( )
4441 {
45- if (! hash_equals ((string ) $ request ->route ('id ' ), (string ) $ request ->user ()->getKey ())) {
46- throw new AuthorizationException ();
47- }
48-
49- if (! hash_equals ((string ) $ request ->hash , sha1 ($ request ->user ()->emailAddress ()))) {
50- throw new AuthorizationException ();
51- }
42+ $ this ->middleware ('auth ' );
43+ $ this ->middleware ('signed ' )->only ('verify ' );
44+ $ this ->middleware ('throttle:6,1 ' )->only ('verify ' , 'resend ' );
45+ }
5246
53- if ($ request ->user ()->hasVerifiedEmail ()) {
54- $ this ->error ('auth.confirmation.no_match ' );
55- return $ request ->wantsJson ()
56- ? new Response ('' , 204 )
57- : redirect ($ this ->redirectPath ());
58- }
47+ public function verify (Request $ request )
48+ {
49+ /** @var \Illuminate\Http\RedirectResponse $response */
50+ $ response = $ this ->traitVerify ($ request );
5951
60- if ($ request ->user ()->markEmailAsVerified ()) {
61- event (new Verified ($ request ->user ()));
52+ if ($ response ->getSession ()->has ('verified ' )) {
53+ $ this ->success ('auth.verification.success ' );
54+ } else {
55+ $ this ->error ('auth.verification.no_match ' );
6256 }
6357
64- $ this ->success ('auth.confirmation.success ' );
65-
66- return $ request ->wantsJson ()
67- ? new Response ('' , 204 )
68- : redirect ($ this ->redirectPath ())->with ('verified ' , true );
58+ return $ response ;
6959 }
7060
71- /**
72- * Resend the email verification notification.
73- *
74- * @param \Illuminate\Http\Request $request
75- * @return \Illuminate\Http\Response
76- */
7761 public function resend (Request $ request )
7862 {
79- if ( $ request -> user ()-> hasVerifiedEmail ()) {
80- $ this ->error ( ' auth.confirmation.already_confirmed ' );
63+ /** @var \Illuminate\Http\RedirectResponse $response */
64+ $ response = $ this ->traitResend ( $ request );
8165
82- return $ request ->wantsJson ()
83- ? new Response ('' , 204 )
84- : redirect ($ this ->redirectPath ());
66+ if ($ response ->getSession ()->has ('resent ' )) {
67+ $ this ->success ('auth.verification.sent ' , $ request ->user ()->emailAddress ());
68+ } else {
69+ $ this ->error ('auth.verification.already_verified ' );
8570 }
8671
87- $ request ->user ()->sendEmailVerificationNotification ();
88-
89- $ this ->success ('auth.confirmation.sent ' , Auth::user ()->emailAddress ());
90-
91- return $ request ->wantsJson ()
92- ? new Response ('' , 202 )
93- : redirect ()->route ('dashboard ' )->with ('resent ' , true );
94- }
95-
96- /**
97- * Create a new controller instance.
98- *
99- * @return void
100- */
101- public function __construct ()
102- {
103- $ this ->middleware ('auth ' );
104- $ this ->middleware ('signed ' )->only ('verify ' );
105- $ this ->middleware ('throttle:6,1 ' )->only ('verify ' , 'resend ' );
72+ return $ response ;
10673 }
10774}
0 commit comments