public function editAction() { $userModel = $this->_getUserModelFromRequestOrRedirectToListing(); $userEditForm = new Application_Form_UserEdit(array('model' => $userModel)); /** @var $request Zend_Controller_Request_Http */ $request = $this->getRequest(); if ($request->isPost() && $userEditForm->isValid($request->getPost())) { $userModel->setFromArray($userEditForm->getValues()); $this->_getUserMapper()->save($userModel); $this->getFlashMessenger()->addSuccessMessage(sprintf('successfully updated user %s', $userModel->getUsername())); $this->_redirect($this->url('list'), array('exit' => true)); } $this->view->assign('form', $userEditForm); $this->view->assign('user', $userModel); }
public function editAction() { $this->isAllowed('view'); $request = $this->getRequest(); $form = new Application_Form_UserEdit(); $id = $this->_session->getSessionId(); if (!isset($id)) { $this->login(); } $user = $this->isLoggedin(); $form->getElement('firstname')->setValue($user->getFirstName()); $form->getElement('lastname')->setValue($user->getLastName()); //$form->getElement('email')->setValue($user->getEmail()); if ($this->getRequest()->isPost()) { if ($form->isValid($request->getPost())) { //$email = strtolower($form->getValue('email')); $user = $this->isLoggedin(); $user->setFirstName($form->getValue('firstname')); $user->setLastName($form->getValue('lastname')); //$user->setEmail($email); $this->_userRepo->update($user); $this->redirect('/user'); } } $this->view->form = $form; }
public function editAction() { if (!Zend_Auth::getInstance()->hasIdentity()) { return $this->_redirect('/'); } $user = new Zend_Session_Namespace('user'); // process the form $form = new Application_Form_UserEdit(); if ($this->getRequest()->isPost()) { if ($form->isValid($_POST)) { /** * Because some fields are excluded from the form, they will be * set manually */ $id = $user->user['id']; $username = $user->user['username']; $password_salt = $user->user['password_salt']; $password_hash = $user->user['password_hash']; if ($form->getValue('password') == $form->getValue('password_confirm')) { /** * Check if the user changed the email to one that is * already in use */ $user_mapper = new Application_Model_UserMapper(); $email = $user_mapper->findByEmail($form->getValue('email')); $duplicate = false; if ($email) { $email = $email[0]; if ($id != $email->getId()) { $duplicate = true; } } if (!$duplicate) { // update the user $values = $form->getValues(); $user_mapper = new Application_Model_UserMapper(); $user = new Application_Model_User($values); $user->setId($id); $user->setUsername($username); $user->setPassword_salt($password_salt); $user->setPassword_hash($password_hash); $user->setActive(1); $user_mapper->save($user); // update the session $session = new Zend_Session_Namespace('user'); $session->user = $user->get_array(); $this->_helper->FlashMessenger('Successful Update'); return $this->_redirect('/user'); } else { print "A user with this email already exists."; } } else { print "The password was not confirmed."; } } else { print 'Invalid form'; } } // populate the form with the user's information $elements = $form->getElements(); unset($elements['submit']); foreach ($elements as $key => $row) { $form->{$key}->setValue($user->user[$key]); } $this->view->form = $form; }