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 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)
  • ¥15 无法使用此凭据登录,因为你的域不可用,如何解决?(标签-Windows)
  • ¥15 yolov9的训练时间
  • ¥15 二叉树遍历没有报错但无法正常运行
  • ¥15 在linux系统下vscode运行robocup3d上场球员报错
  • ¥15 Python语言实验
  • ¥15 SAP HANA SQL 增加合计行
  • ¥20 用C#语言解决一个英文打字练习器,有偿
  • ¥15 srs-sip外部服务 webrtc支持H265格式
  • ¥15 在使用abaqus软件中,继承到assembly里的surfaces怎么使用python批量调动