@@ -29,7 +29,7 @@ require block of your composer.json file:
2929
3030 {
3131 "require": {
32- "jrean/laravel-user-verification": "^3 .0"
32+ "jrean/laravel-user-verification": "^2 .0"
3333 }
3434
3535 }
@@ -199,12 +199,12 @@ verify, ...).
199199
200200### Routes
201201
202- Add the two (2) default routes to the ` routes/web .php ` file. Routes are
202+ Add the two (2) default routes to the ` app\Http\ routes.php` file. Routes are
203203customizable.
204204
205205```
206- Route::get('verification/error', 'Auth\RegisterController @getVerificationError');
207- Route::get('verification/{token}', 'Auth\RegisterController @getVerification');
206+ Route::get('verification/error', 'Auth\AuthController @getVerificationError');
207+ Route::get('verification/{token}', 'Auth\AuthController @getVerification');
208208```
209209
210210### Trait
@@ -329,18 +329,18 @@ following Laravel logic. You are free to implement the way you want.
329329It is highly recommended to read and to understand the way Laravel implements
330330registration/authentication.
331331
332- Edit the ` routes/web .php ` file.
332+ Edit the ` app\Http\ routes.php` file.
333333
334334- Define two (2) new routes.
335335
336336```
337- Route::get('verification/error', 'Auth\RegisterController @getVerificationError');
338- Route::get('verification/{token}', 'Auth\RegisterController @getVerification');
337+ Route::get('verification/error', 'Auth\AuthController @getVerificationError');
338+ Route::get('verification/{token}', 'Auth\AuthController @getVerification');
339339```
340340
341341- Define the e-mail view.
342342
343- Edit the ` app\Http\Controllers\Auth\RegisterController .php ` file.
343+ Edit the ` app\Http\Controllers\Auth\AuthController .php ` file.
344344
345345- [x] Import the ` VerifiesUsers ` trait (mandatory)
346346- [ ] Overwrite and customize the redirect attributes/properties paths
@@ -351,7 +351,8 @@ Edit the `app\Http\Controllers\Auth\RegisterController.php` file.
351351- [x] Create the verification error view at
352352 ` resources/views/errors/user-verification.blade.php ` (mandatory)
353353- [ ] Overwrite the contructor (not mandatory)
354- - [x] Overwrite the ` register() ` method (mandatory)
354+ - [x] Overwrite the ` postRegister() ` /` register() ` method depending on the
355+ Laravel version you use (mandatory)
355356
356357```
357358
@@ -367,65 +368,72 @@ Edit the `app\Http\Controllers\Auth\RegisterController.php` file.
367368 use Jrean\UserVerification\Facades\UserVerification;
368369
369370
370- class RegisterController extends Controller
371+ class AuthController extends Controller
371372 {
373+
372374 /*
373375 |--------------------------------------------------------------------------
374- | Register Controller
376+ | Registration & Login Controller
375377 |--------------------------------------------------------------------------
376378 |
377- | This controller handles the registration of new users as well as their
378- | validation and creation . By default this controller uses a trait to
379- | provide this functionality without requiring any additional code.
379+ | This controller handles the registration of new users, as well as the
380+ | authentication of existing users . By default, this controller uses
381+ | a simple trait to add these behaviors. Why don't you explore it?
380382 |
381383 */
382384
383- use RegistersUsers ;
385+ use AuthenticatesAndRegistersUsers, ThrottlesLogins ;
384386
385387 use VerifiesUsers;
386388
387- /**
388- * Create a new controller instance.
389+ /**
390+ * Create a new authentication controller instance.
389391 *
390392 * @return void
391393 */
392394 public function __construct()
393395 {
394- // Based on the workflow you need, you may update and customize the following lines.
396+ // Based on the workflow you want you may update and customize the following lines.
395397
396- $this->middleware('guest', ['except' => ['getVerification', 'getVerificationError']]);
397- }
398+ // Laravel 5.0.*|5.1.*
399+ $this->middleware('guest', ['except' => ['getLogout', 'getVerification', 'getVerificationError']]);
398400
399- /**
400- * Get a validator for an incoming registration request.
401- *
402- * @param array $data
403- * @return \Illuminate\Contracts\Validation\Validator
404- */
405- protected function validator(array $data)
406- {
407- return Validator::make($data, [
408- 'name' => 'required|max:255',
409- 'email' => 'required|email|max:255|unique:users',
410- 'password' => 'required|min:6|confirmed',
411- ]);
401+ // Laravel 5.2.*
402+ $this->middleware('guest', ['except' => ['logout', 'getVerification, 'getVerificationError]]);
403+ //or
404+ $this->middleware($this->guestMiddleware(), ['except' => ['logout', 'getVerification', 'getVerificationError]]);
412405 }
413406
407+ // Laravel 5.0.*|5.1.*
414408 /**
415- * Create a new user instance after a valid registration .
409+ * Handle a registration request for the application .
416410 *
417- * @param array $data
418- * @return User
411+ * @param \Illuminate\Http\Request $request
412+ * @return \Illuminate\Http\Response
419413 */
420- protected function create(array $data )
414+ public function postRegister(Request $request )
421415 {
422- return User::create([
423- 'name' => $data['name'],
424- 'email' => $data['email'],
425- 'password' => bcrypt($data['password']),
426- ]);
416+ $validator = $this->validator($request->all());
417+
418+ if ($validator->fails()) {
419+ $this->throwValidationException(
420+ $request, $validator
421+ );
422+ }
423+
424+ $user = $this->create($request->all());
425+
426+ // Authenticating the user is not mandatory at all.
427+ Auth::login($user);
428+
429+ UserVerification::generate($user);
430+
431+ UserVerification::send($user, 'My Custom E-mail Subject');
432+
433+ return redirect($this->redirectPath());
427434 }
428435
436+ // Laravel 5.2.*
429437 /**
430438 * Handle a registration request for the application.
431439 *
@@ -434,12 +442,26 @@ Edit the `app\Http\Controllers\Auth\RegisterController.php` file.
434442 */
435443 public function register(Request $request)
436444 {
437- $this->validator($request->all())->validate();
445+ $validator = $this->validator($request->all());
446+
447+ if ($validator->fails()) {
448+ $this->throwValidationException(
449+ $request, $validator
450+ );
451+ }
438452
439453 $user = $this->create($request->all());
440- $this->guard()->login($user);
454+
455+ // Authenticating the user is not mandatory at all.
456+
457+ // Laravel <= 5.2.7
458+ // Auth::login($user);
459+
460+ // Laravel > 5.2.7
461+ Auth::guard($this->getGuard())->login($user);
441462
442463 UserVerification::generate($user);
464+
443465 UserVerification::send($user, 'My Custom E-mail Subject');
444466
445467 return redirect($this->redirectPath());
@@ -457,7 +479,7 @@ update the middleware exception to allow `getVerification` and
457479` getVerificationError ` routes to be accessed.
458480
459481```
460- $this->middleware('guest' , ['except' => ['getVerification', 'getVerificationError']]);
482+ $this->middleware($this->guestMiddleware() , ['except' => ['logout', 'getVerification', 'getVerificationError']]);
461483```
462484
463485## Contribute
0 commit comments