paulon

Untitled

Jan 8th, 2012
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. function login(){
  2. $registry = Zend_Registry::getInstance();
  3. $db = $registry->get('db_adapter');
  4.  
  5. $adapter = new Zend_Auth_Adapter_DbTable($db);
  6. $adapter->setTableName('users')->setIdentityColumn('username')
  7. ->setCredentialColumn('password_unencrypted')
  8. ->setIdentity($username)
  9. ->setCredential($password);
  10.  
  11. $auth = Zend_Auth::getInstance();
  12. $result = $auth->authenticate($adapter);
  13.  
  14. if($result->isValid()){
  15. $identity = $adapter->getResultRowObject(null, 'password_unencrypted');
  16. $auth->getStorage()->write($identity);
  17. $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
  18. $redirector->gotoUrl('/index/');
  19. }
  20. }
  21.  
  22. /*******************************************************/
  23. class indexController extends Zend_Controller_Action{
  24. public function init(){
  25. $auth = Zend_Auth::getInstance();
  26.  
  27. if ($auth->hasIdentity()) {
  28. $userTable = new User_Table();
  29. $select = $userTable->select()->where('id = ?',
  30. $auth->getIdentity()->id);
  31. $this->view->currentUser = $userTable->fetchRow($select);
  32. $adminNamespace = new Zend_Session_Namespace('Admin');
  33.  
  34. } else {
  35. echo 'Zend_auth has no identity'; // this always prints
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment