Ver Mensaje Individual
  #6 (permalink)  
Antiguo 23/09/2010, 21:31
daniko_013
 
Fecha de Ingreso: abril-2010
Ubicación: Lima-Peru
Mensajes: 94
Antigüedad: 14 años, 1 mes
Puntos: 2
Respuesta: Centrar la autenticacion con Zend Framework

si tengo el controllador AuthenticateController dentro del modulo Default, y dentro de el tengo la clase Default_AuthenticateController extends Zend_Controller_Action
con los action loginAction, logoutAction, estoy viendo todo y la verdad no encontro el problema.

Pongo el AuthenticateController:

Código PHP:
class Default_AuthenticateController extends Zend_Controller_Action
{

    public function 
init()
    {
        
/* Initialize action controller here */
    
}

    public function  
preDispatch() {
            
    }
    public function 
indexAction()
    {
        
    }

    public function 
loginAction()
    {
        if(
Zend_Auth::getInstance()->hasIdentity()){
            
$this->_redirect('/index/index');
        }
        
        
$request $this->getRequest();
        
$form = new Default_Form_LoginForm();
        if(
$request->isPost()){
            if(
$form->isValid($this->_request->getPost())){
                
$authAdapter $this->getAuthAdapter();
                
$username $form->getValue('username');
                
$password $form->getValue('password');

                
$authAdapter->setIdentity($username)
                            ->
setCredential(md5($password));

                
$auth Zend_Auth::getInstance();
                
$result $auth->authenticate($authAdapter);
                if(
$result->isValid()){
                    
$identity $authAdapter->getResultRowObject();

                    
$authStorage $auth->getStorage();
                    
$authStorage->write($identity);

                    
$this->_redirect('index/index');
                }  else {
                    
$this->view->errorMessage="Usuario o Paswword Incorrectos";
                    
                }
            }
        }
        
$this->view->form $form;
        
    }

    public function 
logoutAction()
    {
        
Zend_Auth::getInstance()->clearIdentity();
        
$this->_redirect('/authenticate/login');
    }

    private function 
getAuthAdapter(){
        
$authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
        
$authAdapter->setTableName('user')
                   ->
setIdentityColumn('user_name')
                ->
setCredentialColumn('user_password');

        return 
$authAdapter;
    }