本文整理汇总了PHP中yii\authclient\ClientInterface::retrieveAdditionalData方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::retrieveAdditionalData方法的具体用法?PHP ClientInterface::retrieveAdditionalData怎么用?PHP ClientInterface::retrieveAdditionalData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\authclient\ClientInterface
的用法示例。
在下文中一共展示了ClientInterface::retrieveAdditionalData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticate
public function authenticate(ClientInterface $client)
{
// find existing user by service
if ($this->userService !== null) {
/** @var User $user */
$user = Yii::createObject(ModelMapHelper::User());
$user = $user->loadModel($this->userService->user_id);
$user->login(UsersModule::module()->loginDuration);
} else {
// no user for this pair
// this is the most hard part
// create user
/** @var SocialServiceInterface|BaseClient $client */
$client->retrieveAdditionalData();
/** @var RegistrationForm $registrationForm */
$registrationForm = Yii::createObject(ModelMapHelper::RegistrationForm());
$this->mapServiceAttributes($client, $registrationForm);
$user = $registrationForm->socialRegister($client);
if ($user === false) {
throw new ErrorException("Unable to register user");
}
$userService = $this->createService();
if ($user->save() === false) {
throw new ErrorException("Unable to save user:" . var_export($user->errors, true));
}
$user->link('services', $userService);
// check if we need to run post-registration
$user->login(UsersModule::module()->loginDuration);
// check if there's some required or recommended fields missing
foreach (UsersModule::module()->requiredUserAttributes as $attribute) {
if (empty($user->{$attribute})) {
Yii::$app->session->setFlash('info', Yii::t('users', 'Please fill required profile fields.'));
$this->redirectToProfileUpdate();
return;
}
}
foreach (UsersModule::module()->recommendedUserAttributes as $attribute) {
if (empty($user->{$attribute})) {
//! @todo Add limitation on UsersModule::recommendedFieldsMaxPrompts
Yii::$app->session->setFlash('info', Yii::t('users', 'Please fill recommended profile fields.'));
$this->redirectToProfileUpdate();
return;
}
}
}
}