Exemple #1
0
 public function check($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $user = self::model()->findByAttributes(['username' => $this->username]);
         if (empty($user)) {
             $this->addError('username', 'Пользователь не найден.');
         } else {
             if ($user->password !== UserFunctions::encode($this->old_password)) {
                 $this->addError('old_password', 'Неверный пароль');
             }
         }
     }
 }
 public function actionRestore()
 {
     $model = new User('restore');
     if (!empty($_POST)) {
         if (isset($_POST['yt0'])) {
             $model->attributes = $_POST['User'];
             $model->confirm = $_POST['User']['confirm'];
             $model->old_password = $_POST['User']['old_password'];
             if ($model->validate(['old_password', 'confirm'])) {
                 $user = User::model()->findByAttributes(['username' => $model->username]);
                 $user->password = UserFunctions::encode($model->password);
                 $user->save(false);
                 Yii::app()->user->logout();
                 $this->redirect(Yii::app()->homeUrl);
             }
         }
     }
     $this->render('restore', ['model' => $model]);
 }