public function onAuthSuccess($client) { $source = $client->getId(); $userAttributes = $client->getUserAttributes(); if (!isset($this->module->attributeParsers[$source])) { throw \yii\base\InvalidConfigException("There are no settings for '{$source}' in the AuthModule::attributeParsers."); } $attributes = $this->module->attributeParsers[$source]($userAttributes); Yii::$app->session->set(AuthModule::PARAMS_SESSION_ID, $attributes); /* @var $auth Auth */ $auth = Auth::find()->where(['source' => $attributes['source'], 'source_id' => $attributes['source_id']])->one(); if (Yii::$app->user->isGuest) { if ($auth) { // login $user = $auth->user; Yii::$app->user->login($user); } else { // signup if (isset($attributes['email']) && $attributes['email'] && User::find()->where(['email' => $attributes['email']])->exists()) { Yii::$app->getSession()->setFlash('error', [Yii::t('yee/auth', "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()])]); Yii::$app->getResponse()->redirect(['auth/default/login']); } else { return $this->createUser($attributes); } } } else { // user already logged in if (!$auth) { // add auth provider $auth = new Auth(['user_id' => Yii::$app->user->id, 'source' => $attributes['source'], 'source_id' => $attributes['source_id']]); $auth->save(); } } }
public function run() { if (!$this->options) { $this->options = $this->getDefaultOptions(); } if (User::hasPermission('viewUsers')) { $searchModel = new UserSearch(); $formName = $searchModel->formName(); $recent = User::find()->orderBy(['id' => SORT_DESC])->limit($this->recentLimit)->all(); foreach ($this->options as &$option) { $count = User::find()->filterWhere($option['filterWhere'])->count(); $option['count'] = $count; $option['url'] = [$this->indexAction, $formName => $option['filterWhere']]; } return $this->render('users', ['height' => $this->height, 'width' => $this->width, 'position' => $this->position, 'users' => $this->options, 'recent' => $recent]); } }
public function search($params) { $query = User::find(); $query->with(['roles']); if (!Yii::$app->user->isSuperadmin) { $query->where(['superadmin' => 0]); } $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->request->cookies->getValue('_grid_page_size', 20)], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } if ($this->gridRoleSearch) { $query->joinWith(['roles']); } $query->andFilterWhere(['id' => $this->id, 'superadmin' => $this->superadmin, 'status' => $this->status, Yii::$app->yee->auth_item_table . '.name' => $this->gridRoleSearch, 'registration_ip' => $this->registration_ip, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'email_confirmed' => $this->email_confirmed]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email]); return $dataProvider; }