Guest User

Untitled

a guest
Dec 15th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. <?php
  2.  
  3. class LoginController extends \Phalcon\Mvc\Controller
  4. {
  5.  
  6. private function _registerSession(User $user)
  7. {
  8. $this->session->set('auth', array(
  9. 'loggedin' => true,
  10. 'id' => $user->id,
  11. 'username' => $user->username
  12. ));
  13. }
  14.  
  15. public function indexAction()
  16. {
  17. if ($this->request->isPost()) {
  18. $login = $this->request->getPost('login');
  19. $password = $this->request->getPost('password');
  20.  
  21. $user = Users::findFirstByLogin($login);
  22. if ($user) {
  23. if ($this->security->checkHash($password, $user->password)) {
  24. $this->_registerSession($user);
  25. $this->response->redirect('dashboard');
  26. }
  27. } else {
  28. $this->response->redirect('login');
  29. $this->security->hash(rand());
  30. }
  31. }
  32. }
  33.  
  34. }
Add Comment
Please, Sign In to add comment