Esempio n. 1
0
 /**
  * Получение аттрибутов
  * @return array
  * @throws \yii\base\Exception
  */
 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, 'first_name' => $attributes['first_name'], 'last_name' => $attributes['last_name'], 'photo' => $attributes['photo_200'], 'sex' => $this->normalizeSex()[$attributes['sex']]], 'provider_user_id' => $attributes['uid'], 'provider_id' => UserOauthKey::getAvailableClients()['vkontakte'], 'page' => $attributes['uid']];
     return $return_attributes;
 }
Esempio n. 2
0
 /**
  * Получение аттрибутов
  * @return array
  * @throws \yii\base\Exception
  */
 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, 'first_name' => $attributes['login'], 'photo' => $attributes['avatar_url'], 'sex' => User::SEX_MALE], 'provider_user_id' => $attributes['id'], 'provider_id' => UserOauthKey::getAvailableClients()['github'], 'page' => $attributes['login']];
     return $return_attributes;
 }
Esempio n. 3
0
 /**
  * Меняем ссылки на добавление и удаление ключей
  * @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-4']);
     $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-xs">' . Yii::t('user', 'Удалить') . '</span>', Url::toRoute(['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-xs">' . Yii::t('user', 'Добавить') . '</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');
 }
Esempio n. 4
0
 /**
  * Получение аттрибутов
  * @return array
  * @throws \yii\base\Exception
  */
 protected function initUserAttributes()
 {
     $attributes = $this->api('info', 'GET');
     $return_attributes = ['User' => ['email' => $attributes['emails'][0], 'first_name' => $attributes['first_name'], 'last_name' => $attributes['last_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'], 'page' => null];
     return $return_attributes;
 }
Esempio n. 5
0
 /**
  * Получение аттрибутов
  * @return array
  * @throws \yii\base\Exception
  */
 protected function initUserAttributes()
 {
     $attributes = $this->api('people/me', 'GET');
     $return_attributes = ['User' => ['email' => $attributes['emails'][0]['value'], 'first_name' => $attributes['name']['givenName'], 'last_name' => $attributes['name']['familyName'], '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'], 'page' => $attributes['id']];
     return $return_attributes;
 }
Esempio n. 6
0
 /**
  * Удлаение ключа авторизации соц. сети (отвзяывание)
  * @param $id - ID ключа авторизации
  * @return \yii\web\Response
  */
 public function actionUnbind($id)
 {
     /** @var \lowbase\user\models\UserOauthKey $key */
     $key = UserOauthKey::findOne(['user_id' => Yii::$app->user->id, 'provider_id' => UserOauthKey::getAvailableClients()[$id]]);
     if (!$key) {
         Yii::$app->session->setFlash('error', Yii::t('user', 'Ключ не найден'));
     } else {
         /** @var \lowbase\user\models\User $user */
         $user = User::findOne($key->user_id);
         if ($user) {
             if (UserOauthKey::isOAuth($user->id) <= 1 && $user->email === null) {
                 Yii::$app->session->setFlash('error', Yii::t('user', 'Нельзя отвязать единственную соц. сеть, не заполнив Email'));
             } elseif (UserOauthKey::isOAuth($user->id) <= 1 && $user->password_hash === null) {
                 Yii::$app->session->setFlash('error', Yii::t('user', 'Нельзя отвязать единственную соц. сеть, не заполнив пароль'));
             } else {
                 $key->delete();
                 Yii::$app->session->setFlash('success', Yii::t('user', 'Ключ входа удален'));
             }
         }
     }
     return $this->redirect(Yii::$app->request->referrer);
 }
Esempio n. 7
0
echo Html::a('<i class="glyphicon glyphicon-pencil"></i> ' . Yii::t('user', 'Редактировать'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
?>
        <?php 
echo Html::a('<i class="glyphicon glyphicon-trash"></i> ' . Yii::t('user', 'Удалить'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Yii::t('user', 'Вы уверены, что хотите удалить пользователя?'), 'method' => 'post']]);
?>
        <?php 
echo Html::a('<i class="glyphicon glyphicon-menu-left"></i> ' . Yii::t('user', 'Отмена'), ['index'], ['class' => 'btn btn-default']);
?>
    </p>

    <?php 
$keys = '';
if ($model->keys) {
    $keys .= "<div class='row'>";
    foreach ($model->keys as $key) {
        $services = array_flip(UserOauthKey::getAvailableClients());
        $keys .= "<div class='col-xs-1'><a href='" . UserOauthKey::getSites()[$key->provider_id] . $key->page . "'><span class='auth-icon " . $services[$key->provider_id] . "'></span></a></div>";
    }
    $keys .= "</div>";
}
$roles = '';
if ($model->authAssignments) {
    foreach ($model->authAssignments as $role) {
        $type = $role->itemName->type == 1 ? 'label-primary' : 'label-success';
        $roles .= Html::a('<span class="label ' . $type . '">' . $role->itemName->description . '</span>', ['auth-item/view', 'id' => $role->itemName->name]) . " ";
    }
}
?>

    <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'first_name', 'last_name', 'email:email', ['attribute' => 'sex', 'value' => $model->sex ? User::getSexArray()[$model->sex] : null], ['attribute' => 'birthday', 'format' => ['date', 'dd.MM.Y']], 'phone', ['attribute' => 'country_id', 'value' => isset($model->country) ? $model->country->name : null], ['attribute' => 'city_id', 'value' => isset($model->city) ? $model->city->city . " (" . $model->city->state . " " . $model->city->region . ")" : null], 'address', ['attribute' => 'status', 'value' => User::getStatusArray()[$model->status]], 'ip', ['attribute' => 'created_at', 'format' => ['date', 'dd.MM.Y HH:mm:ss']], ['attribute' => 'updated_at', 'format' => ['date', 'dd.MM.Y HH:mm:ss']], ['attribute' => 'login_at', 'format' => ['date', 'dd.MM.Y HH:mm:ss']], ['attribute' => 'image', 'format' => 'raw', 'value' => $model->image ? '<img src="/' . $model->image . '" class="thumbnail">' : null], ['attribute' => Yii::t('user', 'Социальные сети'), 'format' => 'raw', 'value' => $keys ? $keys : null], ['attribute' => Yii::t('user', 'Обладает ролями и допусками'), 'format' => 'raw', 'value' => $roles ? $roles : null]]]);
Esempio n. 8
0
 /**
  * Получение аттрибутов
  * @return array
  * @throws \yii\base\Exception
  */
 protected function initUserAttributes()
 {
     $attributes = $this->api('me', 'GET', ['fields' => implode(',', ['id', 'email', 'first_name', 'last_name', 'picture.height(200).width(200)', 'gender'])]);
     $return_attributes = ['User' => ['email' => $attributes['email'], 'first_name' => $attributes['first_name'], 'last_name' => $attributes['last_name'], 'photo' => $attributes['picture']['data']['url'], 'sex' => $this->normalizeSex()[$attributes['gender']]], 'provider_user_id' => $attributes['id'], 'provider_id' => UserOauthKey::getAvailableClients()['facebook'], 'page' => $attributes['id']];
     return $return_attributes;
 }
Esempio n. 9
0
 /**
  * Получение аттрибутов
  * @return array
  * @throws \yii\base\Exception
  */
 protected function initUserAttributes()
 {
     $attributes = $this->api('account/verify_credentials.json', 'GET');
     $return_attributes = ['User' => ['email' => null, 'first_name' => $attributes['name'], 'photo' => '', 'sex' => User::SEX_MALE], 'provider_user_id' => $attributes['id'], 'provider_id' => UserOauthKey::getAvailableClients()['twitter'], 'page' => $attributes['screen_name']];
     return $return_attributes;
 }