/** * Save account information. * @return <type> * * TODO move logic into model or form */ public function saveAction() { $login = Zend_Auth::getInstance()->getIdentity(); $config = $this->getConfig(); $logger = $this->getLogger(); if (!empty($login) && $this->getRequest()->isPost()) { $accountForm = new Account_Form_Account(); $account = new Opus_Account(null, null, $login); $accountForm->populateFromModel($account); $postData = $this->getRequest()->getPost(); $isPasswordChanged = true; if (empty($postData['password'])) { // modify to pass default validation // TODO think about better solution $postData[Account_Form_Account::ELEMENT_PASSWORD] = 'notchanged'; $postData[Account_Form_Account::ELEMENT_CONFIRM_PASSWORD] = 'notchanged'; $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); $logger->debug('login = '******'new login = '******'admin') { $logger->debug('login changed'); $account->setLogin($newLogin); } } if ($isPasswordChanged) { $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); return $this->renderForm($accountForm); } } $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'])); }