示例#1
0
 /**
  * Verify Old Password
  */
 public function verifyOldPassword($attribute, $params)
 {
     $current = User::find()->notsafe()->findByPk(Yii::$app->user->id)->one()->password;
     $cond = Yii::$app->security->validatePassword($this->{$attribute}, $current);
     if (!$cond) {
         $this->addError($attribute, Module::t("Old Password is incorrect."));
     }
 }
示例#2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     $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;
     }
     $query->andFilterWhere(['create_at' => $this->create_at, 'lastvisit_at' => $this->lastvisit_at]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'superuser', $this->superuser])->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
示例#3
0
 /**
  * Return admins.
  * @return array superusers names
  */
 public static function getAdmins()
 {
     if (!self::$admins) {
         $admins = User::find()->active()->superuser()->all();
         $return_name = [];
         foreach ($admins as $admin) {
             array_push($return_name, $admin->username);
         }
         self::$admins = $return_name ? $return_name : [''];
     }
     return self::$admins;
 }
示例#4
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @return User
  * @throws HttpException
  */
 public function loadModel()
 {
     if ($this->model === null) {
         if (Yii::$app->request->get('id')) {
             $this->model = User::find()->notsafe()->findbyPk(Yii::$app->request->get('id'))->one();
         }
         if ($this->model === null) {
             throw new NotFoundHttpException('The requested page does not exist.');
         }
     }
     return $this->model;
 }
示例#5
0
 /**
  * Lists all models.
  */
 public function actionIndex()
 {
     $query = User::find()->where('status > ' . User::STATUS_BANNED);
     $provider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->controller->module->user_page_size]]);
     return $this->render('index', ['dataProvider' => $provider]);
 }
示例#6
0
 /**
  * Change password
  */
 public function actionChangepassword()
 {
     ///**@var UserChangePassword $model*/
     $model = new UserChangePassword();
     if (Yii::$app->user->id) {
         if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
         if ($model->load(Yii::$app->request->post())) {
             if ($model->validate()) {
                 $new_password = User::find()->notsafe()->andWhere(['id' => Yii::$app->user->id])->one();
                 $new_password->password = Module::encrypting($model->password);
                 $new_password->activkey = Module::encrypting(microtime() . $model->password);
                 $new_password->save();
                 Yii::$app->user->setFlash('success', Module::t("New password has been saved."));
                 $this->redirect(["profile"]);
             }
         }
         return $this->render('changepassword', ['model' => $model]);
     }
     return $this->redirect(Module::getInstance()->loginUrl);
 }