简体   繁体   English

laravel 5中的两种登录表单

[英]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. 我一直想知道如何在laravel 5中制作两个登录表单一段时间...原因是因为我有一个多站点项目,我有一个管理站点,以及一个项目中的公共站点。

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): 我还在这样的每组路由中创建了用于身份验证的自定义路由(这些是针对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: 我还在每个父文件夹中用它的控制器(' AuthController ',' PasswordController ')创建了Auth文件夹,我的控制器是这样的:

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

And so for the views i've got separate Auth views like this: 所以对于视图我有这样的单独的Auth视图:

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. 在我的模型中,users表有一个类型列,可以从Public或Admin站点过滤用户。 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... 什么到目前为止,我已经试过是覆盖AuthenticatesAndRegistersUsers功能,如getLogingetRegister也是变量,如$loginPath$redirectTo但调用时publicPostLogin公共的登录表单有作为动作(结帐路由) {{ route('publicPostLogin') }}它只是不起作用......

Do you hear about Multiauth in laravel . 你听说过laravel中的Multiauth吗 in this library there are two or more type user can login in one laravel application. 在这个库中有两个或更多类型的用户可以在一个laravel应用程序中登录。 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. 在我们的例子中有两种类型的用户管理员公共 ,这意味着用户权利。你通过插入usertype识别用户完全错误亲爱的。

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. 你必须使用这个库。只需按照链接步骤安装库。并在restaurant.com分配两个不同的表,例如用户类型是Public,表示有使用User表的简单用户。

On another hand for admin in our case there is restaurant.net .This login form use admin table to login. 在另一方面,对于管理员来说,在我们的案例中有restaurant.net 。这个登录表单使用管理表登录。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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