Skip to content

Commit daf4487

Browse files
committed
Merge branch 'veare-route-improvement' into 3.0
2 parents c78829d + a8096b3 commit daf4487

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

README.md

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ Or run the following command:
4343
composer require jrean/laravel-user-verification
4444

4545

46-
### Add the Service Provider
46+
### Add the Service Provider & Facade/Alias
4747

48-
Once Larvel User Verification is installed, you need to register the service provider.
49-
50-
Open up `config/app.php` and add the following to the `providers` key:
48+
Once Larvel User Verification is installed, you need to register the service provider in `config/app.php`. Make sure to add the following line **above** the `RouteServiceProvider`.
5149

50+
```php
5251
Jrean\UserVerification\UserVerificationServiceProvider::class,
52+
```
5353

54-
### Add the Facade/Alias
55-
56-
Open up `config/app.php` and add the following to the `aliases` key:
54+
You may add the following `aliases` to your `config/app.php`:
5755

56+
```php
5857
'UserVerification' => Jrean\UserVerification\Facades\UserVerification::class
58+
```
5959

6060
## CONFIGURATION
6161

@@ -161,7 +161,7 @@ Here is a sample e-mail view content to get you started with:
161161
query string with the user's e-mail as parameter.**
162162

163163
```
164-
Click here to verify your account: <a href="{{ $link = url('verification', $user->verification_token) . '?email=' . urlencode($user->email) }}"> {{ $link }}</a>
164+
Click here to verify your account: <a href="{{ $link = route('email-verification.check', $user->verification_token) . '?email=' . urlencode($user->email) }}"> {{ $link }}</a>
165165
```
166166

167167
## ERRORS
@@ -189,7 +189,7 @@ No user found for the given e-mail adresse.
189189

190190
### Error View
191191

192-
By default the `user-verification.blade.php` view will be loaded for the verification error route `/verification/error`. If an error occurs, the user will be redirected to this route and this view will be rendered.
192+
By default the `user-verification.blade.php` view will be loaded for the verification error route `/email-verification/error`. If an error occurs, the user will be redirected to this route and this view will be rendered.
193193

194194
**You may customize this view to your needs.** To do so first publish the view to your resources folder:
195195

@@ -203,12 +203,11 @@ The view will be available in the `resources/views/vendor/laravel-user-verificat
203203

204204
### Routes
205205

206-
Add the two (2) default routes to the `routes/web.php` file. Routes are
207-
customizable.
206+
By default this packages ships with two routes, if you want to change them, you can simply define your own routes. Make sure you added the packages service provider **before** Laravels `RouteServiceProvider`, otherwise you can not overwrite the routes.
208207

209208
```PHP
210-
Route::get('verification/error', 'Auth\RegisterController@getVerificationError');
211-
Route::get('verification/{token}', 'Auth\RegisterController@getVerification');
209+
Route::get('email-verification/error', 'Auth\RegisterController@getVerificationError')->name('email-verification.error');
210+
Route::get('email-verification/check/{token}', 'Auth\RegisterController@getVerification')->name('email-verification.check');
212211
```
213212

214213
### Trait
@@ -292,7 +291,7 @@ Where to reditect if the authenticated user is already verified.
292291

293292
Where to redirect after a successful verification token verification.
294293

295-
* `$redirectIfVerificationFails = '/verification/error';`
294+
* `$redirectIfVerificationFails = '/email-verification/error';`
296295

297296
Where to redirect after a failling token verification.
298297

@@ -333,15 +332,6 @@ following Laravel logic. You are free to implement the way you want.
333332
It is highly recommended to read and to understand the way Laravel implements
334333
registration/authentication.
335334

336-
Edit the `routes/web.php` file.
337-
338-
- Define two (2) new routes.
339-
340-
```PHP
341-
Route::get('verification/error', 'Auth\RegisterController@getVerificationError');
342-
Route::get('verification/{token}', 'Auth\RegisterController@getVerification');
343-
```
344-
345335
- Define the e-mail view.
346336

347337
Edit the `app\Http\Controllers\Auth\RegisterController.php` file.
@@ -455,16 +445,16 @@ update the middleware exception to allow `getVerification` and
455445
`getVerificationError` routes to be accessed.
456446

457447
```PHP
458-
$this->middleware('guest', ['except' => ['getVerification', 'getVerificationError']]);
448+
$this->middleware('guest', ['except' => ['getVerification', 'getVerificationError']]);
459449
```
460450

461451
## Relaunch the process anytime
462452

463453
If you want to regenerate and resend the verification token, you can do this with the following two lines:
464454

465-
```php
466-
UserVerification::generate($user);
467-
UserVerification::send($user, 'My Custom E-mail Subject');
455+
```PHP
456+
UserVerification::generate($user);
457+
UserVerification::send($user, 'My Custom E-mail Subject');
468458
```
469459

470460
The `generate` method will generate a new token for the given user and change the `verified` column to 0. The `send` method will send a new e-mail to the user.

src/Traits/RedirectsUsers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ public function redirectAfterVerification()
2929
}
3030

3131
/**
32-
* Get the redirect path for a failing verification token verification.
32+
* Get the redirect path for a failing token verification.
3333
*
3434
* @return string
3535
*/
3636
public function redirectIfVerificationFails()
3737
{
38-
return property_exists($this, 'redirectIfVerificationFails') ? $this->redirectIfVerificationFails : '/verification/error';
38+
return property_exists($this, 'redirectIfVerificationFails') ? $this->redirectIfVerificationFails : route('email-verification.error');
3939
}
4040
}

src/UserVerificationServiceProvider.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ class UserVerificationServiceProvider extends ServiceProvider
1818
*/
1919
public function boot()
2020
{
21-
$this->loadViewsFrom(__DIR__.'/resources/views', 'laravel-user-verification');
21+
if (! $this->app->routesAreCached()) {
22+
require __DIR__ . '/routes.php';
23+
}
24+
25+
$this->loadViewsFrom(__DIR__ . '/resources/views', 'laravel-user-verification');
2226

2327
$this->publishes([
24-
__DIR__.'/resources/views' => resource_path('views/vendor/laravel-user-verification'),
28+
__DIR__ . '/resources/views' => resource_path('views/vendor/laravel-user-verification'),
2529
], 'laravel-user-verification-views');
2630
}
31+
2732
/**
2833
* Register the service provider.
2934
*

src/routes.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Laravel user verification routes
6+
|--------------------------------------------------------------------------
7+
*/
8+
Route::get('email-verification/error', 'Auth\RegisterController@getVerificationError')->name('email-verification.error');
9+
Route::get('email-verification/check/{token}', 'Auth\RegisterController@getVerification')->name('email-verification.check');

0 commit comments

Comments
 (0)