Guest User

Untitled

a guest
Jul 21st, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 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. // echo $this->view->username=Zend_Registry::get('login_name');
  10. }
  11.  
  12. public function indexAction()
  13. {
  14.  
  15. $this->view->mainourbank='yes';
  16. // $loginDetails = Zend_Auth::getInstance()->getIdentity();
  17. // $this->view->username = $loginDetails->login_name;
  18.  
  19. $this->view->title = "Main Page- Ourbank";
  20. }
  21.  
  22. public function viewAction()
  23. {
  24. // $loginDetails = Zend_Auth::getInstance()->getIdentity();
  25. // $this->view->username = $loginDetails->grantname;
  26. $posts = new Posts();
  27. $this->view->result = $posts->getPosts();
  28. // this works fine
  29.  
  30.  
  31.  
  32.  
  33. }
  34.  
  35.  
  36. public function loginAction()
  37. {
  38. /*
  39. * Creating $loginForm object of class Form_Login
  40. */
  41.  
  42. $this->_helper->layout->disableLayout();
  43.  
  44. $loginForm = new Login();
  45. /*
  46. * Trying to redirect to the page from which it came
  47. */
  48. $redirect = $this->getRequest()->getParam('redirect', 'index/view');
  49. $loginForm->setAttrib('redirect', $redirect );
  50. /*
  51. * Get the Zend_Auth instance
  52. */
  53. $auth = Zend_Auth::getInstance();
  54. /*
  55. * Check whether it has any identity , else check whether the login form is submitted
  56. */
  57. if(Zend_Auth::getInstance()->hasIdentity()) {
  58. $this->_redirect('/index/view');
  59. } else if ($this->getRequest()->isPost()) {
  60. if ( $loginForm->isValid($this->getRequest()->getPost()) ) {
  61. /*
  62. * Get the username
  63. */
  64. $username = $this->getRequest()->getPost('username');
  65.  
  66. /*
  67. * Get password
  68. */
  69. $pwd = $this->getRequest()->getPost('pass');
  70. /*
  71. * Create object $authAdapter of class Model_AuthAdapter
  72.  
  73. */
  74.  
  75. $authAdapter = new AuthAdapter($username, $pwd);
  76. /*
  77. * Try to authenticate and check whether its valid
  78. */
  79. $result = $auth->authenticate($authAdapter);
  80. if(!$result->isValid()) {
  81. switch ($result->getCode()) {
  82. case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
  83. $this->view->error = 'user credentials not found';
  84. }
  85. } else {
  86. /*
  87. * If its valid redirect it . Now it will not work ;) .
  88. * Have not implemented the redirect to the page from where it came.
  89. */
  90. $this->_redirect( $redirect );
  91. }
  92. }
  93. }
  94. /*
  95. * Assign the form elements to view
  96. */
  97. $this->view->loginForm = $loginForm;
  98. }
  99.  
  100. public function logoutAction()
  101. {
  102. /*
  103. * Logout and clear session
  104. */
  105. $auth = Zend_Auth::getInstance();
  106. $auth->clearIdentity();
  107. $this->_redirect('/');
  108. }
  109.  
  110. public function registerAction()
  111. {
  112. /*
  113. * Register for new account
  114. */
  115. $register = new Form_Registration();
  116. if(Zend_Auth::getInstance()->hasIdentity()) {
  117. $this->_redirect('/index/hello');
  118. } else if ($this->getRequest()->isPost()) {
  119. if ( $register->isValid($this->getRequest()->getPost()) ) {
  120.  
  121. }
  122. }
  123. $this->view->register = $register;
  124. }
  125.  
  126. public function forgotPasswordAction()
  127. {
  128. /*
  129. * User submits for new password
  130. */
  131. $forgotPassword = new Form_ForgotPassword();
  132. if(Zend_Auth::getInstance()->hasIdentity()) {
  133. $this->_redirect('/index/hello');
  134. } else if ($this->getRequest()->isPost()) {
  135. if ( $forgotPassword->isValid($this->getRequest()->getPost()) ) {
  136.  
  137. }
  138. }
  139. $this->view->forgotPassword = $forgotPassword;
  140. }
  141. }
Add Comment
Please, Sign In to add comment