Ver Mensaje Individual
  #3 (permalink)  
Antiguo 18/09/2011, 11:17
utopiko
 
Fecha de Ingreso: marzo-2006
Mensajes: 230
Antigüedad: 18 años, 1 mes
Puntos: 2
Respuesta: Problema con Proccesed en Zend_Form

Joe pues no idea de como hacer eso que dices para procesar el form, el Auth-Adapter lo he añadido ahora para configurarlo asi:

Código PHP:
Ver original
  1. <?php
  2.  
  3. class Application_Controller_SignupController extends Zend_Controller_Action
  4. {
  5.     public function getForm()
  6.     {
  7.         return new Application_Form_Signup((array(
  8.             'action' => '/login/process',
  9.             'method' => 'post',
  10.         )));
  11.     }
  12.  
  13.     public function getAuthAdapter(array $params)
  14.     {
  15.        
  16.         // ...or configure the instance with setter methods
  17.  
  18.         $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
  19.  
  20.         $authAdapter
  21.             ->setTableName('usuarios')
  22.             ->setIdentityColumn('Username')
  23.             ->setCredentialColumn('Password')
  24.         ;
  25.        
  26.         return $authAdapter;
  27.     }
  28.    
  29.     public function preDispatch()
  30.     {
  31.         if (Zend_Auth::getInstance()->hasIdentity()) {
  32.             // If the user is logged in, we don't want to show the login form;
  33.             // however, the logout action should still be available
  34.             if ('logout' != $this->getRequest()->getActionName()) {
  35.                 $this->_helpr->redirector('index', 'index');
  36.             }
  37.         } else {
  38.             // If they aren't, they can't logout, so that action should
  39.             // redirect to the login form
  40.             if ('logout' == $this->getRequest()->getActionName()) {
  41.                 $this->_helpr->redirector('index');
  42.             }
  43.         }
  44.     }
  45.    
  46.     public function indexAction()
  47.     {
  48.         $this->view->form = $this->getForm();
  49.     }
  50.    
  51.       public function processAction()
  52.     {
  53.         $request = $this->getRequest();
  54.  
  55.         // Check if we have a POST request
  56.         if (!$request->isPost()) {
  57.             return $this->_helper->redirector('index');
  58.         }
  59.  
  60.         // Get our form and validate it
  61.         $form = $this->getForm();
  62.         if (!$form->isValid($request->getPost())) {
  63.             // Invalid entries
  64.             $this->view->form = $form;
  65.             return $this->render('index'); // re-render the login form
  66.         }
  67.  
  68.         // Get our authentication adapter and check credentials
  69.         $adapter = $this->getAuthAdapter($form->getValues());
  70.         $auth    = Zend_Auth::getInstance();
  71.         $result  = $auth->authenticate($adapter);
  72.         if (!$result->isValid()) {
  73.             // Invalid credentials
  74.             $form->setDescription('Invalid credentials provided');
  75.             $this->view->form = $form;
  76.             return $this->render('index'); // re-render the login form
  77.         }
  78.  
  79.         // We're authenticated! Redirect to the home page
  80.         $this->_helper->redirector('http://dkjhgfk', 'http://dkjhgfk');
  81.     }
  82.    
  83.     public function logoutAction()
  84.     {
  85.         Zend_Auth::getInstance()->clearIdentity();
  86.         $this->_helper->redirector('http://dkjhgfk'); // back to login page
  87.     }
  88.    
  89.    
  90. }