Guest User

Untitled

a guest
Feb 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. //application/controllers/AuthController.php
  2. <?php
  3. class AuthController extends Zend_Controller_Action
  4. {
  5. public function loginAction(){
  6. $db = $this->_getParam('db');
  7.  
  8. $loginForm = new Default_Form_Auth_Login();
  9.  
  10. if($loginForm->isValid($_POST)) {
  11. $adapter = new Zend_Auth_Adapter_DbTable(
  12. $db,
  13. 'users',
  14. 'username',
  15. 'password',
  16. 'MD5(CONCAT(?, password_salt))'
  17. );
  18.  
  19. $adapter->setIdentity($loginForm->getValue('username'));
  20. $adapter->setCredential($loginForm->getValue('password'));
  21.  
  22. $auth = Zend_Auth::getInstance();
  23. $result = $auth->authenticate($adapter);
  24.  
  25. if($result->isValid()) {
  26. $this->_helper->FlashMessenger('Successful Login');
  27. $this->redirect('/');
  28. return;
  29. }
  30. }
  31.  
  32. $this->view->loginForm = $loginForm;
  33. }
  34. }
  35.  
  36. //application/forms/Auth/Login.php
  37. <?php
  38. class Default_Form_Auth_Login extends Zend_Form
  39. {
  40. public function init(){
  41. $this->setMethod('post');
  42. $this->addElement(
  43. 'text', 'username', array(
  44. 'label' => 'Username:',
  45. 'required' => true,
  46. 'filters' => array('StringTrim'),
  47. )
  48. );
  49. $this->addElement(
  50. 'password', 'password', array(
  51. 'label' => 'Password:',
  52. 'required' => true,
  53. )
  54. );
  55. $this->addElement(
  56. 'submit', 'submit', array(
  57. 'ignore' => true,
  58. 'label' => 'Login',
  59. )
  60. );
  61. }
  62. }
Add Comment
Please, Sign In to add comment