Skip to content

Commit e5dd287

Browse files
committed
Request validation + user email check
1 parent 42e2977 commit e5dd287

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* This file is part of Jrean\UserVerification package.
4+
*
5+
* (c) Jean Ragouin <[email protected]> <www.askjong.com>
6+
*/
7+
namespace Jrean\UserVerification\Exceptions;
8+
9+
use Exception;
10+
11+
class UserHasNoEmailException extends Exception
12+
{
13+
/**
14+
* The exception description.
15+
*
16+
* @var string
17+
*/
18+
protected $message = 'The given user instance has an empty or null email field.';
19+
}

src/Traits/VerifiesUsers.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ trait VerifiesUsers
2525
*/
2626
public function getVerification(Request $request, $token)
2727
{
28-
$this->validateRequest($request);
28+
if (! $this->validateRequest($request)) {
29+
return redirect($this->redirectIfVerificationFails());
30+
}
2931

3032
try {
3133
UserVerification::process($request->input('email'), $token, $this->userTable());
@@ -54,7 +56,7 @@ public function getVerificationError()
5456
* Validate the verification link.
5557
*
5658
* @param string $token
57-
* @return Response
59+
* @return boolean
5860
*/
5961
protected function validateRequest(Request $request)
6062
{
@@ -63,7 +65,7 @@ protected function validateRequest(Request $request)
6365
]);
6466

6567
if ($validator->fails()) {
66-
return redirect($this->redirectIfVerificationFails());
68+
return false;
6769
}
6870
}
6971

@@ -74,7 +76,9 @@ protected function validateRequest(Request $request)
7476
*/
7577
protected function verificationErrorView()
7678
{
77-
return property_exists($this, 'verificationErrorView') ? $this->verificationErrorView : 'laravel-user-verification::user-verification';
79+
return property_exists($this, 'verificationErrorView')
80+
? $this->verificationErrorView
81+
: 'laravel-user-verification::user-verification';
7882
}
7983

8084
/**
@@ -84,7 +88,9 @@ protected function verificationErrorView()
8488
*/
8589
protected function verificationEmailView()
8690
{
87-
return property_exists($this, 'verificationEmailView') ? $this->verificationEmailView : 'emails.user-verification';
91+
return property_exists($this, 'verificationEmailView')
92+
? $this->verificationEmailView
93+
: 'emails.user-verification';
8894
}
8995

9096
/**

src/UserVerification.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,15 @@ public function __construct(MailerContract $mailer, Builder $schema)
5858
*
5959
* @param \Illuminate\Contracts\Auth\Authenticatable $user
6060
* @return bool
61+
*
62+
* @throws \Jrean\UserVerification\Exceptions\UserHasNoEmailException
6163
*/
6264
public function generate(AuthenticatableContract $user)
6365
{
66+
if (is_null($user->email) || empty($user->email)) {
67+
throw new UserHasNoEmailException();
68+
}
69+
6470
return $this->saveToken($user, $this->generateToken());
6571
}
6672

0 commit comments

Comments
 (0)