Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. // ------ Controller ----------
  2. public function loginAction() {
  3. // action body
  4. $userForm = new Application_Form_Login();
  5. $this->view->form = $userForm;
  6. if ($this->_request->isPost() && $userForm->isValid($_POST)) {
  7.  
  8. $username = $this->getRequest()->getParam('username');
  9. $password = $this->getRequest()->getParam('password');
  10.  
  11. $db = Zend_Db::factory('Pdo_Mysql', array(
  12. 'host' => 'localhost',
  13. 'username' => 'root',
  14. 'password' => 'root',
  15. 'dbname' => 'test'
  16. ));
  17.  
  18. $auth = new Zend_Auth_Adapter_DbTable($db);
  19. $auth->setTableName('users')
  20. ->setIdentityColumn('username')
  21. ->setCredentialColumn('password')
  22. ->setIdentity($username)
  23. ->setCredential($password);
  24. $result = $auth->authenticate();
  25. if($result->isValid()) {
  26. $this->_redirect('/secure');
  27. } else {
  28. $this->view->loginMessage = "Sorry, your username or password was incorrect: " . $username . "/". $password;
  29.  
  30. }
  31.  
  32. }
  33.  
  34. }
  35.  
  36. // -------- View -----------
  37. <h2>User Login</h2>
  38. <p>To login to your account please enter your username and password below...</p>
  39. <?php if($this->loginMessage) { ?>
  40. <p><?php echo $this->loginMessage?></p>
  41. <?php } ?>
  42. <form action="login" method="POST" action="">
  43. <input type="text" name="username" value="" /><br />
  44. <input type="text" name="password" value="" /><br />
  45. <input type="submit" value="submit" />
  46. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement