1

我正在切换用户,laravel我也成功了,但问题是当我在成功登录后将用户重定向到仪表板时,它会重定向到登录表单,而不是我不知道我做错了什么。这是我正在使用的代码。

public function user_reauthenticate(Request $request) {
    $input = Input::all();
    $data = User::where('email', $input['email'])->first();
    if ($data) {
        if (Hash::check($input['password'], $data->password)) {
            Session::put('email', $input['email']);
            $newuser = Student::find($input['new_user']);
            session(['orig_user' => $data->id]);
            Auth::login($newuser);
            return Redirect::back();
        } else {
            $response = 'Wrong Credentials';
        }
    } else {
        $response = 'User does not exist';
    }
}

谁能帮我找出问题?

4

2 回答 2

0

已编辑

您可以登录

Auth::loginUsingId(1);

新编辑

// If you have the guard student and multiple auth
$auth = auth()->guard('student');
$objAuth = $auth->loginUsingId($input['new_user']);

//Single Auth

$objAuth = Auth::loginUsingId($input['new_user']);
于 2018-05-31T10:55:17.123 回答
0

Add this to your top of the file:- use Illuminate\Foundation\Auth\AuthenticatesUsers;

Afterwards add a if function like below in your already completed code:-

public function user_reauthenticate(Request $request)
{
     use AuthenticatesUsers;
     $input = Input::all();
     $data = User::where('email', $input['email'])->first();
     if ($data) {
     if (Hash::check($input['password'], $data->password))
     {
        Session::put('email', $input['email']);
        $newuser = Student::find($input['new_user']);
        session(['orig_user' => $data->id]);
        Auth::login($newuser);
        if ($this->attemptLogin($request))
        {
             return $this->sendLoginResponse($request);
        }
     }
     else
     {
          $response = 'Wrong Credentials';
     }
 }
     else
     {
          $response = 'User does not exist';
     }
}

After this method override this method as follows:-

protected function authenticated(Request $request, $user)
{   
    return redirect()->route('dashboard');   
}

Check whether your dashboard route is named dashboard or if not name it.

于 2018-05-31T11:57:57.537 回答