/** * Save account information. * @return <type> */ public function saveAction() { $login = Zend_Auth::getInstance()->getIdentity(); $config = Zend_Registry::get('Zend_Config'); if (!empty($login) && $this->getRequest()->isPost()) { $accountForm = new Account_Form_Account($login); $postData = $this->getRequest()->getPost(); $isPasswordChanged = true; if (empty($postData['password'])) { // modify to pass default validation // TODO think about better solution $postData['password'] = '******'; $postData['confirmPassword'] = '******'; $isPasswordChanged = false; } // check if username was provided and if it may be changed if (!isset($postData['username']) || isset($config->account->editPasswordOnly) && $config->account->editPasswordOnly || isset($config->account->changeLogin) && !$config->account->changeLogin) { $postData['username'] = $login; } $postData['oldLogin'] = $login; if ($accountForm->isValid($postData)) { $account = new Opus_Account(null, null, $login); $newLogin = $postData['username']; $password = $postData['password']; $firstname = $postData['firstname']; $lastname = $postData['lastname']; $email = $postData['email']; $isLoginChanged = false; if (isset($config->account->editPasswordOnly) && !$config->account->editPasswordOnly) { $account->setFirstName($firstname); $account->setLastName($lastname); $account->setEmail($email); $this->_logger->debug('login = '******'new login = '******'admin') { $this->_logger->debug('login changed'); $account->setLogin($newLogin); } } if ($isPasswordChanged) { $this->_logger->debug('Password changed'); $account->setPassword($password); } $account->store(); if ($isLoginChanged || $isPasswordChanged) { Zend_Auth::getInstance()->clearIdentity(); } } else { $actionUrl = $this->view->url(array('action' => 'save')); $accountForm->setAction($actionUrl); $this->view->accountForm = $accountForm; return $this->renderScript('index/index.phtml'); } } $this->_helper->redirector('index'); }
public function testValidationBadEmail() { $form = new Account_Form_Account(); $account = new Opus_Account(null, null, 'user'); $form->populateFromModel($account); $postData = array('username' => 'user', 'roleguest' => '1', 'email' => 'notAnEmail', 'password' => 'password', 'confirm' => 'password'); $this->assertFalse($form->isValid($postData)); $errors = $form->getErrors(null, true); $this->assertTrue(isset($errors['email'])); $this->assertTrue(in_array('emailAddressInvalidFormat', $errors['email'])); }