简体   繁体   中英

Two login forms in laravel 5

I've been wondering how could i make two login forms in laravel 5 for a while... The reason of this is because i have a multi-site project, i've got the admin site, and the public site in one project.

I've grouped the routes so the admin routes answer to a domain and public routes answer to another domain like this:

Route::group(array( 'domain' => 'restaurant.com', 'namespace' => 'Public' ), function () {
    //some routes
});

Route::group(array( 'domain' => 'restaurant.net', 'namespace' => 'Admin' ), function () {
    //some routes
});

I've also created custom routes for authentication in each group of routes like this (this ones are for Public):

Route::controllers([
    'auth' => 'Auth\AuthController',
    'password' => 'Auth\PasswordController',
]);

Route::get( '/register' , [
    'as' => 'publicRegister' ,
    'uses' => 'Auth\AuthController@getRegister'
] );

Route::post( '/registrar' , [
    'as' => 'publicPostRegister' ,
    'uses' => 'Auth\AuthController@postRegister'
] );

Route::get( '/login' , [
    'as' => 'publicLogin' ,
    'uses' => 'Auth\AuthController@getLogin'
] );

Route::post( '/login' , [
    'as' => 'publicPostLogin' ,
    'uses' => 'Auth\AuthController@postLogin'
] );

Route::get( '/logout' , [
    'as' => 'publicLogout' ,
    'uses' => 'Auth\AuthController@getLogout'
] );

I've also created the Auth folder with it's controllers (' AuthController ', ' PasswordController ') in each parent folder, my controllers are like this:

app    
|---Http
    |---Controllers
        |----------Public
        |          |---Auth
        |          |    |---AuthController
        |          |    |---PasswordController
        |          |--- ...
        | 
        |----------Admin
                  |---Auth
                  |    |---AuthController
                  |    |---PasswordController
                  |--- ...

And so for the views i've got separate Auth views like this:

resources
    |---views
        |----------Public
        |          |---Auth
        |          |    |---login.blade.php
        |          |    |---password.blade.php
        |          |    |---register.blade.php
        |          |    |---reset.blade.php
        |          |--- ...
        | 
        |----------Admin
                   |---Auth
                   |    |---login.blade.php
                   |    |---password.blade.php
                   |    |---register.blade.php
                   |    |---reset.blade.php
                   |--- ...

In my models the users table has a type column that will filter users from Public or Admin site. The main question here is: How could i make two login forms for my project? What i would like is that Public Users couldn't log into the Admin site and viceversa.

What i've tried so far is override the AuthenticatesAndRegistersUsers functions like getLogin , getRegister and also variables like $loginPath , $redirectTo but when calling publicPostLogin (checkout routes) in the login form of Public that has as action {{ route('publicPostLogin') }} it just don't works...

Do you hear about Multiauth in laravel . in this library there are two or more type user can login in one laravel application. In our case there are two type user Admin and Public that means User right.And you identified user by insert usertype that totally wrong my dear.

You have to use this library.just follow that link step to install library.And assign two different table like in our case in restaurant.com there is user type is Public that means there is simple user that uses User table.

On another hand for admin in our case there is restaurant.net .This login form use admin table to login.

Both forgot password and reset password functionality works separately in one application.

'multi' => [ 'admin' => [ 'driver' => 'database', 'table' => 'admin', 'email' => 'client.emails.password' ], 'users' => [ 'driver' => 'database', 'table' => 'users', 'email' => 'client.emails.password', ] ],

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM