Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <?php
  2.  
  3. namespace controller;
  4.  
  5. require_once("model/LoginModel.php");
  6. require_once("view/LoginView.php");
  7.  
  8. class LoginController {
  9.  
  10. private $model;
  11. private $view;
  12.  
  13. public function __construct(\model\LoginModel $model, \view\LoginView $view) {
  14. $this->model = $model;
  15. $this->view = $view;
  16. }
  17.  
  18. public function doToggleLoginState() {
  19.  
  20. $userClient = $this->view->getUserClientInfo(); //Browser etc
  21.  
  22. if ($this->model->isLoggedIn($userClient)) { //To check session-steal
  23. $this->whenLoggedIn();
  24. } else {
  25. $this->whenLoggedOut();
  26. }
  27. $this->model->renewTemporaryPasswords($userClient);
  28. }
  29.  
  30. private function whenLoggedIn() {
  31. if ($this->view->userWantsToLogout()) {
  32. $this->model->doLogout();
  33. $this->view->setUserLogout();
  34. }
  35. }
  36.  
  37. private function whenLoggedOut() {
  38. if ($this->view->userWantsToLogin()) {
  39. try {
  40. $uc = $this->view->getCredentials();
  41. if ($this->model->doLogin($uc) == true) {
  42. $this->view->setLoginSucceeded();
  43. } else {
  44. $this->view->setLoginFailed();
  45. }
  46. } catch (\Exception $e) {
  47. var_dump($e); //debug
  48. }
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement