Skip to content

Commit 4baee2f

Browse files
committed
Merge branch 'master' into 3.0
2 parents 629973d + bf78ee7 commit 4baee2f

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,37 @@ To customize the migration, publish it with the following command:
8686
php artisan vendor:publish --provider="Jrean\UserVerification\UserVerificationServiceProvider" --tag="migrations"
8787
```
8888

89+
## Middleware
90+
91+
### Default middleware
92+
93+
This package ships with an optional middleware throwing a `UserNotVerifiedException`. You can setup the desired behaviour, for example a redirect to a specific page, in the `app\Exceptions\Handler.php`. Please refer to the [Laravel Documentation](https://laravel.com/docs/master/errors#the-exception-handler) to learn more about how to work with the exception handler.
94+
95+
To register the default middleware add the following to the `$routeMiddleware` array within the `app/Http/Kernel.php` file:
96+
97+
```php
98+
protected $routeMiddleware = [
99+
// …
100+
'isVerified' => Jrean\UserVerification\Middleware\IsVerified::class,
101+
```
102+
103+
Apply the middleware on your routes:
104+
105+
```php
106+
Route::group(['middleware' => ['web', 'isVerified']], function () {
107+
108+
```
109+
110+
### Custom middleware
111+
112+
Create your own custom middleware using the following artisan command:
113+
114+
```
115+
php artisan make:middleware IsVerified
116+
```
117+
118+
For more details about middlewares, please refer to the [Laravel Documentation](https://laravel.com/docs/5.3/middleware).
119+
89120
## E-MAIL
90121

91122
This package provides a method to send an e-mail with a link containing the verification token.
@@ -151,6 +182,10 @@ Wrong verification token.
151182

152183
The given user is already verified.
153184

185+
* `UserNotVerifiedException`
186+
187+
The given user is not yet verified.
188+
154189
* `UserNotFoundException`
155190

156191
No user found for the given e-mail adresse.
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 UserNotVerifiedException extends Exception
12+
{
13+
/**
14+
* The exception description.
15+
*
16+
* @var string
17+
*/
18+
protected $message = 'This user is not verified.';
19+
}

src/Middleware/IsVerified.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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\Middleware;
8+
9+
use Closure;
10+
use Jrean\UserVerification\Exceptions\UserNotVerifiedException;
11+
12+
class IsVerified
13+
{
14+
/**
15+
* Handle an incoming request.
16+
*
17+
* @param \Illuminate\Http\Request $request
18+
* @param \Closure $next
19+
* @return mixed
20+
*
21+
* @throws Jrean\UserVerification\Exceptions\UserNotVerifiedException
22+
*/
23+
public function handle($request, Closure $next)
24+
{
25+
if( ! $request->user()->verified){
26+
throw new UserNotVerifiedException;
27+
}
28+
29+
return $next($request);
30+
}
31+
}

0 commit comments

Comments
 (0)