Foros del Web » Programando para Internet » PHP » Zend »

Problema con validación de formulario y Zend_Auth

Estas en el tema de Problema con validación de formulario y Zend_Auth en el foro de Zend en Foros del Web. Si el formulario de login lo creamos directamente en la vista escribiendo los tags a mano ya no podemos usar los validadores de Zend_Form , ...
  #1 (permalink)  
Antiguo 11/02/2009, 13:44
 
Fecha de Ingreso: diciembre-2007
Mensajes: 42
Antigüedad: 16 años, 3 meses
Puntos: 1
Problema con validación de formulario y Zend_Auth

Si el formulario de login lo creamos directamente en la vista escribiendo los tags a mano ya no podemos usar los validadores de Zend_Form , no ?

Para obtener los valores de entrada del formulario bastaría con:
Código PHP:
if ($this->_request->isPost()) {

    
$values $this->_request->getPost();

    
$values['username'];
    
$values['password'];


Luego para poder validarlos se me ocurren tres maneras:
  • Comprobar los valores con condicionales, por ejemplo:
    Código PHP:
    if (isset($values["username"])) { 
        
    // Comprobar con un modelo si existe en la base de datos...
    } else {
        
    // Si no existe $this->view->message = "mensaje...";

  • Zend_auth propone los results.

    Zend_Auth_Result::SUCCESS
    Zend_Auth_Result::FAILURE
    Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND
    Zend_Auth_Result::FAILURE_IDENTITY_AMBIGUOUS
    Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID
    Zend_Auth_Result::FAILURE_UNCATEGORIZED

    Sin embargo hay cosas que no entiendo de esta forma, por ejemplo... Si el authenticate() requiere el Identity... como puede dar un result FAILURE_IDENTITY_NOT_FOUND ??? tampoco entiendo cuando se daría el AMBIGUOUS o el UNCATEGORIZED

  • Crear validadores personalizados Con Zend_Validate

    Como lo haríais vosotros ??? :S

    Gracias !!

Última edición por irilien; 11/02/2009 a las 15:21
  #2 (permalink)  
Antiguo 11/02/2009, 13:47
 
Fecha de Ingreso: diciembre-2007
Mensajes: 42
Antigüedad: 16 años, 3 meses
Puntos: 1
Respuesta: Estoy editando todavía..........

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');
    
}
}
?>

Última edición por irilien; 11/02/2009 a las 14:04
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:38.