dev-master
9999999-devLaravel 5 Auth Generator
MIT
The Requires
- php >=5.6.4
- laravel/framework >=5.3
Wallogit.com
2017 © Pedro Peláez
Laravel 5 Auth Generator
composer require d4nd3v/auth:dev-master
Add the provider in app/Providers/AppServiceProvider.php, (*1)
public function register()
{
...
if ($this->app->environment() !== 'production') {
$this->app->register('D4nd3v\Auth\AuthServiceProvider');
}
}
php artisan generate:auth, (*2)
php artisan migrate --path=/database/migrations/auth/
This will create users, password_resets and activations tables., (*3)
https://github.com/tymondesigns/jwt-auth/wiki/Installation
In header must be set: Accept: application/json, (*4)
Go to config/auth.php and change App\User:class to App\Models\User::class., (*5)
For 'middleware' => 'guest', in \app\Http\Middleware\RedirectIfAuthenticated.php set return redirect(route('home'));, (*6)
Web routes, (*7)
Route::group(['middleware' => 'guest'], function () {
Route::get('register', 'AuthController@showRegisterForm')->name('registerForm');
Route::post('register', 'AuthController@register')->name('register');
Route::get('login', 'AuthController@showLoginForm')->name('loginForm');
Route::post('login', 'AuthController@authenticate')->name('login');
});
Route::get('account/activate/', 'AuthController@showActivateMessage')->name('activate');
Route::get('account/activate/{token}', 'AuthController@activate');
Route::get('account/reactivate/', 'AuthController@showResendActivationCode')->name('reactivateForm');
Route::post('account/reactivate/', 'AuthController@resendActivationCode')->name('reactivate');
Route::get('logout', 'AuthController@logout')->name('logout');
Route::get('password/reset', 'AuthController@showLinkRequestForm');
Route::post('password/email', 'AuthController@sendEmailWithResetPasswordLink');
Route::get('password/reset/{token}', 'AuthController@showResetForm')->name('password.reset');
Route::post('password/reset', 'AuthController@resetPassword');
Route::group(['middleware' => 'auth'], function () {
Route::get('password/change', 'AuthController@showChangePasswordForm')->name('showChangePasswordForm');
Route::post('password/change', 'AuthController@changePassword')->name('changePassword');
});
API route, (*8)
Route::post('login', 'AuthController@authenticate');
Route::get('logout', 'AuthController@logout');
Route::post('register', 'AuthController@register');
Route::post('password/forgot', 'AuthController@sendEmailWithResetPasswordLink');
Route::post('password/reset', 'AuthController@resetPassword');
Route::post('activate/send', 'AuthController@resendActivationCode');
Route::group(['middleware' => 'auth.jwt'], function () {
Route::post('password/change', 'AuthController@changePassword');
});
In \app\Exceptions\Handler.php, (*9)
.....
public function render($request, Exception $exception)
{
if ($exception instanceof APIException) {
return $exception->apiExceptionResponse;
}
.....
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
throw new ApiException("unauthenticated");
}
.....
> Register (/register) > ActivateAccount Notification (Send Mail) > Activate (From Mail) (GET /account/activate/token) > Forgot password? (GET /password/reset) > PasswordReset Notification (Send Mail) > Change password form (From Mail) (GET /password/reset/token) > Action change password (/password/reset) > Login Form (GET /login) > Login (POST /login) > Form Resend activation code (GET /account/reactivate/) > Action Resend activation code (POST /account/reactivate/) > Change Password (GET /password/change) > Set New Password (POST /password/change) > Logout (GET /logout)
Test users:
<a href="javascript:;" onclick="$('#email').val('test@test.test'); $('#password').val('xxx');">test@test.test</a>
Laravel 5 Auth Generator
MIT