本文整理汇总了PHP中yii\authclient\ClientInterface::getUserAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::getUserAttributes方法的具体用法?PHP ClientInterface::getUserAttributes怎么用?PHP ClientInterface::getUserAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\authclient\ClientInterface
的用法示例。
在下文中一共展示了ClientInterface::getUserAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: successCallback
/**
*
* @param \yii\authclient\ClientInterface $client
* @return type
*/
public function successCallback($client)
{
// TODO: Group FK's to one local user.
// Otherwise, if we log in via FB and another time via google, we
// end up with two local accounts.
if (!$this->action instanceof \yii\authclient\AuthAction) {
throw new \yii\base\InvalidCallException("successCallback is only meant to be executed by AuthAction!");
}
$attributes = $client->getUserAttributes();
$externalUser = new AuthForm();
$externalUser->authProvider = $client->getName();
$externalUser->externalUserId = array_key_exists('id', $attributes) ? $attributes['id'] : null;
if ($externalUser->validate()) {
Yii::info('AuthForm validated.');
if ($externalUser->isRegistered()) {
Yii::info('ExternalUser is registered. Logging in and redirecting to game/index.');
$externalUser->login();
return $this->action->redirect(Url::to(['site/index'], true));
} else {
throw new \yii\base\InvalidCallException("Can't login non-registered user '{$externalUser->externalUserId}@{$externalUser->authProvider}'!");
}
} else {
// TODO error. Throw, display actionError?
Yii::info('AuthForm couldn\'t be validated. Errors: ' . print_r($externalUser->errors, true));
Yii::info('Client attributes: ' . print_r($attributes, true));
}
}
示例2: onAuthSuccess
/**
* @param $client
*
* TODO
*/
public function onAuthSuccess(ClientInterface $client)
{
$attributes = $client->getUserAttributes();
/* @var $auth UserAuth */
$auth = UserAuth::find()->where(['source' => $client->getId(), 'source_id' => $attributes['id']])->one();
if (Yii::$app->user->isGuest) {
if ($auth) {
$user = $auth->user;
Yii::$app->user->login($user);
} else {
if (isset($attributes['email']) && User::find()->where(['email' => $attributes['email']])->exists()) {
Yii::$app->getSession()->setFlash('error', [Yii::t('app', "User with the same email as in {client} account already exists but isn't linked to it. Login using email first to link it.", ['client' => $client->getTitle()])]);
} else {
if ($client->signIn()) {
$this->redirect('/profile');
}
}
}
} else {
if (!$auth) {
$auth = new UserAuth(['user_id' => Yii::$app->user->id, 'source' => $client->getId(), 'source_id' => $attributes['id']]);
$auth->save();
}
}
}
示例3: findSocialProfile
/**
* Ищет в базе и возвращает авторизующийся социальный профиль.
* Если не найден — сохраняет и возвращает.
*
* @param ClientInterface $client
*
* @throws Exception
* @return SocialProfile
*/
protected function findSocialProfile(ClientInterface $client)
{
$attributes = $client->getUserAttributes();
if (null === ($profile = SocialProfile::findOne(['socialId' => $attributes['user_id']]))) {
$profile = $this->save($attributes);
}
return $profile;
}
示例4: createLog
/**
* @param \yii\authclient\ClientInterface $Client
* @return static
*/
public static function createLog(\yii\authclient\ClientInterface $Client)
{
$AuthResponse = new static();
$AuthResponse->client = $Client->getId();
$attributes = $Client->getUserAttributes();
$AuthResponse->response = Json::encode($attributes);
return $AuthResponse;
}
示例5: byClient
/**
* Finds an account by client.
* @param ClientInterface $client
* @return AccountQuery
*/
public function byClient(ClientInterface $client)
{
//xiaoma update
//qq and sina 's attr has no id
$client_type = $client->getId();
switch ($client_type) {
case 'qq':
$client_id = $client->getUserAttributes()['openid'];
break;
case 'sina':
$client_id = $client->getUserAttributes()['uid'];
break;
default:
$client_id = $client->getUserAttributes()['id'];
break;
}
return $this->andWhere(['provider' => $client->getId(), 'client_id' => $client_id]);
}
示例6: updateUserInfo
/**
* @param Account $user
*/
private function updateUserInfo(Account $user)
{
$attributes = $this->client->getUserAttributes();
// $github = ArrayHelper::getValue($attributes, 'login');
// if ($user->github === null && $github) {
// $user->github = $github;
// $user->save();
// }
}
示例7: authSuccessCallback
/**
* @param \yii\authclient\ClientInterface $Client
* @throws \yii\base\NotSupportedException
*/
public function authSuccessCallback(\yii\authclient\ClientInterface $Client)
{
$AuthResponse = new \resources\User\Auth\Response();
$AuthResponse->client = $Client->getId();
$attributes = $Client->getUserAttributes();
$AuthResponse->response = Json::encode($attributes);
$UserQuery = \resources\User::find();
switch ($Client->getId()) {
case 'facebook':
$UserQuery->byFacebookId($attributes['id']);
break;
case 'github':
$UserQuery->byGithubId($attributes['id']);
break;
case 'google':
$UserQuery->byGoogleId($attributes['id']);
break;
case 'linkedin':
$UserQuery->byLinkedinId($attributes['id']);
break;
case 'live':
$UserQuery->byLiveId($attributes['id']);
break;
case 'twitter':
$UserQuery->byTwitterId($attributes['id']);
break;
case 'vkontakte':
$UserQuery->byVkontakteId($attributes['id']);
break;
case 'yandex':
$UserQuery->byYandexId($attributes['id']);
break;
}
/** @var \resources\User $User */
$User = $UserQuery->one();
if ($User instanceof \resources\User) {
$AuthResponse->result = Json::encode($User->id);
} else {
$User = new \resources\User();
$User->appendClientAttributes($Client);
if ($User->save()) {
$User->createSocialLink($Client);
$AuthResponse->result = Json::encode($User->id);
AuthManager()->assign(RbacFactory::Role(\frontend\Permissions::ROLE_USER), $User->id);
} else {
$AuthResponse->result = Json::encode($User->getErrors());
}
}
$AuthResponse->save();
if ($User instanceof \resources\User && !$User->isNewRecord) {
$User->save();
User()->login($User, 86400);
}
}
示例8: autorizar
/**
* Red Social
*/
public function autorizar()
{
$attributes = $this->client->getUserAttributes();
$model = new LoginRedSocialForm();
$model->red_social = $this->client->getName();
$model->perfil_id = $attributes['id'];
$model->correo = isset($attributes['email']) ? $attributes['email'] : null;
$model->nombre = $attributes['first_name'];
$model->apellido = $attributes['last_name'];
$model->genero = $attributes['gender'];
$model->url_perfil = $attributes['link'];
$model->localidad = $attributes['locale'];
$model->estado = $attributes['verified'];
$model->access_token = $this->token_acces;
$model->imagen = $this->getImagenPerfilFacebook($attributes['id']);
//Set return url if the user is authenticated. AuthAction will handle the redirect
if ($returnUrl = $model->autenticarUsuario()) {
\Yii::$app->user->setReturnUrl($returnUrl);
}
}
示例9: appendClientAttributes
/**
* @param \yii\authclient\ClientInterface $Client
* @throws \yii\base\NotSupportedException
*/
public function appendClientAttributes(\yii\authclient\ClientInterface $Client)
{
/** @var \cookyii\modules\Account\resources\Account\Model $self */
$self = $this;
$attributes = $Client->getUserAttributes();
switch ($Client->getId()) {
default:
$attributes = null;
break;
case 'facebook':
$attributes = $this->appendFacebookAttributes($attributes);
break;
case 'instagram':
$attributes = $this->appendInstagramAttributes($attributes);
break;
case 'github':
$attributes = $this->appendGithubAttributes($attributes);
break;
case 'google':
$attributes = $this->appendGoogleAttributes($attributes);
break;
case 'linkedin':
$attributes = $this->appendLinkedinAttributes($attributes);
break;
case 'live':
$attributes = $this->appendLiveAttributes($attributes);
break;
case 'twitter':
$attributes = $this->appendTwitterAttributes($attributes);
break;
case 'vkontakte':
$attributes = $this->appendVkontakteAttributes($attributes);
break;
case 'yandex':
$attributes = $this->appendYandexAttributes($attributes);
break;
case 'odnoklassniki':
$attributes = $this->appendOdnoklassnikiAttributes($attributes);
break;
}
if (!empty($attributes)) {
foreach ($attributes as $key => $value) {
$attr = $self->getAttribute($key);
if ($self->hasAttribute($key) && empty($attr)) {
$self->setAttribute($key, $value);
}
}
}
}
示例10: social
public function social(ClientInterface $client)
{
$user_data = new UserData($client->getName(), $client->getUserAttributes());
if (Yii::$app->user->isGuest) {
$user = User::findSocial($user_data->getObjectName(), $user_data->getObjectName());
if ($user) {
Login::login($user);
} else {
$user_data->save();
}
} else {
User::saveSocial(Yii::$app->user->identity, $user_data);
}
Yii::$app->session->set('social', $client->getName());
}
示例11: authenticate
public function authenticate(ClientInterface $client)
{
$attributes = $client->getUserAttributes();
$provider = $client->getId();
$clientId = $attributes['id'];
$model = SocialAccount::find()->where(['provider' => $provider, 'client_id' => $clientId])->one();
if ($model === NULL) {
$model->save(FALSE);
}
if (NULL === ($user = $model->getUser())) {
$this->action->successUrl = Url::to(['/user/registration/connect', 'account_id' => $model->id]);
} else {
Yii::$app->user->login($user, UserModule::$rememberMeDuration);
}
}
示例12: authenticate
/**
* Logs the user in if this social account has been already used. Otherwise shows registration form.
*
* @param ClientInterface $client
* @return \yii\web\Response
*/
public function authenticate(ClientInterface $client)
{
$attributes = $client->getUserAttributes();
$provider = $client->getId();
$clientId = $attributes['id'];
if (null === ($account = $this->module->manager->findAccount($provider, $clientId))) {
$account = $this->module->manager->createAccount(['provider' => $provider, 'client_id' => $clientId, 'data' => json_encode($attributes)]);
$account->save(false);
}
if (null === ($user = $account->user)) {
$this->action->successUrl = Url::to(['/user/registration/connect', 'account_id' => $account->id]);
} else {
\Yii::$app->user->login($user, $this->module->rememberFor);
}
}
示例13: authenticate
/**
* Logs the user in if this social account has been already used. Otherwise shows registration form.
* @param ClientInterface $client
* @return \yii\web\Response
*/
public function authenticate(ClientInterface $client)
{
$attributes = $client->getUserAttributes();
$provider = $client->getId();
$clientId = $attributes['id'];
$account = UserAccount::find()->where(['provider' => $provider, 'client_id' => $clientId])->one();
if ($account === null) {
$account = \Yii::createObject(['class' => UserAccount::className(), 'provider' => $provider, 'client_id' => $clientId, 'data' => json_encode($attributes), 'created_at' => time()]);
$account->save(false);
}
if (null === ($user = $account->user)) {
$this->action->successUrl = Url::to(['/site/connect', 'account_id' => $account->id]);
} else {
\Yii::$app->user->login($user, 1209600);
// two weeks
}
}
示例14: parseProfile
/**
* Parse profile
*
* @return array
*/
private function parseProfile()
{
$profile = $this->client->getUserAttributes();
$data = [];
switch ($this->type) {
case UserProvider::TYPE_FACEBOOK:
$data = $this->parseProfileFacebook($profile);
break;
case UserProvider::TYPE_VKONTAKTE:
$data = $this->parseProfileVkontakte($profile);
break;
case UserProvider::TYPE_TWITTER:
$data = $this->parseProfileTwitter($profile);
break;
}
return $data;
}
示例15: onAuthSuccess
/**
* @param ClientInterface $client
*/
public function onAuthSuccess($client)
{
$attributes = $client->getUserAttributes();
$email = ArrayHelper::getValue($attributes, 'email');
/** @var Auth $auth */
$auth = Auth::find()->where(['source' => $client->getId(), 'source_id' => $attributes['id']])->one();
if (Yii::$app->user->isGuest) {
if ($auth) {
// login
$user = $auth->user;
Yii::$app->user->login($user, 3600 * 24 * 30);
} else {
// signup
if (User::find()->where(['email' => $email])->exists()) {
Yii::$app->getSession()->setFlash('error', [Yii::t('app', "User with the same email as in {client} account already exists but isn't linked to it. Login using email first to link it.", ['client' => $client->getTitle()])]);
} else {
$password = Yii::$app->security->generateRandomString(6);
$user = new User(['username' => $attributes['login'], 'email' => $email, 'password' => $password]);
$user->generateAuthKey();
$user->generatePasswordResetToken();
$transaction = $user->getDb()->beginTransaction();
if ($user->save()) {
$auth = new Auth(['user_id' => $user->id, 'source' => $client->getId(), 'source_id' => (string) $attributes['id']]);
if ($auth->save()) {
$transaction->commit();
Yii::$app->user->login($user, 3600 * 24 * 30);
} else {
print_r($auth->getErrors());
die;
}
} else {
print_r($user->getErrors());
die;
}
}
}
} else {
// user already logged in
if (!$auth) {
// add auth provider
$auth = new Auth(['user_id' => Yii::$app->user->id, 'source' => $client->getId(), 'source_id' => $attributes['id']]);
$auth->save();
}
}
}