protected function registerAndLoginUser($client, $userAuth)
{
/** @var \amnah\yii2\user\models\User $user */
/** @var \amnah\yii2\user\models\Profile $profile */
/** @var \amnah\yii2\user\models\Role $role */
$role = $this->module->model("Role");
// set user and profile info
$attributes = $client->getUserAttributes();
$function = "setInfo" . ucfirst($client->name);
// "setInfoFacebook()"
list($user, $profile) = $this->{$function}($attributes);
// calculate and double check username (in case it is already taken)
$fallbackUsername = "{$client->name}_{$userAuth->provider_id}";
$user = $this->doubleCheckUsername($user, $fallbackUsername);
// save new models
$user->setScenario("social");
$user->setRegisterAttributes($role::ROLE_USER, $user::STATUS_ACTIVE)->save();
$profile->setUser($user->id)->save();
$userAuth->setUser($user->id)->save();
// log user in
Yii::$app->user->login($user, $this->module->loginDuration);
}