22
33namespace Jrean \UserVerification \Traits ;
44
5+ use Illuminate \Http \Request ;
6+ use Illuminate \Support \Facades \Validator ;
57use Jrean \UserVerification \Facades \UserVerification ;
8+ use Jrean \UserVerification \Exceptions \UserNotFoundException ;
9+ use Jrean \UserVerification \Exceptions \UserIsVerifiedException ;
610
711trait VerifiesUsers
812{
@@ -14,16 +18,16 @@ trait VerifiesUsers
1418 * @param string $token
1519 * @return Response
1620 */
17- public function getVerification ($ token )
21+ public function getVerification (Request $ request , $ token )
1822 {
19- $ user = UserVerification:: getUser ( $ token , $ this ->userTable () );
23+ $ this ->validateRequest ( $ request );
2024
21- if (UserVerification::isVerified ($ user )) {
22- return redirect ($ this ->redirectIfVerified ());
23- }
24-
25- if (! UserVerification::process ($ user , $ token )) {
25+ try {
26+ UserVerification::process ($ request ->input ('email ' ), $ token , $ this ->userTable ());
27+ } catch (UserNotFoundException $ e ) {
2628 return redirect ($ this ->redirectIfVerificationFails ());
29+ } catch (UserIsVerifiedException $ e ) {
30+ return redirect ($ this ->redirectIfVerified ());
2731 }
2832
2933 return redirect ($ this ->redirectAfterVerification ());
@@ -39,12 +43,29 @@ public function getVerificationError()
3943 return view ($ this ->verificationErrorView ());
4044 }
4145
46+ /**
47+ * Validate the verification link.
48+ *
49+ * @param string $token
50+ * @return Response
51+ */
52+ protected function validateRequest (Request $ request )
53+ {
54+ $ validator = Validator::make ($ request ->all (), [
55+ 'email ' => 'required|email '
56+ ]);
57+
58+ if ($ validator ->fails ()) {
59+ return redirect ($ this ->redirectIfVerificationFails ());
60+ }
61+ }
62+
4263 /**
4364 * Get the verification error view name.
4465 *
4566 * @return string
4667 */
47- public function verificationErrorView ()
68+ protected function verificationErrorView ()
4869 {
4970 return property_exists ($ this , 'verificationErrorView ' ) ? $ this ->verificationErrorView : 'errors.user-verification ' ;
5071 }
@@ -54,7 +75,7 @@ public function verificationErrorView()
5475 *
5576 * @return string
5677 */
57- public function userTable ()
78+ protected function userTable ()
5879 {
5980 return property_exists ($ this , 'userTable ' ) ? $ this ->userTable : 'users ' ;
6081 }
0 commit comments