protected function createKey($attributes, $user_id) { $key = new UserOauthKey(); $key->provider_id = $attributes['provider_id']; $key->provider_user_id = $attributes['provider_user_id']; $key->user_id = $user_id; return $key->save(); }
/** * @inheritdoc */ protected function initUserAttributes() { $attributes = $this->api('users.get.json', 'GET', ['fields' => implode(',', ['uid', 'first_name', 'last_name', 'photo_200', 'sex'])]); $attributes = array_shift($attributes['response']); $return_attributes = ['User' => ['email' => isset($this->accessToken->params['email']) ? $this->accessToken->params['email'] : null, 'username' => $attributes['first_name'] . ' ' . $attributes['last_name'], 'photo' => $attributes['photo_200'], 'sex' => $this->normalizeSex()[$attributes['sex']]], 'provider_user_id' => $attributes['uid'], 'provider_id' => UserOauthKey::getAvailableClients()['vkontakte']]; return $return_attributes; }
/** * @inheritdoc */ protected function initUserAttributes() { $attributes = $this->api('user', 'GET'); $emails = $this->api('user/emails', 'GET'); $verifiedEmail = ''; foreach ($emails as $email) { if ($email['verified'] && $email['primary']) { $verifiedEmail = $email['email']; } } $return_attributes = ['User' => ['email' => $verifiedEmail, 'username' => $attributes['login'], 'photo' => $attributes['avatar_url'], 'sex' => User::SEX_MALE], 'provider_user_id' => $attributes['id'], 'provider_id' => UserOauthKey::getAvailableClients()['github']]; return $return_attributes; }
/** * Outputs client auth link. * @param ClientInterface $client external auth client instance. * @param string $text link text, if not set - default value will be generated. * @param array $htmlOptions link HTML options. * @throws InvalidConfigException on wrong configuration. */ public function clientLink($client, $text = null, array $htmlOptions = []) { echo Html::beginTag('div', ['class' => 'col-xs-6']); $exists = UserOauthKey::findOne(['user_id' => Yii::$app->user->id, 'provider_id' => UserOauthKey::getAvailableClients()[$client->getId()]]); if ($exists) { $button = Html::a('<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> <span class="hidden-md">' . Yii::t('yii', 'Delete') . '</span>', Url::toRoute(['/user/auth/unbind', 'id' => $client->getId()]), ['class' => 'btn btn-danger btn-sm', 'onclick' => '$(this).off("click"); return true;']); } else { $viewOptions = $client->getViewOptions(); if (isset($viewOptions['popupWidth'])) { $htmlOptions['data-popup-width'] = $viewOptions['popupWidth']; } if (isset($viewOptions['popupHeight'])) { $htmlOptions['data-popup-height'] = $viewOptions['popupHeight']; } $htmlOptions['class'] = 'btn btn-success btn-sm'; $button = Html::a('<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> <span class="hidden-md">' . Yii::t('users', 'ADD') . '</span>', $this->createClientUrl($client), $htmlOptions); } echo Html::tag('span', $button, ['class' => 'auth-icon ' . $client->getName(), 'style' => 'padding-left: 40px; margin-bottom: 10px;']); echo Html::endTag('div'); }
/** * @inheritdoc */ protected function initUserAttributes() { $attributes = $this->api('info', 'GET'); $return_attributes = ['User' => ['email' => $attributes['emails'][0], 'username' => $attributes['real_name'], 'photo' => 'https://avatars.yandex.net/get-yapic/' . $attributes['default_avatar_id'] . '/islands-200', 'sex' => $this->normalizeSex()[$attributes['sex']]], 'provider_user_id' => $attributes['id'], 'provider_id' => UserOauthKey::getAvailableClients()['yandex']]; return $return_attributes; }
/** * @inheritdoc */ protected function initUserAttributes() { $attributes = $this->api('people/~:(' . implode(',', ['id', 'email-address', 'first-name', 'last-name', 'picture-urls::(original)']) . ')', 'GET'); $return_attributes = ['User' => ['email' => $attributes['email-address'], 'username' => $attributes['first-name'] . ' ' . $attributes['last-name'], 'photo' => isset($attributes['picture-urls']) ? $attributes['picture-urls']['picture-url'] : '', 'sex' => User::SEX_MALE], 'provider_user_id' => $attributes['id'], 'provider_id' => UserOauthKey::getAvailableClients()['linkedin']]; return $return_attributes; }
/** * @inheritdoc */ protected function initUserAttributes() { $attributes = $this->api('me', 'GET', ['fields' => implode(',', ['id', 'email', 'name', 'picture.height(200).width(200)', 'gender'])]); $return_attributes = ['User' => ['email' => $attributes['email'], 'username' => $attributes['name'], 'photo' => $attributes['picture']['data']['url'], 'sex' => $this->normalizeSex()[$attributes['gender']]], 'provider_user_id' => $attributes['id'], 'provider_id' => UserOauthKey::getAvailableClients()['facebook']]; return $return_attributes; }
/** * @inheritdoc */ protected function initUserAttributes() { $attributes = $this->api('people/me', 'GET'); $return_attributes = ['User' => ['email' => $attributes['emails'][0]['value'], 'username' => $attributes['displayName'], 'photo' => str_replace('sz=50', 'sz=200', $attributes['image']['url']), 'sex' => $this->normalizeSex()[$attributes['gender']]], 'provider_user_id' => $attributes['id'], 'provider_id' => UserOauthKey::getAvailableClients()['google']]; return $return_attributes; }
/** * @inheritdoc */ protected function initUserAttributes() { $attributes = $this->api('me', 'GET'); $return_attributes = ['User' => ['email' => $attributes['emails']['preferred'], 'username' => $attributes['name'], 'photo' => '', 'sex' => $attributes['gender'] != null ? $this->normalizeSex()[$attributes['gender']] : User::SEX_MALE], 'provider_user_id' => $attributes['id'], 'provider_id' => UserOauthKey::getAvailableClients()['live']]; return $return_attributes; }
public function getOauthKeys() { return $this->hasMany(UserOauthKey::className(), 'user_id'); }
/** * @inheritdoc */ protected function initUserAttributes() { $attributes = $this->api('account/verify_credentials.json', 'GET'); $return_attributes = ['User' => ['email' => null, 'username' => $attributes['name'], 'photo' => '', 'sex' => User::SEX_MALE], 'provider_user_id' => $attributes['id'], 'provider_id' => UserOauthKey::getAvailableClients()['twitter']]; return $return_attributes; }