Uhmm este es el controlador...
Código PHP:
<?php
class Users_LoginController extends Zend_Controller_Action
{
public function preDispatch()
{
if (Zend_Auth::getInstance()->hasIdentity()) {
$this->_helper->redirector('index', 'index', 'default');
// o bién $this->redirect('/');
}
}
public function indexAction()
{
if ($this->_request->isPost()) {
$authAdapter = new Zend_Auth_Adapter_DbTable(
Zend_Registry::get('Zend_Db'),
'users',
'username',
'password',
'md5(?)'
);
$values = $this->_request->getPost();
try {
if(empty($values['username'])) {
throw new Exception("nombre de usuario vacío");
} else {
$authAdapter->setIdentity($values['username'])
->setCredential($values['password']);
$result = Zend_Auth::getInstance()->authenticate($authAdapter);
switch ($result->getCode()) {
case Zend_Auth_Result::SUCCESS:
if ($result->isValid()) {
$data = $authAdapter->getResultRowObject(null, 'password');
Zend_Auth::getInstance()->getStorage()->write($data);
$this->_helper->redirector('index', 'index', 'default');
// o bién $this->redirect('/');
}
break;
case Zend_Auth_Result::FAILURE:
throw new Exception("Failure");
break;
case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
throw new Exception("Failure: Identity not foud");
break;
case Zend_Auth_Result::FAILURE_IDENTITY_AMBIGUOUS:
throw new Exception("Failure: Identity abiguous");
break;
case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
throw new Exception("Failure: Credential invalid");
break;
case Zend_Auth_Result::FAILURE_UNCATEGORIZED:
throw new Exception("Failure: Uncategorized");
break;
}
}
} catch (Exception $e) {
$this->view->message = $e->getMessage();
}
}
}
public function logoutAction()
{
Zend_Auth::getInstance()->clearIdentity();
$this->_helper->redirector('index', 'login');
// o bién $this->redirect('/users/login');
}
}
?>