Inheritance: extends yii\base\Model
Ejemplo n.º 1
0
 public function actionChangepassword()
 {
     if (Yii::$app->user->isGuest) {
         return $this->redirect(['login']);
     }
     $model = new ChangePasswordForm();
     $modeluser = Yii::$app->user->identity;
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             try {
                 $modeluser->setPassword($model->newpass);
                 $modeluser->generateAuthKey();
                 $modeluser->change_password = 0;
                 if ($modeluser->save()) {
                     Yii::$app->getSession()->setFlash('success', Yii::t('frontend', 'Password changed'));
                     return $this->redirect(['login']);
                 } else {
                     Yii::$app->getSession()->setFlash('error', Yii::t('frontend', 'Password not changed'));
                     return $this->redirect(['index']);
                 }
             } catch (Exception $e) {
                 Yii::$app->getSession()->setFlash('error', "{$e->getMessage()}");
                 return $this->render('changepassword', ['model' => $model]);
             }
         } else {
             return $this->render('changepassword', ['model' => $model]);
         }
     } else {
         return $this->render('changepassword', ['model' => $model]);
     }
 }
Ejemplo n.º 2
0
 public function actionChangePassword()
 {
     $model = new ChangePasswordForm();
     if ($model->load(\Yii::$app->request->post()) && $model->changepassword()) {
         $this->refresh();
     }
     return $this->render('change-password', ['model' => $model]);
 }
 /**
  * change email
  * @return string
  */
 public function actionPassword()
 {
     $model = new ChangePasswordForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->changePassword()) {
         Yii::$app->session->setFlash('success', Yii::t('app', 'Success! Your Password has been changed!'));
     }
     return $this->render('password', ['model' => $model]);
 }
Ejemplo n.º 4
0
 public function actionSettings()
 {
     $user = User::thisUser();
     $changePasswordModel = new ChangePasswordForm();
     if ($changePasswordModel->load(Yii::$app->request->post()) && $changePasswordModel->validate() && $changePasswordModel->changePassword()) {
         Yii::$app->session->setFlash('success', Lang::t('page/accountProfile', 'changePasswordSuccess'));
         return $this->redirect(['account/settings']);
     }
     $ulogins = Ulogin::findAll(['user_id' => $user->id]);
     return $this->render('settings', ['user' => $user, 'changePasswordModel' => $changePasswordModel, 'ulogins' => $ulogins]);
 }
Ejemplo n.º 5
0
 public function actionChangePassword()
 {
     try {
         $model = new ChangePasswordForm();
     } catch (InvalidParamException $e) {
         throw new BadRequestHttpException($e->getMessage());
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->changePassword()) {
         Yii::$app->getSession()->setFlash('success', Yii::t('app', 'New password was saved.'));
         return $this->redirect(['change-password']);
     }
     return $this->render('changePassword', ['model' => $model]);
 }
Ejemplo n.º 6
0
 public function actionChangePassword()
 {
     $notify = "";
     $type_notify = "";
     if (Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new ChangePasswordForm();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->ChangePassword()) {
             $notify = "Change password successfully";
             $type_notify = "success";
         } else {
             $notify = "Change the password to fail";
             $type_notify = "danger";
         }
     }
     return $this->render('change-password', ['model' => $model, 'notify' => $notify, 'type_notify' => $type_notify]);
 }
Ejemplo n.º 7
0
 public function actionChangePassword()
 {
     $passwordForm = new ChangePasswordForm();
     $paymentForm = Profile::find()->where(['user_id' => Yii::$app->user->identity->id])->one();
     if (!isset($paymentForm)) {
         $paymentForm = new ProfileForm();
     }
     $userForm = User::findOne(Yii::$app->user->identity->id);
     $passwordForm->id = $userForm->id;
     $request = Yii::$app->request;
     if ($request->isPost && $passwordForm->load($request->post()) && $passwordForm->validate()) {
         if ($passwordForm->save()) {
             return $this->redirect(['setting', 'tab' => 'passwordTab', 'alert' => $passwordForm->getAlert()]);
         } else {
             return $this->render('setting', ['userForm' => $userForm, 'passwordForm' => $passwordForm, 'tab' => 'passwordTab', 'paymentForm' => $paymentForm]);
         }
     }
     return $this->render('setting', ['userForm' => $userForm, 'passwordForm' => $passwordForm, 'tab' => 'passwordTab', 'paymentForm' => $paymentForm]);
 }
Ejemplo n.º 8
0
 public function actionPassword($step = '1')
 {
     $params = ['step' => $step];
     if ($step === '1') {
         $verifyPasswordForm = new VerifyPasswordForm();
         if ($verifyPasswordForm->load(Yii::$app->request->post()) && $verifyPasswordForm->validate()) {
             Yii::$app->session['passwordVerified'] = true;
             return $this->redirect(['password', 'step' => '2']);
         }
         $params['verifyPasswordForm'] = $verifyPasswordForm;
     } elseif ($step === '2' && Yii::$app->session->has('passwordVerified') && Yii::$app->session['passwordVerified']) {
         $changePasswordForm = new ChangePasswordForm();
         $changePasswordForm->load(Yii::$app->request->post());
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($changePasswordForm);
         }
         if (Yii::$app->request->isPost && $changePasswordForm->change()) {
             Yii::$app->session->setFlash('success', '密码更改成功!');
             return $this->redirect(['password']);
         }
         $params['changePasswordForm'] = $changePasswordForm;
     } else {
         return $this->redirect(['password']);
     }
     return $this->render('password', $params);
 }
Ejemplo n.º 9
0
 public function actionChangePassword()
 {
     if (Yii::$app->user->can("admin")) {
         $this->layout = "admin";
     }
     Yii::$app->view->title = "Lifeguard - Change Password";
     $model = new ChangePasswordForm();
     $currentUser = User::findByUsername(Yii::$app->user->identity->username);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         try {
             $currentUser->setPassword($_POST['ChangePasswordForm']['newPassword']);
             if ($currentUser->save()) {
                 Yii::$app->getSession()->setFlash('success', 'Password changed');
             } else {
                 Yii::$app->getSession()->setFlash('error', 'Password not changed');
             }
         } catch (Exception $e) {
             Yii::$app->getSession()->setFlash('error', "{$e->getMessage()}");
             return $this->render('change-password', ['model' => $model]);
         }
     }
     return $this->render('change-password', ['model' => $model]);
 }
Ejemplo n.º 10
0
 /**
  * 修改密码
  *
  * @return array
  */
 public function actionPassword()
 {
     $model = new ChangePasswordForm();
     if ($model->load(Yii::$app->request->post(), '') && $model->change()) {
         return ['status' => 'success', 'data' => []];
     } else {
         return ['status' => 'fail', 'data' => ['errors' => $model->getFirstErrors()]];
     }
 }