public function authAction(){
$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');
// set the input credential values
$uname = $request->getParam('username');
$passwd = $request->getParam('password');
$authAdapter->setIdentity($uname);
$authAdapter->setCredential(md5($passwd));
// perform the auth query, saving the result
$result = $auth->authenticate($authAdapter);
if($result->isValid()){
$data = $authAdapter->getResultRowObject(null, 'passwd');
$auth->getStorage()->write($data);
$this->_redirect('/user/userpage');
}else{
$this->_redirect('/user/loginform');
}
}
public function userpageAction(){
$auth = Zend_Auth::getInstance();
if(!$auth->hasIdentity()){
$this->_redirect('/user/loginform');
}
$request = $this->getRequest();
$user = $auth->getIdentity();
$real_name = $user->real_name;
$username = $user->username;
$url = $request->getBaseURL().'/user/logout';
$this->view->assign('username', $real_name);
$this->view->assign('url', $url);
}
public function logoutAction(){
$auth = Zend_Auth::getInstance();
$auth->clearIdentity();
$this->_redirect('/user');
}
$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');
// set the input credential values
$uname = $request->getParam('username');
$passwd = $request->getParam('password');
$authAdapter->setIdentity($uname);
$authAdapter->setCredential(md5($passwd));
// perform the auth query, saving the result
$result = $auth->authenticate($authAdapter);
if($result->isValid()){
$data = $authAdapter->getResultRowObject(null, 'passwd');
$auth->getStorage()->write($data);
$this->_redirect('/user/userpage');
}else{
$this->_redirect('/user/loginform');
}
}
public function userpageAction(){
$auth = Zend_Auth::getInstance();
if(!$auth->hasIdentity()){
$this->_redirect('/user/loginform');
}
$request = $this->getRequest();
$user = $auth->getIdentity();
$real_name = $user->real_name;
$username = $user->username;
$url = $request->getBaseURL().'/user/logout';
$this->view->assign('username', $real_name);
$this->view->assign('url', $url);
}
public function logoutAction(){
$auth = Zend_Auth::getInstance();
$auth->clearIdentity();
$this->_redirect('/user');
}
No comments:
Post a Comment