amnah\yii2\user\controllers\AuthController::setInfoVkontakte PHP Method

setInfoVkontakte() protected method

Set info for vkontakte registration
Author: Ilya Sheershoff ([email protected])
protected setInfoVkontakte ( array $attributes ) : array
$attributes array
return array [$user, $profile]
    protected function setInfoVkontakte($attributes)
    {
        /** @var \amnah\yii2\user\models\User $user */
        /** @var \amnah\yii2\user\models\Profile $profile */
        $user = $this->module->model("User");
        $profile = $this->module->model("Profile");
        foreach ($_SESSION as $k => $v) {
            if (is_object($v) && get_class($v) == "yii\\authclient\\OAuthToken") {
                /** @var \yii\authclient\OAuthToken $v */
                $user->email = $v->getParam('email');
            }
        }
        // set email/username if they are set
        // note: email may be missing if user signed up using a phone number
        if (!empty($attributes["email"])) {
            $user->email = $attributes["email"];
        }
        if (!empty($attributes["username"])) {
            $user->username = $attributes["username"];
        } else {
            $user->username = "vkontakte_{$attributes["id"]}";
        }
        $profile->full_name = "{$attributes["first_name"]} {$attributes["last_name"]}";
        return [$user, $profile];
    }