Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. <?php
  2.  
  3. public function getRequestUserName() {
  4. return $_POST[self::$name];
  5. }
  6.  
  7. public function getRequestPassword() {
  8. return $_POST[self::$password];
  9. }
  10.  
  11. public function getKeepLoggedIn() {
  12. if (isset($_POST[self::$keep])) {
  13. return true;
  14. }
  15. return false;
  16. }
  17.  
  18. public function userFilledInUsername() {
  19. if (isset($_POST[self::$name]) && !empty($_POST[self::$name])) {
  20. return true;
  21. }
  22. else {
  23. return false;
  24. }
  25. }
  26.  
  27. public function userFilledInPassword() {
  28. if (isset($_POST[self::$password]) && !empty($_POST[self::$password])) {
  29. return true;
  30. }
  31. else {
  32. return false;
  33. }
  34. }
  35.  
  36. public function userWantsToLogIn() {
  37. if (isset($_POST[self::$login])) {
  38. return true;
  39. }
  40. else {
  41. return false;
  42. }
  43. }
  44.  
  45. public function userPressedLogout() {
  46. if (isset($_POST[self::$logout])) {
  47. return true;
  48. }
  49. else {
  50. return false;
  51. }
  52. }
  53.  
  54. private function getResponseMessage() {
  55. if ($this->userWantsToLogIn()) {
  56. $username = $this->getRequestUserName();
  57. $password = $this->getRequestPassword();
  58.  
  59. if ($this->userFilledInPassword() === false && $this->userFilledInUsername()) {
  60. return 'Password is missing';
  61. }
  62.  
  63. if ($this->userFilledInUsername() === false) {
  64. return 'Username is missing';
  65. }
  66.  
  67. if ($this->model->usernameExists($username) === false || $this->model->checkUsernameAndPassword($username, $password) === false) {
  68. return 'Wrong name or password';
  69. }
  70.  
  71. if ($this->model->usernameExists($username) && $this->model->checkUsernameAndPassword($username, $password)) {
  72. return 'Welcome';
  73. }
  74. }
  75.  
  76. if ($this->session->isCookieSet()) {
  77. return 'Welcome back with cookie';
  78. }
  79.  
  80. if ($this->userPressedLogout()) {
  81. return 'Bye bye!';
  82. }
  83.  
  84. return '';
  85. }
  86.  
  87. private function setCookie() {
  88. if ($this->getKeepLoggedIn()) {
  89. $this->session->setKeepLoggedIn();
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement