Пример #1
0
 /**
  * Updates an existing User model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $passwordForm = new ChangeUserPasswordForm($model);
     $passwordForm->askOldPassword = false;
     if (\Yii::$app->request->isAjax) {
         \Yii::$app->response->format = Response::FORMAT_JSON;
         $model->load(\Yii::$app->request->post());
         return ActiveForm::validate($model);
     }
     if ($model->load(\Yii::$app->request->post()) && $model->save()) {
         \Yii::$app->session->setFlash(Yz::FLASH_SUCCESS, \Yii::t('admin/t', 'Record was successfully updated'));
         return $this->getCreateUpdateResponse($model);
     } elseif ($passwordForm->load(\Yii::$app->request->post()) && $passwordForm->process()) {
         \Yii::$app->session->setFlash(Yz::FLASH_SUCCESS, \Yii::t('admin/t', 'Password was successfully changed'));
         return $this->getCreateUpdateResponse($model);
     } elseif (Yii::$app->request->post('__action') == 'reset_access_token') {
         $model->access_token = \Yii::$app->security->generateRandomString(User::ACCESS_TOKEN_LENGTH);
         if ($model->save()) {
             \Yii::$app->session->setFlash(Yz::FLASH_SUCCESS, \Yii::t('admin/t', 'Access token was successfully changed'));
         } else {
             \Yii::$app->session->setFlash(Yz::FLASH_SUCCESS, \Yii::t('admin/t', 'Unknown error'));
         }
         return $this->redirect('');
     } else {
         return $this->render('update', ['model' => $model, 'passwordForm' => $passwordForm]);
     }
 }
Пример #2
0
 public function actionIndex()
 {
     /** @var User $model */
     $model = \Yii::$app->user->identity;
     $passwordForm = new ChangeUserPasswordForm($model);
     if (\Yii::$app->request->isAjax) {
         \Yii::$app->response->format = Response::FORMAT_JSON;
         $model->load(\Yii::$app->request->post());
         return ActiveForm::validate($model);
     }
     if ($model->load(\Yii::$app->request->post()) && $model->save()) {
         \Yii::$app->session->setFlash(\yz\Yz::FLASH_SUCCESS, \Yii::t('admin/t', 'Your profile was successfully updated'));
         return $this->redirect(['index']);
     } elseif ($passwordForm->load(\Yii::$app->request->post()) && $passwordForm->process()) {
         \Yii::$app->session->setFlash(\yz\Yz::FLASH_SUCCESS, \Yii::t('admin/t', 'Your password was successfully changed'));
         return $this->redirect(['index']);
     } else {
         return $this->render('index', ['model' => $model, 'passwordForm' => $passwordForm]);
     }
 }