duanhanzi8328 2014-04-13 11:12
浏览 17
已采纳

Laravel设置为多重登录

in this framework i want to use multi login and i have userAccount model with define table with userAccount names.

in this below Route i want to use userAccount model and table for login

Route::post('accountAuth', array('as'=>'accountAuth', 'before'=>'csrf', function(){
    if ( Auth::attempt( array( 'username'=>Input::get('username'), 'password'=>Input::get('password') ) ) ){
        Return View::make('layouts.account.main');
    }
    else
        return Redirect::route('userLogin')
                ->with('message','ERROR')
                ->withInput();
}));

how to do this action for enable or using multi login?

  • 写回答

1条回答 默认 最新

  • douzhong8856 2014-04-13 22:04
    关注

    You can do multi login pretty easily if you use a controller to help with your task:

    class LogonController extends Controller {
    
        public function adminLogin()
        {
            return $this->login('Admin');
        }
    
        public function accountLogin()
        {
            return $this->login('User');
        }
    
        public function login($model)
        {
            if ($user = $model::where('username', Input::get('username'))->first())
            {
                if (Hash::check($user->password, Input::get('password')))
                {
                    Auth::login($user);
    
                    return Redirect::to('/');
                }
                else
                {
                    return Redirect::back()->withMessage('Wrong password.');
                }
            }
            else
            {
                return Redirect::back()->withMessage('User not found.');
            }
        }
    
    }
    

    Then you just need to create different routes for it:

    Route::post('admin', 'LogonController@adminLogin');
    
    Route::post('login', 'LogonController@accountLogin');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件