/** * Change password */ public function changepasswordAction() { $request = $this->getRequest(); $Profiles = new Application_Model_Profiles(); if (Zend_Auth::getInstance()->hasIdentity()) { $profile = $Profiles->getProfileByField('id', Zend_Auth::getInstance()->getIdentity()->id); } // Redirect if bad or no user if (!isset($profile) || !$profile) { $this->redirect(''); } $this->buildMenu(); $changepassword_form = new Application_Form_ChangePassword(); $this->view->changepassword_form = $changepassword_form; // Form Submitted... if ($request->isPost() && $changepassword_form->isValid($_POST)) { Application_Plugin_Common::redirectOnDemoAccount(); // if regular pw update check for old pw $hash = new Application_Plugin_Phpass(); $old_password = $changepassword_form->getValue('passwordold'); // old password checks $check = false; // pass when old password is blank (user from facebook registration) if ($profile->password == '') { $check = true; } // try with md5 if (is_string($old_password) && md5($old_password) == $profile->password) { $check = true; } // Check that hash value is correct if (is_string($old_password) && $hash->CheckPassword($old_password, $profile->password)) { $check = true; } if (!$check) { $changepassword_form->getElement('passwordold')->setErrors(array(Zend_Registry::get('Zend_Translate')->translate('Enter your password'))); return; } // old password is ok, proceed... $newpassword = $changepassword_form->getValue('password2'); $hash = new Application_Plugin_Phpass(); $hashed_password = $hash->HashPassword($newpassword); $Profiles->updateField($profile->name, 'password', $hashed_password); Application_Plugin_Alerts::success($this->view->translate('Password updated')); // prepare phtml email template $mail_template_path = APPLICATION_PATH . '/views/emails/'; $view = new Zend_View(); $view->setScriptPath($mail_template_path); $body = $view->render('passwordnotice.phtml'); // send email as a security measure $ret = Application_Plugin_Common::sendEmail($profile->email, $this->view->translate('Password updated'), $body, true); } }
public function changePasswordAction() { $usersNs = new Zend_Session_Namespace("members"); $user = new Security_Model_User(); $model = $user->find($usersNs->userId); $request = $this->getRequest(); $form = new Application_Form_ChangePassword(); $elements = $form->getElements(); $form->clearDecorators(); foreach ($elements as $element) { $element->removeDecorator('label'); $element->removeDecorator('Errors'); } if ($request->isPost()) { $options = $request->getPost(); if ($form->isValid($options)) { $model->setPassword(md5($options['password'])); $model->save(); $this->_flashMessenger->addMessage(array('success' => 'Your password has been changed successfully!')); $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/admin/dashboard')); } else { $this->view->password_msg = array_pop($form->getMessages('password')); $this->view->cpassword_msg = array_pop($form->getMessages('confirmPassword')); $form->reset(); $form->populate($options); } } // Assign the form to the view $this->view->form = $form; }
function changePasswordAction() { $usersNs = new Zend_Session_Namespace("members"); $user = new Application_Model_User(); $model = $user->find($usersNs->userId); $request = $this->getRequest(); $form = new Application_Form_ChangePassword(); if ($request->isPost()) { $options = $request->getPost(); if ($form->isValid($options)) { $model->setPassword(md5($options['password'])); $model->save(); $this->view->msg = "Your password changed successfully!"; } else { $form->reset(); $form->populate($options); } } // Assign the form to the view $this->view->form = $form; }