This is my MyAuthAdapter class
PHP Code:
<?php
require_once 'Zend/Auth/Adapter/Interface.php';
require_once 'Zend/Auth/Result.php';
class MyAuthAdapter implements Zend_Auth_Adapter_Interface
{
protected $_username;
protected $_password;
/**
* Sets username and password for authentication
*
* @return void
*/
public function __construct($username, $password)
{
$this->_username = $username;
$this->_password = $password;
}
/**
* Performs an authentication attempt
*
* @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
* @return Zend_Auth_Result
*/
public function authenticate()
{
$DB = Zend_Registry::get('dbAdapter');
$select = $DB->select();
$select->from('tbl_users', 'username', 'password');
$select->where('Username = ?', $this->_username);
$select->where('Password = ?', $this->_password);
$sql = $select->__toString();
$rowsFound = $DB->fetchAll($select);
if (isset($rowsFound[0]['username']))
{
$msg=array();
$msg[1]="Authenticated";
$result = new Zend_Auth_Result(true, $this->_username, $msg);
return $result;
}
else
{
$msg=array();
$msg[1]="Sorry, you are not authenticate to access this website. Please check your username and password";
$result = new Zend_Auth_Result(false, $this->_username, $msg);
return $result;
}
}
}
?>
And this is authenticateAction()
PHP Code:
public function authenticateAction()
{
if($this->_request->isPost())
{
Zend_Loader::loadClass('Zend_Filter_StripTags');
$f = new Zend_Filter_StripTags();
$username = $f->filter($this->_request->getPost('username'));
$password = $f->filter($this->_request->getPost('password'));
$authAdapter = new MyAuthAdapter($username, $password);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
if (!$result->isValid()) {
// Authentication failed; print the reasons why
foreach ($result->getMessages() as $message) {
echo "$message\n. Click <a href='".$this->view->baseUrl."/'>here</a> to try again";
}
} else {
$dbAdapter = Zend_Registry::get('dbAdapter');
$select = $dbAdapter->select()
->from(array('r' => 'tbl_roles'),
array('roleid', 'rolename'))
->join(array('u' => 'tbl_users'),
'r.roleid = u.roleid');
$select->where('u.username = ?', $auth->getIdentity());
$rs = $dbAdapter->fetchAll($select);
if (isset($rs[0]['rolename']))
{
$role = $rs[0]['rolename'];
$_SESSION['role'] = $role;
}
$result->getIdentity() === $auth->getIdentity();
$this->_redirect($this->baseUrl.'/');
}
}
else
{
$this->_redirect($this->baseUrl.'/');
}
}
I want to set timeout after 20minutes from the last interaction. Someone help me