Answer the question
In order to leave comments, you need to log in
Yii2 registration problem with facebook?
Help me to make a normal registration / authorization through facebook. Everything seemed to work out for me, but then I found out that there is a user on facebook without email and when clicking on the facebook icon, it does not register them, because the email field is empty.
public function successCallback($client)
{
$attributes = $client->getUserAttributes();
$user = User::find()->where(['id_facebook'=>$attributes['id']])->one();
if(!empty($user)){
Yii::$app->user->login($user);
}else{
$user = new User();
$user->username = $attributes['name'];
$user->email = $attribute['email'];
$user->id_facebook = $attributes['id'];
$user->status = '10';
$user->generateAuthKey();
$user->save();
// Save session attribute user from FB
$session = Yii::$app->session;
$session['attributes']=$attributes;
Yii::$app->user->login($user);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question