Hola buenos dias, tengo un problema con un Zend_Form de autentificacion, con usuario y contraseña. He seguido las indicaciones de
http://bit.ly/2jDe , pero en el helper nunca llega a poner processed y no se como hacerlo funcionar, no tengo ni idea, el codigo mio es el siguiente(Por cierto esta en el Layout, el form):
/application/forms/Signup.php
Código PHP:
Ver original<?
class Application_Form_Signup extends Zend_Form
{
public $processed = false;
public function init()
{
$this->addElement('text', 'name', array( 'label' => 'Name',
'required' => true,
),
));
$this->addElement('text', 'email', array( 'label' => 'Email',
'required' => true,
'EmailAddress',
),
));
$this->addElement('submit', 'go', array( 'label' => 'Sign up',
));
}
}
/application/views/helpers/SignupForm.php
Código PHP:
Ver original<?php
class Zend_View_Helper_SignupForm extends Zend_View_Helper_Abstract
{
public function signupForm(Application_Form_Signup $form)
{
$html = '<h2>Sign up for our newsletter</h2>';
if($form->processed) {
$html .= '<p>Thank you for signing up</p>';
} else {
$html .= $form->render();
}
return $html;
}
}
/application/controllers/SignupControler.php
Código PHP:
Ver original<?php
class Application_Controller_SignupController extends Zend_Controller_Action
{
public function getForm()
{
return new Application_Form_Signup
((array( 'action' => '/login/process',
'method' => 'post',
)));
}
public function getAuthAdapter
(array $params) {
// Leaving this to the developer...
// Makes the assumption that the constructor takes an array of
// parameters which it then uses as credentials to verify identity.
// Our form, of course, will just pass the parameters 'username'
// and 'password'.
}
public function preDispatch()
{
if (Zend_Auth::getInstance()->hasIdentity()) {
// If the user is logged in, we don't want to show the login form;
// however, the logout action should still be available
if ('logout' != $this->getRequest()->getActionName()) {
$this->_helpr->redirector('index', 'index');
}
} else {
// If they aren't, they can't logout, so that action should
// redirect to the login form
if ('logout' == $this->getRequest()->getActionName()) {
$this->_helpr->redirector('index');
}
}
}
public function indexAction()
{
$this->view->form = $this->getForm();
}
public function processAction()
{
$request = $this->getRequest();
// Check if we have a POST request
if (!$request->isPost()) {
return $this->_helper->redirector('index');
}
// Get our form and validate it
$form = $this->getForm();
if (!$form->isValid($request->getPost())) {
// Invalid entries
$this->view->form = $form;
return $this->render('index'); // re-render the login form
}
// Get our authentication adapter and check credentials
$adapter = $this->getAuthAdapter($form->getValues());
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($adapter);
if (!$result->isValid()) {
// Invalid credentials
$form->setDescription('Invalid credentials provided');
$this->view->form = $form;
return $this->render('index'); // re-render the login form
}
// We're authenticated! Redirect to the home page
$this->_helper->redirector('index', 'index');
}
public function logoutAction()
{
Zend_Auth::getInstance()->clearIdentity();
$this->_helper->redirector('index'); // back to login page
}
}