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 editAction() { $this->view->title = "Редагувати дані користувача"; $this->view->headTitle($this->view->title, 'PREPEND'); // $id=$this->getRequest->getParam('id'); $id = $this->getParam('id'); $user = new Model_User($id); //форма для edit $form = new Form_User(); //зберігаємо редаговані дані if ($this->getRequest()->isPost()) { if ($form->isValid($this->getRequest()->getPost())) { //дані з форми $user->fill($form->getValues()); //оскільки ми модифікуємо,то $user->modefied = date('Y-m-d, H:i:s'); $user->save(); $this->_helper->redirector('index'); } } else { //заповнити форму даними цього юзера //populate() приймає асоціативний масив $form->populate($user->populateform()); } $this->view->form = $form; }
public function editAction() { $this->view->title = "Редактировать данные пользователя."; $this->view->headTitle($this->view->title, 'PREPEND'); //$id = $this->getRequest()->getParam('id'); $id = $this->_getParam('id'); $user = new Model_User($id); $form = new Form_User(); if ($this->getRequest()->isPost()) { if ($form->isValid($this->getRequest()->getPost())) { $user->fill($form->getValues()); $user->modified = date('Y-m-d H:i:s'); $user->save(); $this->_helper->redirector('index'); } } else { $form->populate($user->populateForm()); } $this->view->form = $form; }
public function updateAction() { $id = $this->_request->getParam('id'); $formUser = new Form_User(); $formUser->removeElement('username'); $formUser->removeElement('password'); $formUser->removeElement('password2'); $formUser->removeElement('role'); $formUser->removeElement('status'); $formUser->removeElement('avatar'); $modelUser = new User(); if ($this->getRequest()->isPost()) { if ($formUser->isValid($_POST)) { // 上传和获取图片信息 $adapter = new Zend_File_Transfer_Adapter_Http(); //$path = APPLICATION_PATH.'/../public/uploads/'.date("Y-m").'/avatar/'; //$folder = new Zend_Search_Lucene_Storage_Directory_Filesystem($path); //如果文件夹不存在,则创建 //$fileInfo = $adapter->getFileInfo();//获取基本配置 //$extName = $this->_getExtension($fileInfo);//获取扩展名 //$filename = time().'.'.$extName;//重命名 //$adapter->addFilter('Rename', array('target' => $filename, 'overwrite' => true));//执行重命名 //$adapter->setDestination($path); //设定保存路径 //$adapter->addValidator('Size',FALSE, 128000 ); // 上传文件大小 //$adapter->addValidator('Extension', FALSE, array('jpg', 'gif', 'png', 'jpeg')); //扩展名验证 // 获取其它表单数据 $data = array(); $data['sex'] = $formUser->getValue('sex'); $data['email'] = $formUser->getValue('email'); $data['profile'] = $formUser->getValue('profile'); if ($adapter->receive()) { //如执行上传 $updateUser = $modelUser->updateUser($id, $data); } } if (updateUser) { $this->_redirect('user/account/id/' . $id . '/' . $updateUser); } else { throw new Zend_Exception('更新用户信息出错!'); } } $user = $modelUser->find($id)->current(); $formUser->populate($user->toArray()); $this->view->user = $user; $this->view->formUser = $formUser; }