Ejemplo n.º 1
0
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'password_fail_attempts' => $this->password_fail_attempts, 'last_login_on' => $this->last_login_on, 'password_reset_on' => $this->password_reset_on, 'created_on' => $this->created_on, 'updated_on' => $this->updated_on]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'password', $this->password])->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;
 }
Ejemplo n.º 2
0
 /**
  * Finds the User model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return User the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = User::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 3
0
 /**
  * User relation
  *
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'id']);
 }
Ejemplo n.º 4
0
 /**
  * User registration action
  *
  * @return mixed
  */
 public function actionRegister()
 {
     $config = $this->module->registrationSettings;
     if (!$config['enabled']) {
         return $this->goBack();
     }
     $model = new User(['scenario' => Module::UI_REGISTER]);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($config['autoActivate']) {
             $model->setStatus(User::STATUS_ACTIVE);
             $model->save();
             Yii::$app->session->setFlash("success", Yii::t('user', Module::MSG_REGISTRATION_ACTIVE, ['username' => $model->username]));
             return $this->goHome();
         } else {
             $model->save();
             if ($model->sendEmail('activation')) {
                 Yii::$app->session->setFlash("success", Yii::t('user', Module::MSG_PENDING_ACTIVATION, ['email' => $model->email]));
             } else {
                 Yii::$app->session->setFlash("warning", Yii::t('user', Module::MSG_PENDING_ACTIVATION_ERR, ['email' => $model->email]));
             }
         }
     }
     return $this->render(Module::UI_REGISTER, ['model' => $model, 'config' => $config]);
 }
Ejemplo n.º 5
0
 /**
  * Finds user by [[username]], [[email]], or both
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         if ($this->_settings['loginType'] === Module::LOGIN_USERNAME) {
             $user = User::findByUsername($this->username);
         } elseif ($this->_settings['loginType'] === Module::LOGIN_EMAIL) {
             $user = User::findByEmail($this->username);
         } else {
             $user = User::findByUserOrEmail($this->username);
         }
         $this->_user = $user->one();
     }
     return $this->_user;
 }
Ejemplo n.º 6
0
 /**
  * Superuser already exists in the database?
  * @return bool
  */
 public function hasSuperUser()
 {
     return count(User::find()->superuser()->all()) > 0;
 }