Skip to content

Commit

Permalink
Documentation + refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jrean committed Mar 25, 2016
1 parent 76effb9 commit e81ee20
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ easily handle a user verification flow and validate its email.

- Generate and store a verification token for a registered user.
- Send an email with the verification token link.
- Handle the verification.
- Handle the verification of the token.
- Set the user as verified.

## Installation
Expand All @@ -15,7 +15,7 @@ To get the latest version of Laravel User Verification, simply add the following
the require block of your composer.json file:

"jrean/laravel-user-verification": "dev-master"
"jrean/laravel-user-verification": "2.0"
"jrean/laravel-user-verification": "2.*"

or

Expand Down Expand Up @@ -94,7 +94,7 @@ Once the migration is generated, edit the file in `database/migration` with the
```

Where `:table` is replaced by the table of your choice.
Where `:table` is replaced by the table name of your choice.

Migrate the migration with the following command:

Expand All @@ -108,17 +108,13 @@ This package offers to send an email with a link containing the verification tok

Please refer to the Laravel documentation for the proper email component configuration.

[Laravel Email](http://laravel.com/docs/5.1/mail)

#### View

When a user submits a request to register or when you decide, they will receive
an e-mail with a link that points to the getVerification method (typically
routed at /auth/verification/{token}) of the AuthController. You will need to
create a view for this e-mail at
The user will receive an e-mail with a link leading to the getVerification
method (endpoint). You will need to create a view for this e-mail at
resources/views/emails/user-verification.blade.php. The view will receive the
`$user` variable which contains the user information such as the verification
token. Here is an example e-mail view to get you started:
`$user` variable which contains the user details such as the verification
token. Here is an sample e-mail view to get you started:

```
Click here to verify your account {{ url('auth/verification/' . $user->verification_token) }}
Expand All @@ -132,7 +128,7 @@ The package public API offers four (4) methods.

* `generate(AuthenticatableContract $user)`

Generate and save a verification token the given user.
Generate and save a verification token for the given user.

* `send(AuthenticatableContract $user, $subject = null)`

Expand All @@ -155,7 +151,7 @@ over the four (4) previous listed public methods.

The package also offers a trait for a quick implementation.

#### Actions
#### Endpoints

The two following methods are endpoints you can join by defining the proper
route(s) of your choice.
Expand Down Expand Up @@ -201,15 +197,15 @@ Name of the default table used for managing users.
## Example

This package whishes to let you be creative while offering you a predefined
path. The following examples assume you have configured Laravel for the
path. The following sample assume you have configured Laravel for the
package as well as created and migrated the migration according to this
documentation.
This package doesn't require the user to be authenticated to perform the
verification. You are free to implement any flow you may want to achieve.
Note that by default the behaviour of Laravel is to return an authenticated
user straight after the registration.

### Example 1
### Example

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

Expand Down Expand Up @@ -243,6 +239,8 @@ Edit the `app\Http\Controller\Auth\AuthController.php` file.
*/
public function __construct()
{
// Based on the workflow you want you may update the following lines.
// Laravel 5.0.*|5.1.*
$this->middleware('guest', ['except' => ['getLogout']]);
Expand Down Expand Up @@ -288,6 +286,11 @@ Edit the `app\Http\routes.php` file.
```
Route::get('auth/verification/error', 'Auth\AuthController@getVerificationError');
Route::get('auth/verification/{token}', 'Auth\AuthController@getVerification');
or
Route::get('verification/error', 'Auth\AuthController@getVerificationError');
Route::get('verification/{token}', 'Auth\AuthController@getVerification');
```

## Contribute
Expand Down
17 changes: 9 additions & 8 deletions src/UserVerification.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(MailerContract $mailer, Builder $schema)
}

/**
* Generate and save a verification token.
* Generate and save a verification token for the given user.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return bool
Expand All @@ -69,7 +69,7 @@ public function send(AuthenticatableContract $user, $subject = null)
}

/**
* Process the token verification.
* Process the token verification for the given token.
*
* @param stdClass $user
* @param string $token
Expand All @@ -81,9 +81,10 @@ public function process($user, $token)
return false;
}

$this->wasVerified($user);
// test
dd($this->wasVerified($user));

return true;
/* return true; */
}

/**
Expand All @@ -98,7 +99,7 @@ public function isVerified($user)
}

/**
* Update and save the user has verified.
* Update and save the user as verified.
*
* @param stdClass $user
* @return void
Expand Down Expand Up @@ -173,7 +174,7 @@ protected function generateToken($email)
* @param string $token
* @return string
*/
public function decryptEmailFromToken($token)
protected function decryptEmailFromToken($token)
{
return Crypt::decrypt($token);
}
Expand Down Expand Up @@ -238,7 +239,7 @@ protected function hasColumn(AuthenticatableContract $user, $column)
* @param string $table
* @return stdClass
*/
public function getUser($token, $table)
protected function getUser($token, $table)
{
return $this->getUserByEmail($this->getEmail($token), $table);
}
Expand All @@ -254,7 +255,7 @@ public function getUser($token, $table)
*/
protected function getUserByEmail($email, $table)
{
$user = DB::table($table)->where('email', $email)->first();
$user = DB::table($table)->where('email', $email)->first(['id', 'email', 'verified', 'verification_token']);

if ($user === null) {
throw new UserNotFoundException();
Expand Down

0 comments on commit e81ee20

Please sign in to comment.