/** * Авторизация */ public function indexAction() { // вывод загаловков $this->view->title = "Авторизация"; $this->view->headTitle($this->view->title, 'PREPEND'); // форма $form = new Application_Form_Auth(); $message = ''; if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $auth = Zend_Auth::getInstance(); $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter(), 'users', 'login', 'password'); $data = $form->getValues(); $authAdapter->setIdentity($data['login'])->setCredential($data['password']); $result = $auth->authenticate($authAdapter); if ($result->isValid()) { $currentUser = $authAdapter->getResultRowObject(array('id_user', 'login', 'role')); Zend_Auth::getInstance()->getStorage()->write($currentUser); $this->_redirect($data['redirect']); } else { $message = 'Попробуйте еще раз.'; } } } // вывод в шаблон $this->view->message = $message; $this->view->form = $form; }
public function loginAction() { $form = new Application_Form_Auth(); $this->view->form = $form; $this->view->message = $this->_flashMessenger->getMessages(); if ($this->getRequest()->isPost()) { $formData = $this->getRequest()->getPost(); if ($form->isValid($formData)) { $authAdapter = new Zend_Auth_Adapter_DbTable(NULL, 'PERSONEN', 'P_LOGNAME', 'P_PASSWORT'); $authAdapter->setCredential($this->_getParam('password'))->setIdentity($this->_getParam('username')); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authAdapter); if ($result->isValid()) { $this->_helper->redirector('index', 'admin'); } else { $this->_flashMessenger->addMessage('Name oder Passwort nicht korrekt!'); $this->_helper->redirector('login', 'index'); } } } }