public function loginAction() { $userForm = new Form_User(); $userForm->setAction('/user/login'); $userForm->removeElement('first_name'); $userForm->removeElement('last_name'); $userForm->removeElement('role'); if ($this->_request->isPost() && $userForm->isValid($_POST)) { $data = $userForm->getValues(); //set up the auth adapter // get the default db adapter $db = Zend_Db_Table::getDefaultAdapter(); //create the auth adapter $authAdapter = new Zend_Auth_Adapter_DbTable($db, 'users', 'username', 'password'); //set the username and password $authAdapter->setIdentity($data['username']); $authAdapter->setCredential(md5($data['password'])); //authenticate $result = $authAdapter->authenticate(); if ($result->isValid()) { // store the username, first and last names of the user $auth = Zend_Auth::getInstance(); $storage = $auth->getStorage(); $storage->write($authAdapter->getResultRowObject(array('username', 'first_name', 'last_name', 'role'))); return $this->_forward('index'); } else { $this->view->loginMessage = "Sorry, your username or\n password was incorrect"; } } $this->view->form = $userForm; }
/** * 更改密码 * */ 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; }