コード例 #1
0
 public function testChangeCorrect()
 {
     /** @var User $user */
     $user = User::findOne($this->users[0]['id']);
     $form = new PasswordChangeForm($user);
     $form->setAttributes(['currentPassword' => 'adminpass', 'newPassword' => 'new-password', 'newPasswordRepeat' => 'new-password']);
     expect('password is changed', $form->changePassword())->true();
     expect('password is correct', $user->validatePassword('new-password'))->true();
 }
コード例 #2
0
 public function actionPassword()
 {
     $user = $this->findModel();
     $model = new PasswordChangeForm($user);
     if ($model->load(Yii::$app->request->post()) && $model->changePassword()) {
         Yii::$app->getSession()->setFlash('success', Module::t('app', 'FLASH_PASSWORD_CHANGE_SUCCESS'));
         return $this->redirect(['index']);
     } else {
         return $this->render('password', ['model' => $model]);
     }
 }
コード例 #3
0
 public function actionIndex()
 {
     $user = $this->findModel();
     $profile = $user->profile;
     $passwordChangeForm = new PasswordChangeForm($user);
     $profileChangeForm = new ProfileChangeForm($profile);
     $postData = Yii::$app->request->post();
     $session = Yii::$app->getSession();
     if ($passwordChangeForm->load($postData) && $passwordChangeForm->changePassword()) {
         $session->setFlash('success', Yii::t('user/password', 'The password has been successfully updated'));
         $passwordChangeForm = new PasswordChangeForm($user);
     }
     if ($profileChangeForm->load($postData) && $profileChangeForm->update()) {
         $session->setFlash('success', Yii::t('user/password', 'The profile has been successfully updated'));
     }
     return $this->render('index', ['passwordChangeForm' => $passwordChangeForm, 'profileChangeForm' => $profileChangeForm]);
 }