/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'password_fail_attempts' => $this->password_fail_attempts, 'password_reset_on' => $this->password_reset_on, 'status' => $this->status, 'status_sec' => $this->status_sec, 'created_on' => $this->created_on, 'updated_on' => $this->updated_on, 'last_login_on' => $this->last_login_on]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'activation_key', $this->activation_key])->andFilterWhere(['like', 'reset_key', $this->reset_key])->andFilterWhere(['like', 'last_login_ip', $this->last_login_ip]); return $dataProvider; }
/** * Logs in a user using the provided username and password. * * @param User $user the user model * * @return boolean whether the user is logged in successfully */ public function login($user) { if (!empty($user->status_sec)) { return (int) $user->status_sec; } if ($user->status_sec == Module::STATUS_EXPIRED || $user->status_sec == Module::STATUS_LOCKED) { return $user->status_sec; } if ($user->isPasswordExpired()) { $user->status_sec = Module::STATUS_EXPIRED; $user->save(false); return Module::STATUS_EXPIRED; } if ($user->isLocked()) { $user->status_sec = Module::STATUS_LOCKED; $user->save(false); return Module::STATUS_LOCKED; } return Yii::$app->user->login($user, $this->rememberMe ? $this->_settings['rememberMeDuration'] : 0); }
/** * User relation * * @return \yii\db\ActiveQuery */ public function getUser() { return $this->hasOne(User::className(), ['id' => 'id']); }
/** * Gets the admin configuration ability for a user model record * * @param User $model the user model * * @return array|bool */ public function getEditSettingsAdmin($model) { if ($model === null) { return false; } $user = Yii::$app->user; if ($model->isSuperuser()) { if (!$user->isSuperuser || $model->id != $user->id) { return false; } return $this->superuserEditSettings; } elseif ($model->isAdmin()) { $allowed = $user->isAdmin && $model->id == $user->id || $user->isSuperuser; if (!$allowed) { return false; } return $this->adminEditSettings; } elseif ($user->isSuperuser || $user->isAdmin) { return true; } return false; }