/** * @return void */ public function actionPassword() { $model = new PasswordForm(); if (isset($_POST['PasswordForm'])) { $model->attributes = $_POST['PasswordForm']; if ($model->validate()) { // get user from db $user = User::model()->findByPk(Yii::app()->user->id); // set new password $user->password = Yii::app()->securityManager->padUserPassword($model->newPassword); // encrypt encryptionKey with new password $securityManager = Yii::app()->securityManager; $user->encryptionKey = $securityManager->encrypt(Yii::app()->user->encryptionKey, $user->password); // salt password $user->saltPassword(new CEvent()); // save user record $user->save(false); // set success-flash & refresh page Yii::app()->user->setFlash('success', 'Your password was changed successfully.'); $this->refresh(); } } $this->render('password', array('model' => $model)); }
/** * @dataProvider invalidDataProvider */ public function testInvalid($scenario, $attributes, $errors) { $form = new PasswordForm($scenario); $form->userIdentityClass = 'UserIdentity'; $form->setIdentity(new UserIdentity('neo', 'Test1233')); $form->setAttributes($attributes); $this->assertFalse($form->validate()); $this->assertEquals($errors, $form->getErrors()); }
/** * Displays page where user can update account settings password. * @return string|\yii\web\Response */ public function actionSecurity() { $model = new PasswordForm(); $request = YII::$app->request; if ($request->isPost && $model->load(Yii::$app->request->post()) && $model->changePassword()) { Yii::$app->user->logout(); return $this->goHome(); } else { return $this->render('password', ['model' => $model]); } }
public function actionPassword() { $model = new PasswordForm(); if (isset($_POST['PasswordForm'])) { $model->attributes = $_POST['PasswordForm']; if ($model->validate()) { $password = UserIdentity::createPassword($model->password, $model->cost); return $this->render('password_generated', array('password' => $password)); } } $model->cost = 8; $this->render('password', array('model' => $model)); }
public function executePassword($request) { $user = $this->getUser(); $this->form = $form = new PasswordForm($user); if ($request->getMethod() == sfRequest::POST) { $form->bind($request->getPostParameters()); if ($form->isValid()) { $user->setPassword($form->getValue('password')); $user->setAuthenticated(false); //$user->setFlash('notice','Password changed'); return $this->redirect('@homepage'); } } }
/** * Displays the password reset page */ public function actionPassword() { if (Pii::guest()) { $this->_redirectError('You must be logged in to change your password.'); } $_model = new PasswordForm(); // collect user input data if (isset($_POST, $_POST['PasswordForm'])) { $_model->attributes = $_POST['PasswordForm']; // Validate user input and redirect to the previous page if valid if ($_model->validate()) { try { $_userId = Session::getCurrentUserId(); $_result = Password::changePassword($_userId, $_model->old_password, $_model->new_password); if (Option::getBool($_result, 'success')) { Yii::app()->user->setFlash('password-form', 'Your password has been successfully updated.'); } } catch (\Exception $_ex) { $_model->addError(null, $_ex->getMessage()); } } } $this->render('password', array('model' => $_model, 'backUrl' => $this->_getRedirectUrl())); }
<?php class PasswordForm extends MailForm { function PasswordForm() { parent::MailForm(); $this->parseSettings('inc/app/sitellite/forms/user/password/settings.php'); $this->widgets['pw2']->addRule('equals "pw1"', 'Your passwords do not match.'); } function onSubmit($vals) { } } if ($context == 'action') { page_title('Change Password'); } $form = new PasswordForm(); echo $form->run();
public function actionProfile($update = false) { if (Yii::app()->user->isGuest) { $this->redirect(array('login')); } $model = new ProfileForm(); $model->setAttributes($model->getIdentity()->getAttributes()); $passwordForm = new PasswordForm(); if (isset($_POST['ajax']) && $_POST['ajax'] === 'profile-form') { $models = array($model); if (isset($_POST['PasswordForm']) && trim($_POST['PasswordForm']['newPassword']) !== '') { $models[] = $passwordForm; } echo CActiveForm::validate($models); Yii::app()->end(); } $flashes = array('success' => array(), 'error' => array()); if (isset($_POST['PasswordForm']) && trim($_POST['PasswordForm']['newPassword']) !== '') { $passwordForm->setAttributes($_POST['PasswordForm']); if ($passwordForm->validate()) { if ($passwordForm->resetPassword($model->getIdentity())) { $flashes['success'][] = Yii::t('UsrModule.usr', 'Changes have been saved successfully.'); } else { $flashes['error'][] = Yii::t('UsrModule.usr', 'Failed to change password.'); } } } if (isset($_POST['ProfileForm']) && empty($flashes['error'])) { $model->setAttributes($_POST['ProfileForm']); if ($model->validate()) { $oldEmail = $model->getIdentity()->getEmail(); if ($model->save()) { if ($this->module->requireVerifiedEmail && $oldEmail != $model->email) { if ($this->sendEmail($model, 'verify')) { $flashes['success'][] = Yii::t('UsrModule.usr', 'An email containing further instructions has been sent to provided email address.'); } else { $flashes['error'][] = Yii::t('UsrModule.usr', 'Failed to send an email.') . ' ' . Yii::t('UsrModule.usr', 'Try again or contact the site administrator.'); } } $flashes['success'][] = Yii::t('UsrModule.usr', 'Changes have been saved successfully.'); if (!empty($flashes['success'])) { Yii::app()->user->setFlash('success', implode('<br/>', $flashes['success'])); } if (!empty($flashes['error'])) { Yii::app()->user->setFlash('error', implode('<br/>', $flashes['error'])); } $this->redirect(array('profile')); } else { $flashes['error'][] = Yii::t('UsrModule.usr', 'Failed to update profile.') . ' ' . Yii::t('UsrModule.usr', 'Try again or contact the site administrator.'); } } } if (!empty($flashes['success'])) { Yii::app()->user->setFlash('success', implode('<br/>', $flashes['success'])); } if (!empty($flashes['error'])) { Yii::app()->user->setFlash('error', implode('<br/>', $flashes['error'])); } if ($update) { $this->render('updateProfile', array('model' => $model, 'passwordForm' => $passwordForm)); } else { $this->render('viewProfile', array('model' => $model)); } }
function changepasswordAction() { $this->view->activeTab = 'Profile'; $this->view->title = $this->view->translate("Wildfire") . " - " . $this->view->translate("Change_Password"); $form = new PasswordForm(); $consumerModel = new Consumer(); if ($this->_request->isPost()) { //POST $formData = $this->_request->getPost(); if ($form->isValid($formData)) { if ($formData['newpassword'] == $formData['repeat']) { $id = $this->_currentUser->id; $consumer = $consumerModel->find($id)->current(); if ($consumer->password == md5($formData['oldpassword'])) { $consumer->password = md5($form->getValue('newpassword')); $consumer->save(); $form->populate($consumer->toArray()); $this->view->showMessage = $this->view->translate('Save_Successfully'); } else { $this->view->showMessage = $this->view->translate('Password_is_wrong'); } } else { $this->view->showMessage = $this->view->translate('New_password_and_repeat_must_be_consistent'); } } // Zend_Debug::dump($this->veiw->showMessage); } else { //GET $email = $this->_currentUser->email; $form->setDefault('email', $email); } $this->view->form = $form; }