Skip to content

Commit 89f9072

Browse files
committed
Documentation
1 parent 9dca154 commit 89f9072

File tree

1 file changed

+91
-34
lines changed

1 file changed

+91
-34
lines changed

README.md

Lines changed: 91 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
**jrean/laravel-user-verification** is a PHP package built for Laravel 5.* to
2-
easily handle a user verification flow and validate its e-mail.
2+
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

66
## About
77

8-
- Generate and store a verification token for a registered user.
9-
- Send an e-mail with the verification token link.
10-
- Handle the verification of the token.
11-
- Set the user as verified.
8+
- [x] Generate and store a verification token for a registered user
9+
- [x] Send an e-mail with the verification token link
10+
- [x] Handle the verification of the token
11+
- [x] Set the user as verified
1212

1313
## Installation
1414

@@ -47,14 +47,15 @@ Open up `config/app.php` and add the following to the `aliases` key:
4747

4848
## Configuration
4949

50-
Prior to use this package the table representing the user must be updated with
51-
two new columns, "verified" and "verification_token". It is mandatory to add
52-
the two columns on the same table and where the user's e-mail is
53-
stored.
50+
Prior to use this package the table representing the `User` must be updated with
51+
two new columns, `verified` and `verification_token`.
5452

55-
Last but not least, the model must implement the authenticatable
53+
**It is mandatory to add the two columns on the same table and where the user's
54+
e-mail is stored.**
55+
56+
The model representing the `User` must implement the authenticatable
5657
interface `Illuminate\Contracts\Auth\Authenticatable` which is the default with
57-
the Eloquent User model.
58+
the Eloquent `User` model.
5859

5960
### Migration
6061

@@ -64,15 +65,15 @@ Generate the migration file with the following artisan command:
6465
php artisan make:migration add_verification_to_:table_table --table=":table"
6566
```
6667

67-
Where `:table` is replaced by the table of your choice.
68+
Where `:table` is replaced by the table name of your choice.
6869

6970
For instance if you want to keep the default Eloquent User table:
7071

7172
```
7273
php artisan make:migration add_verification_to_users_table --table="users"
7374
```
7475

75-
Once the migration is generated, edit the file in `database/migration` with the following:
76+
Once the migration is generated, edit the generated migration file in `database/migration` with the following:
7677

7778
```
7879
/**
@@ -113,19 +114,22 @@ php artisan migrate
113114

114115
### Exception
115116

116-
If the table representing the user is not updated and then a user instance is
117-
given to the package a `ModelNotCompliantException` will be thrown.
117+
If the table representing the user is not updated and a user instance is given
118+
to the package without implement the authenticatable interface
119+
`Illuminate\Contracts\Auth\Authenticatable` a `ModelNotCompliantException` will
120+
be thrown.
121+
118122

119123
## E-mail
120124

121125
This package offers to send an e-mail with a link containing the verification token.
122126

123-
Please refer to the Laravel documentation for the proper e-mail component configuration.
127+
Please refer to the Laravel [documentation](https://laravel.com/docs/) for the proper e-mail component configuration.
124128

125129
### E-mail View
126130

127-
The user will receive an e-mail with a link leading to the 'getVerificationi()'
128-
method (endpoint). You will need to create a view for this e-mail at
131+
The user will receive an e-mail with a link leading to the `getVerification()`
132+
method (endpoint). Create a view for this e-mail at
129133
`resources/views/emails/user-verification.blade.php`. The view will receive the
130134
`$user` variable which contains the user details such as the verification
131135
token. Here is a sample e-mail view content to get you started with:
@@ -136,25 +140,33 @@ Click here to verify your account: <a href="{{ $link = url('verification', $user
136140

137141
## Errors
138142

139-
This package throws several exceptions.
143+
This package throws several exceptions. You are free to use `try/catch`
144+
statements or to rely on Laravel built-in exceptions handling.
140145

141146
* `ModelNotCompliantException`
142-
The model instance provided is not compliant with this package.
147+
148+
The model instance provided is not compliant with this package. It must
149+
implement the authenticatable interface
150+
`Illuminate\Contracts\Auth\Authenticatable`
143151

144152
* `TokenMismatchException`
153+
145154
Wrong verification token.
146155

147156
* `UserIsVerifiedException`
148-
This user is already verified.
157+
158+
The given user is already verified.
149159

150160
* `UserNotFoundException`
161+
151162
No user found for the given e-mail adresse.
152163

153164
### Error View
154165

155-
Create a view for the default verification error route at
156-
`resources/views/errors/user-verification.blade.php`. Customize this view to your
157-
needs.
166+
Create a view for the default verification error route `/verification/error` at
167+
`resources/views/errors/user-verification.blade.php`. If an error occurs, the
168+
user will be redirected to this route and this view will be rendered. Customize
169+
this view to your needs.
158170

159171
## Usage
160172

@@ -186,6 +198,8 @@ The package also offers two (2) traits for a quick implementation.
186198

187199
`Jrean\UserVerification\Traits\VerifiesUsers`
188200

201+
which includes:
202+
189203
`Jrean\UserVerification\Traits\RedirectsUsers`
190204

191205
#### Endpoints
@@ -231,12 +245,18 @@ Name of the view returned by the getVerificationError method.
231245

232246
Name of the default table used for managing users.
233247

248+
#### Custom methods
249+
250+
You can easily customize the package behaviour by overriding/overwriting the
251+
public methods. Dig into the source.
252+
234253
## Guidelines
235254

236255
This package whishes to let you be creative while offering you a predefined
237256
path. The following guidelines assume you have configured Laravel for the
238257
package as well as created and migrated the migration according to this
239258
documentation.
259+
240260
This package doesn't require the user to be authenticated to perform the
241261
verification. You are free to implement any flow you may want to achieve.
242262
Note that by default the behaviour of Laravel is to return an authenticated
@@ -246,16 +266,19 @@ user straight after the registration step.
246266

247267
The following code sample aims to showcase a quick and basic implementation.
248268

249-
Edit the `app\Http\Controller\Auth\AuthController.php` file.
269+
Edit the `app\Http\Controller\Auth\AuthController.php` file. It is highly
270+
recommended to read the content of the authentication properpties /
271+
methods provided by Laravel before implementing the package.
250272

251-
- Import the `VerifiesUsers` trait (mandatory)
252-
- Overwrite and customize the redirect path attributes/properties (not
273+
- [x] Import the `VerifiesUsers` trait (mandatory)
274+
- [] Overwrite and customize the redirect path attributes/properties (not
253275
mandatory)
254-
- Overwrite and customize the view name for the `getVerificationError` method
276+
- [] Overwrite and customize the view name for the `getVerificationError()` method
255277
(not mandatory)
256-
- Create the verification error view according to the defined path (mandatory)
257-
- Overwrite the contructor (not mandatory)
258-
- Overwrite the `postRegister()`/`register()` method (mandatory)
278+
- [x] Create the verification error view according to the defined path (mandatory)
279+
- [] Overwrite the contructor (not mandatory)
280+
- [x] Overwrite the `postRegister()`/`register()` method depending on the
281+
Laravel version you use (mandatory)
259282

260283
```
261284
...
@@ -287,6 +310,8 @@ Edit the `app\Http\Controller\Auth\AuthController.php` file.
287310
288311
...
289312
313+
// Laravel 5.0.*|5.1.*
314+
290315
/**
291316
* Handle a registration request for the application.
292317
*
@@ -314,6 +339,40 @@ Edit the `app\Http\Controller\Auth\AuthController.php` file.
314339
315340
return redirect($this->redirectPath());
316341
}
342+
343+
// Laravel 5.2.*
344+
/**
345+
* Handle a registration request for the application.
346+
*
347+
* @param \Illuminate\Http\Request $request
348+
* @return \Illuminate\Http\Response
349+
*/
350+
public function register(Request $request)
351+
{
352+
$validator = $this->validator($request->all());
353+
354+
if ($validator->fails()) {
355+
$this->throwValidationException(
356+
$request, $validator
357+
);
358+
}
359+
360+
$user = $this->create($request->all());
361+
362+
// Authenticating the user is not mandatory at all.
363+
364+
// Laravel <= 5.2.7
365+
// Auth::login($user);
366+
367+
// Laravel > 5.2.7
368+
Auth::guard($this->getGuard())->login($user);
369+
370+
UserVerification::generate($user);
371+
372+
UserVerification::send($user, 'My Custom E-mail Subject');
373+
374+
return redirect($this->redirectPath());
375+
}
317376
```
318377

319378
Edit the `app\Http\routes.php` file.
@@ -329,9 +388,7 @@ change the pre-defined routes.
329388

330389
## Contribute
331390

332-
This package is (yet) under development and refactoring but is ready for
333-
production. Please, feel free to comment, contribute and help. I will be happy
334-
to get some help to deliver tests.
391+
Feel free to comment, contribute and help. 1 PR = 1 feature.
335392

336393
## License
337394

0 commit comments

Comments
 (0)