@@ -3,11 +3,21 @@ easily handle a user verification and validate the e-mail.
33
44[ ![ Latest Stable Version] ( https://poser.pugx.org/jrean/laravel-user-verification/v/stable )] ( https://packagist.org/packages/jrean/laravel-user-verification ) [ ![ Total Downloads] ( https://poser.pugx.org/jrean/laravel-user-verification/downloads )] ( https://packagist.org/packages/jrean/laravel-user-verification ) [ ![ License] ( https://poser.pugx.org/jrean/laravel-user-verification/license )] ( https://packagist.org/packages/jrean/laravel-user-verification )
55
6+ ## Versions
7+ ** This package is Laravel 5.3 compliant.**
8+
9+ For Laravel 5.3.* , use branch
10+ [ 3.0] ( https://github.com/jrean/laravel-user-verification/tree/3.0 )
11+ and/or [ master] ( https://github.com/jrean/laravel-user-verification/tree/master )
12+
13+ For Laravel 5.0.* | 5.1.* | 5.2.* , use branch
14+ [ 2.2] ( https://github.com/jrean/laravel-user-verification/tree/2.2 )
15+
616## About
717
818- [x] Generate and store a verification token for a registered user
919- [x] Send an e-mail with the verification token link
10- - [x] Handle the verification of the token
20+ - [x] Handle the token verification
1121- [x] Set the user as verified
1222- [x] Relaunch the process anytime
1323
@@ -19,7 +29,7 @@ require block of your composer.json file:
1929
2030 {
2131 "require": {
22- "jrean/laravel-user-verification": "^2 .0"
32+ "jrean/laravel-user-verification": "^3 .0"
2333 }
2434
2535 }
@@ -48,7 +58,7 @@ Open up `config/app.php` and add the following to the `aliases` key:
4858
4959## Configuration
5060
51- Prior to use this package the table representing the user must be updated with
61+ Prior to use this package, the table representing the user must be updated with
5262two new columns, ` verified ` and ` verification_token ` .
5363
5464** It is mandatory to add the two columns on the same table and where the user's
@@ -68,7 +78,7 @@ php artisan make:migration add_verification_to_:table_table --table=":table"
6878
6979Where ` :table ` is replaced by the table name of your choice.
7080
71- For instance if you want to keep the default Eloquent User table:
81+ For instance, if you want to keep the default Eloquent ` User ` table:
7282
7383```
7484php artisan make:migration add_verification_to_users_table --table="users"
@@ -114,13 +124,6 @@ Migrate the migration with the following command:
114124php artisan migrate
115125```
116126
117- ### Exception
118-
119- If the table representing the user is not updated with the two new columns and
120- the model representing the user doesn't implement the authenticatable interface
121- ` Illuminate\Contracts\Auth\Authenticatable ` , a ` ModelNotCompliantException `
122- will be thrown.
123-
124127## E-mail
125128
126129This package provides a method to send an e-mail with a link containing the verification token.
@@ -162,7 +165,7 @@ Click here to verify your account: <a href="{{ $link = url('verification', $user
162165## Errors
163166
164167This package throws several exceptions. You are free to use ` try/catch `
165- statements or to rely on the Laravel built-in exceptions handling .
168+ statements or to rely on the Laravel built-in exceptions handler .
166169
167170* ` ModelNotCompliantException `
168171
@@ -196,12 +199,12 @@ verify, ...).
196199
197200### Routes
198201
199- Add the two (2) default routes to the ` app\Http\ routes.php` file. Routes are
202+ Add the two (2) default routes to the ` routes/web .php ` file. Routes are
200203customizable.
201204
202205```
203- Route::get('verification/error', 'Auth\AuthController @getVerificationError');
204- Route::get('verification/{token}', 'Auth\AuthController @getVerification');
206+ Route::get('verification/error', 'Auth\RegisterController @getVerificationError');
207+ Route::get('verification/{token}', 'Auth\RegisterController @getVerification');
205208```
206209
207210### Trait
@@ -289,7 +292,7 @@ package as well as created and migrated the migration according to this
289292documentation and the previous documented steps.**
290293
291294Note that by default the behaviour of Laravel is to return an authenticated
292- user straight after the registration step.
295+ user after the registration step.
293296
294297### Example
295298
@@ -298,29 +301,29 @@ following Laravel logic. You are free to implement the way you want.
298301It is highly recommended to read and to understand the way Laravel implements
299302registration/authentication.
300303
301- Edit the ` app\Http\ routes.php` file.
304+ Edit the ` routes/web .php ` file.
302305
303306- Define two (2) new routes.
304307
305308```
306- Route::get('verification/error', 'Auth\AuthController @getVerificationError');
307- Route::get('verification/{token}', 'Auth\AuthController @getVerification');
309+ Route::get('verification/error', 'Auth\RegisterController @getVerificationError');
310+ Route::get('verification/{token}', 'Auth\RegisterController @getVerification');
308311```
309312
310313- Define the e-mail view.
311314
312- Edit the ` app\Http\Controllers\Auth\AuthController .php ` file.
315+ Edit the ` app\Http\Controllers\Auth\RegisterController .php ` file.
313316
314317- [x] Import the ` VerifiesUsers ` trait (mandatory)
315318- [ ] Overwrite and customize the redirect attributes/properties paths
316319 available within the ` RedirectsUsers ` trait included by the
317320 ` VerifiesUsers ` trait. (not mandatory)
318- - [ ] Overwrite the error view name used by the ` getVerificationError() ` method
321+ - [ ] Overwrite the default error view name used by the ` getVerificationError() ` method
319322 (not mandatory)
320- - [x] Create the verification error view (mandatory)
323+ - [x] Create the verification error view at
324+ ` resources/views/errors/user-verification.blade.php ` (mandatory)
321325- [ ] Overwrite the contructor (not mandatory)
322- - [x] Overwrite the ` postRegister() ` /` register() ` method depending on the
323- Laravel version you use (mandatory)
326+ - [x] Overwrite the ` register() ` method (mandatory)
324327
325328```
326329
@@ -329,78 +332,72 @@ Edit the `app\Http\Controllers\Auth\AuthController.php` file.
329332 use App\User;
330333 use Validator;
331334 use App\Http\Controllers\Controller;
332- use Illuminate\Foundation\Auth\ThrottlesLogins;
333- use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
335+ use Illuminate\Foundation\Auth\RegistersUsers;
336+ use Illuminate\Http\Request;
337+
334338 use Jrean\UserVerification\Traits\VerifiesUsers;
335339 use Jrean\UserVerification\Facades\UserVerification;
336- use Illuminate\Http\Request;
337- use Illuminate\Support\Facades\Auth;
338340
339- class AuthController extends Controller
341+
342+ class RegisterController extends Controller
340343 {
341344 /*
342345 |--------------------------------------------------------------------------
343- | Registration & Login Controller
346+ | Register Controller
344347 |--------------------------------------------------------------------------
345348 |
346- | This controller handles the registration of new users, as well as the
347- | authentication of existing users . By default, this controller uses
348- | a simple trait to add these behaviors. Why don't you explore it?
349+ | This controller handles the registration of new users as well as their
350+ | validation and creation . By default this controller uses a trait to
351+ | provide this functionality without requiring any additional code.
349352 |
350353 */
351354
352- use AuthenticatesAndRegistersUsers, ThrottlesLogins ;
355+ use RegistersUsers ;
353356
354357 use VerifiesUsers;
355358
356- /**
357- * Create a new authentication controller instance.
359+ /**
360+ * Create a new controller instance.
358361 *
359362 * @return void
360363 */
361364 public function __construct()
362365 {
363- // Based on the workflow you want you may update and customize the following lines.
364-
365- // Laravel 5.0.*|5.1.*
366- $this->middleware('guest', ['except' => ['getLogout', 'getVerification', 'getVerificationError']]);
366+ // Based on the workflow you need, you may update and customize the following lines.
367367
368- // Laravel 5.2.*
369- $this->middleware('guest', ['except' => ['logout', 'getVerification, 'getVerificationError]]);
370- //or
371- $this->middleware($this->guestMiddleware(), ['except' => ['logout', 'getVerification', 'getVerificationError]]);
368+ $this->middleware('guest', ['except' => ['getVerification', 'getVerificationError']]);
372369 }
373370
374- // Laravel 5.0.*|5.1.*
375371 /**
376- * Handle a registration request for the application .
372+ * Get a validator for an incoming registration request .
377373 *
378- * @param \Illuminate\Http\Request $request
379- * @return \Illuminate\Http\Response
374+ * @param array $data
375+ * @return \Illuminate\Contracts\Validation\Validator
380376 */
381- public function postRegister(Request $request )
377+ protected function validator(array $data )
382378 {
383- $validator = $this->validator($request->all());
384-
385- if ($validator->fails()) {
386- $this->throwValidationException(
387- $request, $validator
388- );
389- }
390-
391- $user = $this->create($request->all());
392-
393- // Authenticating the user is not mandatory at all.
394- Auth::login($user);
395-
396- UserVerification::generate($user);
397-
398- UserVerification::send($user, 'My Custom E-mail Subject');
379+ return Validator::make($data, [
380+ 'name' => 'required|max:255',
381+ 'email' => 'required|email|max:255|unique:users',
382+ 'password' => 'required|min:6|confirmed',
383+ ]);
384+ }
399385
400- return redirect($this->redirectPath());
386+ /**
387+ * Create a new user instance after a valid registration.
388+ *
389+ * @param array $data
390+ * @return User
391+ */
392+ protected function create(array $data)
393+ {
394+ return User::create([
395+ 'name' => $data['name'],
396+ 'email' => $data['email'],
397+ 'password' => bcrypt($data['password']),
398+ ]);
401399 }
402400
403- // Laravel 5.2.*
404401 /**
405402 * Handle a registration request for the application.
406403 *
@@ -409,26 +406,12 @@ Edit the `app\Http\Controllers\Auth\AuthController.php` file.
409406 */
410407 public function register(Request $request)
411408 {
412- $validator = $this->validator($request->all());
413-
414- if ($validator->fails()) {
415- $this->throwValidationException(
416- $request, $validator
417- );
418- }
409+ $this->validator($request->all())->validate();
419410
420411 $user = $this->create($request->all());
421-
422- // Authenticating the user is not mandatory at all.
423-
424- // Laravel <= 5.2.7
425- // Auth::login($user);
426-
427- // Laravel > 5.2.7
428- Auth::guard($this->getGuard())->login($user);
412+ $this->guard()->login($user);
429413
430414 UserVerification::generate($user);
431-
432415 UserVerification::send($user, 'My Custom E-mail Subject');
433416
434417 return redirect($this->redirectPath());
@@ -446,7 +429,7 @@ update the middleware exception to allow `getVerification` and
446429` getVerificationError ` routes to be accessed.
447430
448431```
449- $this->middleware($this->guestMiddleware() , ['except' => ['logout', 'getVerification', 'getVerificationError']]);
432+ $this->middleware('guest' , ['except' => ['getVerification', 'getVerificationError']]);
450433```
451434
452435## Contribute
0 commit comments