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条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭