Guest User

Untitled

a guest
Jul 12th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. <?php
  2.  
  3. class IndexController extends Zend_Controller_Action
  4. {
  5.  
  6. public function init()
  7. {
  8. /* Initialize action controller here */
  9. }
  10.  
  11. public function indexAction()
  12. {
  13. // action body
  14. $form = new Default_Form_Login();
  15. $this->view->form = $form;
  16.  
  17.  
  18. $username = $this->_request->getParam('username');
  19. echo "<br>";
  20. $password = $this->_request->getParam('password');
  21.  
  22. if ($username && $password) {
  23. // Save a reference to the Singleton instance of Zend_Auth
  24. $auth = Zend_Auth::getInstance();
  25. // Use 'someNamespace' instead of 'Zend_Auth'
  26. $auth->setStorage(new Zend_Auth_Storage_Session('user'));
  27.  
  28. $dbAdapter = Zend_Db_Table::getDefaultAdapter();
  29. // Configure the instance with constructor parameters...
  30. $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
  31. $authAdapter->setTableName('users')
  32. ->setIdentityColumn('username')
  33. ->setCredentialColumn('password');
  34.  
  35. $authAdapter->setIdentity($username)
  36. ->setCredential($password);
  37.  
  38. $result = $auth->authenticate($authAdapter);
  39.  
  40. switch ($result->getCode()) {
  41. case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
  42. echo '/ do stuff for nonexistent identity /';
  43. break;
  44.  
  45. case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
  46. echo '/ do stuff for invalid credential /';
  47. break;
  48.  
  49. case Zend_Auth_Result::SUCCESS:
  50. echo '/ do stuff for successful authentication /';
  51. $this->_redirect('/members');
  52. break;
  53.  
  54. default:
  55. echo '/ do stuff for other failure /';
  56. break;
  57. }
  58. }
  59. }
  60.  
  61. }
Add Comment
Please, Sign In to add comment