@@ -16,8 +16,8 @@ For Laravel 5.0.* | 5.1.* | 5.2.*, use branch
1616## About
1717
1818- [x] Generate and store a verification token for a registered user
19- - [x] Send an e-mail with the verification token link
20- - [x] Handle the verification of the token
19+ - [x] Send or queue an e-mail with the verification token link
20+ - [x] Handle the token verification
2121- [x] Set the user as verified
2222- [x] Relaunch the process anytime
2323
@@ -29,7 +29,7 @@ require block of your composer.json file:
2929
3030 {
3131 "require": {
32- "jrean/laravel-user-verification": "^2 .0"
32+ "jrean/laravel-user-verification": "^3 .0"
3333 }
3434
3535 }
@@ -58,7 +58,7 @@ Open up `config/app.php` and add the following to the `aliases` key:
5858
5959## Configuration
6060
61- 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
6262two new columns, ` verified ` and ` verification_token ` .
6363
6464** It is mandatory to add the two columns on the same table and where the user's
@@ -78,7 +78,7 @@ php artisan make:migration add_verification_to_:table_table --table=":table"
7878
7979Where ` :table ` is replaced by the table name of your choice.
8080
81- 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:
8282
8383```
8484php artisan make:migration add_verification_to_users_table --table="users"
@@ -124,13 +124,6 @@ Migrate the migration with the following command:
124124php artisan migrate
125125```
126126
127- ### Exception
128-
129- If the table representing the user is not updated with the two new columns and
130- the model representing the user doesn't implement the authenticatable interface
131- ` Illuminate\Contracts\Auth\Authenticatable ` , a ` ModelNotCompliantException `
132- will be thrown.
133-
134127## E-mail
135128
136129This package provides a method to send an e-mail with a link containing the verification token.
@@ -172,7 +165,7 @@ Click here to verify your account: <a href="{{ $link = url('verification', $user
172165## Errors
173166
174167This package throws several exceptions. You are free to use ` try/catch `
175- statements or to rely on the Laravel built-in exceptions handling .
168+ statements or to rely on the Laravel built-in exceptions handler .
176169
177170* ` ModelNotCompliantException `
178171
@@ -206,12 +199,12 @@ verify, ...).
206199
207200### Routes
208201
209- 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
210203customizable.
211204
212205```
213- Route::get('verification/error', 'Auth\AuthController @getVerificationError');
214- Route::get('verification/{token}', 'Auth\AuthController @getVerification');
206+ Route::get('verification/error', 'Auth\RegisterController @getVerificationError');
207+ Route::get('verification/{token}', 'Auth\RegisterController @getVerification');
215208```
216209
217210### Trait
@@ -240,7 +233,7 @@ Do something if the verification fails.
240233
241234### API
242235
243- The package public API offers three (3 ) methods.
236+ The package public API offers height (8 ) methods.
244237
245238* ` generate(AuthenticatableContract $user) `
246239
@@ -250,18 +243,42 @@ Generate and save a verification token for the given user.
250243
251244Send by e-mail a link containing the verification token.
252245
246+ * ` sendQueue(AuthenticatableContract $user, $subject = null, $from = null, $name = null) `
247+
248+ Queue and send by e-mail a link containing the verification token.
249+
250+ * ` sendQueueOn($queue, AuthenticatableContract $user, $subject = null, $from = null, $name = null) `
251+
252+ Queue on the given queue and send by e-mail a link containing the verification token.
253+
254+ * ` sendLater($seconds, AuthenticatableContract $user, $subject = null, $from = null, $name = null) `
255+
256+ Send later by e-mail a link containing the verification token.
257+
258+ * ` sendLaterOn($queue, $seconds, AuthenticatableContract $user, $subject = null, $from = null, $name = null) `
259+
260+ Send later on the given queue by e-mail a link containing the verification token.
261+
253262* ` process($email, $token, $userTable) `
254263
255264Process the token verification for the given e-mail and token.
256265
266+ * ` emailView($name) `
267+
268+ Set the e-mail view name.
269+
270+ For the ` sendQueue ` , ` sendQueueOn ` , ` sendLater ` and
271+ ` sendLaterOn ` methods, you must [ configure your queues] ( https://laravel.com/docs/ )
272+ before using this feature.
273+
257274### Facade
258275
259276The package offers a facade ` UserVerification:: ` .
260277
261278### Attributes/Properties
262279
263280To customize the package behaviour and the redirects you can implement and
264- customize six (5 ) attributes/properties:
281+ customize six (6 ) attributes/properties:
265282
266283* ` $redirectIfVerified = '/'; `
267284
@@ -279,6 +296,10 @@ Where to redirect after a failling token verification.
279296
280297Name of the view returned by the getVerificationError method.
281298
299+ * ` $verificationEmailView = 'emails.user-verification'; `
300+
301+ Name of the default e-mail view.
302+
282303* ` $userTable = 'users'; `
283304
284305Name of the default table used for managing users.
@@ -299,7 +320,7 @@ package as well as created and migrated the migration according to this
299320documentation and the previous documented steps.**
300321
301322Note that by default the behaviour of Laravel is to return an authenticated
302- user straight after the registration step.
323+ user after the registration step.
303324
304325### Example
305326
@@ -308,29 +329,29 @@ following Laravel logic. You are free to implement the way you want.
308329It is highly recommended to read and to understand the way Laravel implements
309330registration/authentication.
310331
311- Edit the ` app\Http\ routes.php` file.
332+ Edit the ` routes/web .php ` file.
312333
313334- Define two (2) new routes.
314335
315336```
316- Route::get('verification/error', 'Auth\AuthController @getVerificationError');
317- Route::get('verification/{token}', 'Auth\AuthController @getVerification');
337+ Route::get('verification/error', 'Auth\RegisterController @getVerificationError');
338+ Route::get('verification/{token}', 'Auth\RegisterController @getVerification');
318339```
319340
320341- Define the e-mail view.
321342
322- Edit the ` app\Http\Controllers\Auth\AuthController .php ` file.
343+ Edit the ` app\Http\Controllers\Auth\RegisterController .php ` file.
323344
324345- [x] Import the ` VerifiesUsers ` trait (mandatory)
325346- [ ] Overwrite and customize the redirect attributes/properties paths
326347 available within the ` RedirectsUsers ` trait included by the
327348 ` VerifiesUsers ` trait. (not mandatory)
328- - [ ] Overwrite the error view name used by the ` getVerificationError() ` method
349+ - [ ] Overwrite the default error view name used by the ` getVerificationError() ` method
329350 (not mandatory)
330- - [x] Create the verification error view (mandatory)
351+ - [x] Create the verification error view at
352+ ` resources/views/errors/user-verification.blade.php ` (mandatory)
331353- [ ] Overwrite the contructor (not mandatory)
332- - [x] Overwrite the ` postRegister() ` /` register() ` method depending on the
333- Laravel version you use (mandatory)
354+ - [x] Overwrite the ` register() ` method (mandatory)
334355
335356```
336357
@@ -339,78 +360,72 @@ Edit the `app\Http\Controllers\Auth\AuthController.php` file.
339360 use App\User;
340361 use Validator;
341362 use App\Http\Controllers\Controller;
342- use Illuminate\Foundation\Auth\ThrottlesLogins;
343- use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
363+ use Illuminate\Foundation\Auth\RegistersUsers;
364+ use Illuminate\Http\Request;
365+
344366 use Jrean\UserVerification\Traits\VerifiesUsers;
345367 use Jrean\UserVerification\Facades\UserVerification;
346- use Illuminate\Http\Request;
347- use Illuminate\Support\Facades\Auth;
348368
349- class AuthController extends Controller
369+
370+ class RegisterController extends Controller
350371 {
351372 /*
352373 |--------------------------------------------------------------------------
353- | Registration & Login Controller
374+ | Register Controller
354375 |--------------------------------------------------------------------------
355376 |
356- | This controller handles the registration of new users, as well as the
357- | authentication of existing users . By default, this controller uses
358- | a simple trait to add these behaviors. Why don't you explore it?
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.
359380 |
360381 */
361382
362- use AuthenticatesAndRegistersUsers, ThrottlesLogins ;
383+ use RegistersUsers ;
363384
364385 use VerifiesUsers;
365386
366- /**
367- * Create a new authentication controller instance.
387+ /**
388+ * Create a new controller instance.
368389 *
369390 * @return void
370391 */
371392 public function __construct()
372393 {
373- // Based on the workflow you want you may update and customize the following lines.
394+ // Based on the workflow you need, you may update and customize the following lines.
374395
375- // Laravel 5.0.*|5.1.*
376- $this->middleware('guest', ['except' => ['getLogout', 'getVerification', 'getVerificationError']]);
377-
378- // Laravel 5.2.*
379- $this->middleware('guest', ['except' => ['logout', 'getVerification, 'getVerificationError]]);
380- //or
381- $this->middleware($this->guestMiddleware(), ['except' => ['logout', 'getVerification', 'getVerificationError]]);
396+ $this->middleware('guest', ['except' => ['getVerification', 'getVerificationError']]);
382397 }
383398
384- // Laravel 5.0.*|5.1.*
385399 /**
386- * Handle a registration request for the application .
400+ * Get a validator for an incoming registration request .
387401 *
388- * @param \Illuminate\Http\Request $request
389- * @return \Illuminate\Http\Response
402+ * @param array $data
403+ * @return \Illuminate\Contracts\Validation\Validator
390404 */
391- public function postRegister(Request $request )
405+ protected function validator(array $data )
392406 {
393- $validator = $this->validator($request->all());
394-
395- if ($validator->fails()) {
396- $this->throwValidationException(
397- $request, $validator
398- );
399- }
400-
401- $user = $this->create($request->all());
402-
403- // Authenticating the user is not mandatory at all.
404- Auth::login($user);
405-
406- UserVerification::generate($user);
407-
408- UserVerification::send($user, 'My Custom E-mail Subject');
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+ ]);
412+ }
409413
410- return redirect($this->redirectPath());
414+ /**
415+ * Create a new user instance after a valid registration.
416+ *
417+ * @param array $data
418+ * @return User
419+ */
420+ protected function create(array $data)
421+ {
422+ return User::create([
423+ 'name' => $data['name'],
424+ 'email' => $data['email'],
425+ 'password' => bcrypt($data['password']),
426+ ]);
411427 }
412428
413- // Laravel 5.2.*
414429 /**
415430 * Handle a registration request for the application.
416431 *
@@ -419,26 +434,12 @@ Edit the `app\Http\Controllers\Auth\AuthController.php` file.
419434 */
420435 public function register(Request $request)
421436 {
422- $validator = $this->validator($request->all());
423-
424- if ($validator->fails()) {
425- $this->throwValidationException(
426- $request, $validator
427- );
428- }
437+ $this->validator($request->all())->validate();
429438
430439 $user = $this->create($request->all());
431-
432- // Authenticating the user is not mandatory at all.
433-
434- // Laravel <= 5.2.7
435- // Auth::login($user);
436-
437- // Laravel > 5.2.7
438- Auth::guard($this->getGuard())->login($user);
440+ $this->guard()->login($user);
439441
440442 UserVerification::generate($user);
441-
442443 UserVerification::send($user, 'My Custom E-mail Subject');
443444
444445 return redirect($this->redirectPath());
@@ -456,7 +457,7 @@ update the middleware exception to allow `getVerification` and
456457` getVerificationError ` routes to be accessed.
457458
458459```
459- $this->middleware($this->guestMiddleware() , ['except' => ['logout', 'getVerification', 'getVerificationError']]);
460+ $this->middleware('guest' , ['except' => ['getVerification', 'getVerificationError']]);
460461```
461462
462463## Contribute
0 commit comments