Guest User

Untitled

a guest
Jul 22nd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. form
  2.  
  3. <?php
  4. class App_Form_Login extends Zend_Form
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct($options);
  9. $this->setName('UserLogin');
  10. $username = new Zend_Form_Element_Text('username');
  11. $username->setLabel('User Name')
  12. ->setRequired(true)
  13. ->addFilter('StripTags')
  14. ->addFilter('StringTrim')
  15. ->addValidator('NotEmpty');
  16. $pass = new Zend_Form_Element_Password('pass');
  17. $pass->setLabel('Password')
  18. ->setRequired(true)
  19. ->addFilter('StripTags')
  20. ->addFilter('StringTrim')
  21. ->addValidator('NotEmpty');
  22. $submit = new Zend_Form_Element_Submit('submit');
  23. $redirect = new Zend_Form_Element_Hidden('redirect');
  24. $submit->setAttrib('id', 'submitbutton');
  25. $this->addElements( array ( $username, $pass, $submit));
  26. }
  27. }
  28.  
  29. controller
  30.  
  31. <?php
  32. class IndexController extends Zend_Controller_Action {
  33. public function init() {
  34. }
  35.  
  36. public function indexAction() {
  37. $this->view->mainourbank='yes';
  38. }
  39.  
  40. public function loginAction() {
  41. $this->_helper->layout->disableLayout();
  42. $loginForm = new App_Form_Login();
  43. $redirect = $this->getRequest()->getParam('redirect', 'index/view');
  44. $loginForm->setAttrib('redirect', $redirect );
  45. $auth = Zend_Auth::getInstance();
  46. if(Zend_Auth::getInstance()->hasIdentity()) {
  47. $this->_redirect('/index/view');
  48. } else if ($this->getRequest()->isPost()) {
  49. if ( $loginForm->isValid($this->getRequest()->getPost()) ) {
  50. $username = $this->getRequest()->getPost('username');
  51. $pwd = $this->getRequest()->getPost('pass');
  52. $authAdapter = new App_Model_AuthAdapter($username, $pwd);
  53. $result = $auth->authenticate($authAdapter);
  54. if(!$result->isValid()) {
  55. switch ($result->getCode()) {
  56. case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
  57. $this->view->error = 'user credentials not found';
  58. }
  59. } else {
  60. // $tre = new Acl($username,$pwd);
  61. $this->_redirect( $redirect );
  62. }
  63. }
  64. }
  65. $this->view->loginForm = $loginForm;
  66. }
  67.  
  68. public function viewAction() {
  69.  
  70. }
  71. public function logoutAction() {
  72. $auth = Zend_Auth::getInstance();
  73. $auth->clearIdentity();
  74. $this->_redirect('/');
  75. }
  76.  
  77.  
  78.  
  79. }
  80.  
  81.  
  82.  
  83. model
  84.  
  85. <?php
  86. class App_Model_Users extends Zend_Db_Table_Abstract
  87. {
  88. /*
  89. * @var $_name table name : users
  90. */
  91. protected $_name = 'ourbank_userloginupdates';
  92.  
  93. public function findCredentials($username, $pwd)
  94. {
  95. $select = $this->select()
  96. ->setIntegrityCheck(false)
  97. ->join(array('u' => 'ourbank_userloginupdates'),array('user_id'))
  98. ->where('u.login_name = ?', $username)
  99. ->where('u.password = ?',$pwd)
  100. ->join(array('g'=>'ourbank_usergrants'),'u.user_id = g.user_id')
  101. ->join(array('r' =>'ourbank_grant'),'r.grant_id = g.grant_id')
  102. ->join(array('a' =>'ourbank_grantactivites'),'a.grant_id = r.grant_id')
  103. ->join(array('c' =>'ourbank_activity'),'c.activity_id = a.activity_id');
  104. $result= $this->fetchRow($select);
  105. // print_r($result);
  106. // print_r($result);
  107. // return($result);
  108. // return $result->toArray();
  109. // print_r($result);
  110.  
  111. if($row) {
  112. /*
  113. * If success return the row
  114. */
  115. return $row;
  116. }
  117. return false;
  118. // }
  119.  
  120.  
  121.  
  122. }
  123. }
Add Comment
Please, Sign In to add comment