Наследование: extends yii\base\Model
Пример #1
0
 /**
  * Updates an existing Game model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionChangePassword()
 {
     $model = $this->model;
     $modelForm = new PasswordChangeForm(['user' => $model]);
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         $modelForm->load(\Yii::$app->request->post());
         \Yii::$app->response->format = Response::FORMAT_JSON;
         return \skeeks\cms\modules\admin\widgets\ActiveForm::validate($modelForm);
     }
     if ($modelForm->load(\Yii::$app->request->post()) && $modelForm->changePassword()) {
         \Yii::$app->getSession()->setFlash('success', 'Успешно сохранено');
         return $this->redirect(['change-password', 'id' => $model->id]);
     } else {
         if (\Yii::$app->request->isPost) {
             \Yii::$app->getSession()->setFlash('error', 'Не удалось изменить пароль');
         }
         return $this->output(\Yii::$app->cms->moduleCms()->renderFile('admin-user/change-password.php', ['model' => $modelForm]));
         /*return $this->render('_form-change-password', [
               'model' => $modelForm,
           ]);*/
     }
 }
Пример #2
0
 public function update(AdminAction $adminAction)
 {
     /**
      * @var $model CmsUser
      */
     $model = $this->model;
     $relatedModel = $model->relatedPropertiesModel;
     $passwordChange = new PasswordChangeForm(['user' => $model]);
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         $passwordChange->load(\Yii::$app->request->post());
         return \yii\widgets\ActiveForm::validateMultiple([$model, $relatedModel, $passwordChange]);
     }
     if ($rr->isRequestPjaxPost()) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         $passwordChange->load(\Yii::$app->request->post());
         if ($model->save() && $relatedModel->save()) {
             \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/cms', 'Saved'));
             if ($passwordChange->new_password) {
                 if (!$passwordChange->changePassword()) {
                     \Yii::$app->getSession()->setFlash('error', "Пароль не изменен");
                 }
             }
             if (\Yii::$app->request->post('submit-btn') == 'apply') {
             } else {
                 return $this->redirect($this->indexUrl);
             }
             $model->refresh();
         } else {
             $errors = [];
             if ($model->getErrors()) {
                 foreach ($model->getErrors() as $error) {
                     $errors[] = implode(', ', $error);
                 }
             }
             \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/cms', 'Could not save') . ". " . implode($errors));
         }
     }
     return $this->render('_form', ['model' => $model, 'relatedModel' => $relatedModel, 'passwordChange' => $passwordChange]);
 }