Two login forms in laravel 5

百般思念 提交于 2020-05-27 07:42:07

问题


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...


回答1:


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', ] ],


来源:https://stackoverflow.com/questions/31933251/two-login-forms-in-laravel-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!