一个登录页面可供多个客户使用

时间:2019-03-11 15:01:58

标签: php mysql laravel

我构建了一个laravel系统,试图弄清楚多个客户端如何使用单个URL(例如www.example.com/login

)登录。

此刻每个用户都必须具有如下所示的唯一网址:

www.example.com/biz1/admin/login
www.example.com/biz2/admin/login

据我所知,代码是从URL获取biz名称并将其添加到表单中的,请参见以下表单:

 <form action="{{ route('business.admin.authenticate', ['bzname' => $bzname]) }}" method="post" >
                {{ csrf_field() }}
                <div class="form-group">
                    <label style="color: #fff" class="label">Email</label>
                    <div class="input-group">
                        <input style="color: #fff" type="text" class="form-control" placeholder="Email" name="email">
                        <div class="input-group-append">
                          <span class="input-group-text">
                            <i class="mdi mdi-check-circle-outline"></i>
                          </span>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label style="color: #fff" class="label">Password</label>
                    <div class="input-group">
                        <input style="color: #fff" type="password" class="form-control" placeholder="*********" name="password">
                        <div class="input-group-append">
                            <span class="input-group-text">
                                <i class="mdi mdi-check-circle-outline"></i>
                            </span>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <button type="submit" class="btn btn-primary submit-btn btn-block">Login</button>
                </div>

            </form>

此表单然后粘贴到下面的控制器中的功能:

  public function authenticate(Request $request, $bzname)
{
    $business = Business::where('business_name', $bzname)->first();
    $business_admin = BusinessAdmin::where('business_id', $business->id)->first();
    if(isset($business_admin))
    {
        $user = User::findOrFail($business_admin->user_id);

        if($user->email === $request->input('email'))
        {
            if (Auth::guard('business')->attempt(['email'=>$request->input('email'), 'password'=>$request->input('password')]))
            {
                $permissions = [];
                session(['permissions' => $permissions]);
                return redirect()->route('business.admin.dashboard', ['bzname' => $bzname]);

            }
            else
            {
                return redirect()->route('business.admin.login', ['bzname' => $bzname])->with('errorLogin', 'Ooops! Invalid Email or Password')->withInput();
            }
        }
        else
        {
            return redirect()->route('business.admin.login', ['bzname' => $bzname])->with('errorLogin', 'Ooops! Pls Enter Correct Business')->withInput();
        }
    }
}

我正在以某种方式在$ business参数中思考,我需要从链接到客户端的电子邮件中获取bzname,而不是从URL中获取它。

目前我的知识非常基础,任何建议都值得赞赏。

谢谢

0 个答案:

没有答案