Пример #1
0
 /** @inheritdoc */
 public function rules()
 {
     return ['requiredFields' => [['login', 'password'], 'required'], 'loginTrim' => ['login', 'trim'], 'loginInfoValidate' => ['password', function ($attribute) {
         if ($this->user === null || !$this->user->validatePassword($this->password)) {
             $this->addError($attribute, Yii::t('user', 'Invalid login or password'));
         }
     }], 'accountAvaiable' => ['password', function ($attribute) {
         if ($this->user->isBlocked()) {
             $this->addError($attribute, Yii::t('user', 'Your account has been blocked'));
         }
     }], 'rememberMe' => ['rememberMe', 'boolean']];
 }
 /**
  * Create new superuser account.
  *
  * @param string      $login    Login account
  * @param null|string $password Password
  */
 public function actionCreate($login, $password)
 {
     $user = Yii::createObject(['class' => User::className(), 'login' => $login, 'password' => $password, 'scenario' => 'console-create']);
     if ($user->consoleCreate()) {
         $this->stdout(Yii::t('user', 'User has been created') . "!\n", Console::FG_GREEN);
     } else {
         $this->stdout(Yii::t('user', 'Please fix following errors:') . "\n", Console::FG_RED);
         foreach ($user->errors as $errors) {
             foreach ($errors as $error) {
                 $this->stdout(' - ' . $error . "\n", Console::FG_RED);
             }
         }
     }
 }
Пример #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     // echo '<PRE>';
     // var_dump($params);
     // die();
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'creator' => $this->creator, 'creator_ip' => $this->creator_ip, 'confirmed_at' => $this->confirmed_at, 'superuser' => $this->superuser, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'login', $this->login]);
     return $dataProvider;
 }
 /**
  * Finds the User model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $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.');
     }
 }
 /**
  * Loads attributes to the user model. You should override this method if you are going to add new fields to the
  * registration form. You can read more in special guide.
  *
  * By default this method set all attributes of this model to the attributes of User model, so you should properly
  * configure safe attributes of your User model.
  *
  * @param User $user
  */
 protected function loadAttributes(User $user)
 {
     $user->setAttributes($this->attributes);
 }