M
M
Maxim Lagoysky2017-05-24 15:29:47
Yii
Maxim Lagoysky, 2017-05-24 15:29:47

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);
        }
}

How would I think, can I somehow force them to log in through their unique id that comes with the facbook? If so, how?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question