How to create 2-step-login on laravel5.2

I was asked about how to make of 2-step-login at the comment column of the article of the “multi-Authentication” that I posted.
Then I try it.

Outline I create this time is below

not login → login as user → login as Admin
According to login stage, you can see more pages.

■github – my-blog-161117__2step-login
https://github.com/dog-ears/my-blog-161117__2step-login

(i) create multi-Authentication with my article

■How to make the multi-Authentication in laravel 5.2
http://dog-ears.net/laravel/160523/

(ii) edit route

#/app/Http/routes.php
https://github.com/dog-ears/my-blog-161117__2step-login/blob/master/app/Http/routes.php

Route::group(['middleware' => 'auth'], function () {
...
});

Grouping all admin route with middleware ‘auth’.
And when you see admin page without login as user,
you need user login at first.

(iii) when you logout as user, automatically you logout as admin.

■github – logout as admin when logout as user
https://github.com/dog-ears/my-blog-161117__2step-login/commit/95f97aa9b08ce2ee5b186c12bc4a4e9d445c3942

#app/Http/routes.php

$this->get('logout', 'Auth\AuthController@logoutAll');

when you move to /logout, logoutAll method is executed.
modify route.

#app/Http/Controllers/Auth/AuthController.php

$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
↓
$this->middleware($this->guestMiddleware(), ['except' => 'logoutAll']);

change middleware except from logout to logoutAll.
and add logoutAll method to the controller.

That’s all.
2-step-login is done.

Leave a Reply

Your email address will not be published. Required fields are marked *