我的问题是 - 存储在远程(其他)服务器上的注册用户数据(用户名,电子邮件,密码)。当用户尝试使用电子邮件和密码登录时,请求转到该远程服务器,并从那里检索数据(使用API)。问题是 - 当我检索数据时,如果用户存在,我应该登录他/她(我不检查数据库中的任何内容)。这是laravel登录方法
public function login(Request $request)
{
$this->validateLogin($request);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
if ($this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
$credentials = $this->credentials($request);
if ($this->guard()->attempt($credentials, $request->has('remember'))) {
return $this->sendLoginResponse($request);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}
我已经编写了需要检索数据的方法,但是在获得数据后我该如何登录?我应该覆盖登录方法还是有更好的方法?
答案 0 :(得分:1)
以下是如何在5.2上手动登录用户:
if (/* your condition */) {
$user = User::where('email', $credentials['email'])->first();
Auth::login($user);
return $this->sendLoginResponse($request);
}
这是5.3:
alias glg='log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short'
alias gll='log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat'
alias gld='log --pretty=format:"%C(yellow)%h\\ %C(green)%ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short --graph'
alias gls='log --pretty=format:"%C(green)%h\\ %C(yellow)[%ad]%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=relative'
alias gb="!git for-each-ref --sort='-authordate' --format='%(authordate)%09%(objectname:short)%09%(refname)' refs/heads | sed -e 's-refs/heads/--'"