Trying to build up a login scrip and this should work however i get a persistent error that crashes the script. I am not quite sure what is causing this.
Notice: Undefined index: DB in /Sites/dev/application/controllers/LoginController.php on line 34
Catchable fatal error: Argument 1 passed to Zend_Auth_Adapter_DbTable::__construct() must be an instance of Zend_Db_Adapter_Abstract, null given, called in Sites/dev/application/controllers/LoginController.php on line 36 and defined in Sites/dev/library/Zend/Auth/Adapter/DbTable.php on line 128
<?php
/*
Login Authentication method
*/
require_once 'Zend/Controller/Action.php';
require_once 'Zend/Auth.php';
require_once 'Zend/Auth/Adapter/DbTable.php';
class LoginController extends Zend_Controller_Action
{
public function indexAction()
{
/*
Function displays the login forum
*/
$request = $this->getRequest();
$this->view->assign('action', $request->getBaseURL()."/login/auth"); // Submit buttons action
$this->view->assign('title', 'Login Form'); // Page Title
$this->view->assign('username', 'User Name'); // Username
$this->view->assign('password', 'Password'); // Password
}
public function authAction()
{
/*
Login Authentication
*/
$request = $this->getRequest();
$registry = Zend_Registry::getInstance();
$auth = Zend_Auth::getInstance();
$db = $registry['DB'];
$authAdapter = new Zend_Auth_Adapter_DbTable($db);
$authAdapter->setTableName('users')->setIdentityColumn('username')->setCredentialColumn('password');
/*
Pass data though validation
*/
$uname = $request->getParam('username');
$paswd = $request->getParam('password');
$authAdapter->setIdentity($uname);
$authAdapter->setCredential(md5($paswd));
/*
Authenticate the user
*/
$result = $auth->authenticate($authAdapter);
if ($result->isValid())
{
$data = $authAdapter->getResultRowObject(null,'password');
$auth->getStorage()->write($data);
$this->_redirect('/index/welcome/');
}
else
{
$this->_redirect('/login/');
}
}
}
?>