public function addAction() { $this->view->title = "New User"; $this->view->headTitle($this->view->title, 'PREPEND'); $form = new Form_User(); $form->submit->setLabel('Sign Up'); $this->view->form = $form; if ($this->getRequest()->isPost()) { $formData = $this->getRequest()->getPost(); if ($form->isValid($formData)) { $first = $form->getValue('first'); $last = $form->getValue('last'); $email = $form->getValue('email'); $password = $form->getValue('password1'); $users = new Model_DbTable_Users(); $users->addUser($first, $last, $email, $password); //auto log-in user and redirect to home page // Setup DbTable adapter $dbAdapter = Zend_Db_Table::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter); $authAdapter->setTableName('users')->setIdentityColumn('email')->setCredentialColumn('password'); $authAdapter->setIdentity($email)->setCredential(hash('SHA256', $password)); // authentication attempt $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authAdapter); $userInfo = $authAdapter->getResultRowObject(null, 'password'); // the default storage is a session with namespace Zend_Auth $authStorage = $auth->getStorage(); $authStorage->write($userInfo); $this->_redirect('/index'); } else { $form->populate($formData); } } }
public function passwordAction() { $passwordForm = new Form_User(); $passwordForm->setAction('/user/password'); $passwordForm->removeElement('first_name'); $passwordForm->removeElement('last_name'); $passwordForm->removeElement('username'); $passwordForm->removeElement('role'); $userModel = new Model_User(); if ($this->_request->isPost()) { if ($passwordForm->isValid($_POST)) { $userModel->updatePassword($passwordForm->getValue('id'), $passwordForm->getValue('password')); return $this->_forward('list'); } } else { $id = $this->_request->getParam('id'); $currentUser = $userModel->find($id)->current(); $passwordForm->populate($currentUser->toArray()); } $this->view->form = $passwordForm; }
public function step2Action() { $namespace = new Zend_Session_Namespace('signup'); if (!is_null($namespace->sitename) && !is_null($namespace->siteurl)) { $userform = new Form_User(); $userform->addRepeatPassword(); $userform->setAction('/registration/step2'); $userform->addDBNoRecordExistsValidator(); if ($this->_request->isPost()) { if ($userform->isValid($this->_request->getPost())) { $namespace->email = $userform->getValue('email'); $namespace->password = $userform->getValue('password'); $this->_redirect('/registration/step3'); } } $this->view->userform = $userform->replaceSubmitLabel("Step 3 >"); $this->view->sitename = $namespace->sitename; $this->view->siteurl = $namespace->siteurl; } else { $this->_redirect('/auth'); } }
/** * 更改密码 * */ public function changePasswordAction() { $id = $this->_request->getParam('id'); $formUser = new Form_User(); $formUser->removeElement('username'); $formUser->removeElement('sex'); $formUser->removeElement('email'); $formUser->removeElement('avatar'); $formUser->removeElement('profile'); $formUser->removeElement('role'); $formUser->removeElement('star'); $formUser->removeElement('status'); if ($this->getRequest()->isPost()) { if ($formUser->isValid($_POST)) { $modelUser = new User(); $newpsw = $modelUser->changPassword($id, $formUser->getValue('password')); return $this->_forward('account'); } } $this->view->formUser = $formUser; }