[英]Register & Authentication Laravel 5.2
Good afternoon ! 下午好 !
I am creating and authenticating with Laravel 5.2 and I have the following problem , I am using Socialite with google for this case , the user could be register correctly but in the authenticacion with this code fails. 我正在使用Laravel 5.2创建和身份验证,并且遇到以下问题,在这种情况下,我正在与google一起使用Socialite,用户可以正确注册,但是使用此代码的身份验证失败。
Could anyone help to me ? 有人可以帮我吗?
public function handleProviderCallback(){
$user = Socialite::driver('google')->user();
$usuario = new User();
$usuario->name=$user->name;
$usuario->email=$user->email;
$usuario->password=\Hash::make("1234");
$usuario->photo=$user->avatar;
$usuario->role_id=1;
$usuario->isLocked=0;
$usuario->save();
$findUser= User::where('email','=',$usuario->email)->get();
if (!$buscarUsuario->isEmpty()) {
if (\Auth::attempt(['email' => $findUser[0]->email, 'password' => $findUser[0]->password]))
{
return redirect()->intended('profile');
}else{
echo "NO";
//return \Redirect::back();
}
}else{
echo "NOTHING";
}
}
The result doing echo in $buscarUsuario 在$ buscarUsuario中执行回显的结果
[{"id":81,"name":"Kiko","first_surname":"","last_surname":"","descripcion":"","email":"correo@gmail.com","created_at":"2016-06-04 14:15:07","updated_at":"2016-06-04 14:15:07"}
Use 采用
Auth::loginUsingId($findUser['id']);
https://laravel.com/docs/5.1/authentication#other-authentication-methods https://laravel.com/docs/5.1/authentication#other-authentication-methods
method for login form ID 登录表单ID的方法
The issue is that when you call Auth::attempt()
, it is expecting the plaintext password, but you are passing the hashed password. 问题在于,当您调用
Auth::attempt()
,它期望使用纯文本密码,但是您正在传递哈希密码。 This is why it fails. 这就是为什么它失败。
Since you have selected the User object and have the ID, you can call \\Auth::loginUsingId()
like below. 由于选择了User对象并具有ID,因此可以像下面一样调用
\\Auth::loginUsingId()
。
Also, you are calling isEmpty()
on $buscarUsuario
, which doesn't appear to exist. 另外,您正在
$buscarUsuario
上调用isEmpty()
,该函数似乎不存在。 That should be $findUser
. 那应该是
$findUser
。
if(!$findUser->isEmpty()){
if (\Auth::loginUsingId($findUser[0]->id))
{
return redirect()->intended('profile');
}else{
echo "NO";
//return \Redirect::back();
}
} else {
echo "NO";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.