dongwu1410 2016-11-05 05:40
浏览 29
已采纳

Laravel子域重定向登录

I am fairly new to stack overflow so please stick with me here.

I am creating a laravel project that has the following links...

main.dev (This is for login, registration, and help sections for the user)

athlete.main.dev (This is for athletes to be redirected to upon main.dev login)

coach.main.dev (This is for coaches to be redirect to upon main.dev login)

Here is an idea of what the code looks like to redirect the user switch (User::getGroup()) { case 'Athlete': return Redirect::to('http://athlete.main.dev'); case 'Coach': return Redirect::to('http://coach.main.dev'); }

This works fine and the user is redirected according to their account type, but upon arriving at this subdomain the user is currently forced to log in again.

I have been searching now for about three days trying to find the answer to no avail.

Is it possible to automatically login the user upon arriving at these redirects based off of main.dev's login information? Or how can I share the session data across subdomains?

Thanks for your help, -Nick

  • 写回答

2条回答 默认 最新

  • douzuqin3467 2016-11-05 11:23
    关注

    One way to solve you problem is by sending the username and password to the url you want to redirect and make an Auth::attemp() in the subdomain to.

    switch (User::getGroup()) {
                case 'Athlete':
                    return Redirect::to('http://athlete.main.dev')->with([
                    'username' => $username,
                    'password' => $password
                    ]);
                case 'Coach':
                    return Redirect::to('http://coach.main.dev')->with([
                    'username' => $username,
                    'password' => $password
                    ]);;
           }
    

    In your controller that handles coach.main.dev and athlete.main.dev add this before you make anything else

    if(isset($username) && isset($password)){
        Auth::attempt(['username' => $username, 'password' => $password]);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能