Hi All,
I’m new to Zend and I’m trying to set up a simple user login script with that framework.
Here’s the LoginController.php :
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
else {
$this->_helper->redirector('index', 'index');
}
}
and the called getAuthAdapter function from the same file :
protected function getAuthAdapter(array $params)
{
$dbAdapter = Zend_Db::factory('Pdo_Mysql', array(
'host' => 'localhost',
'username' => 'root',
'password' => 'my_password_here',
'dbname' => 'my_db_name_here'
));
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('users')
->setIdentityColumn('username')
->setCredentialColumn('password')
->setCredentialTreatment('MD5(?)');
$adapter = $authAdapter;
$adapter->setIdentity($params['username']);
$adapter->setCredential($params['password']);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($adapter);
if ($result->isValid()) {
$user = $adapter->getResultRowObject();
$auth->getStorage()->write($user);
return true;
}
return false;
}
The problem is when I try to login with CORRECT data, the browser is displaying a blank page and stops at /login/process
When I refresh the page, after I confirm the browser’s dialog box :
To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier.
the script renders the index page and I’m logged in.
If I enter invalid login details, the script stops at /login/process and regardless if I refresh the page, it displays a blank page with no content and empty source code… I believe I made some basic mistake and for someone familiar with Zend framework this will be an easy debug (hopefully)… Thank you in advance for your help!!!