Login_Page.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Landing (login) page file.
  4. *
  5. * Provides a class with all the properties and methods to display the page.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. */
  11. require_once(PATH::PAGE . "Page.php");
  12. /**
  13. * Login page model.
  14. *
  15. * @category Page
  16. */
  17. class Login_Page extends Page{
  18. /**
  19. * @var bool Indicates if the user has been redirected to this page after an error.
  20. */
  21. private $is_error = false;
  22. /**
  23. * @var string Error message to show when login was unsuccesfull and
  24. * the user is back in the login page
  25. */
  26. private $error_message = "";
  27. /**
  28. * Constructor.
  29. *
  30. * Retrieves the data and initializes the variables.
  31. */
  32. public function __construct(){
  33. parent::__construct();
  34. $this->set_public(true);
  35. $this->set_view("login.php");
  36. $this->set_title("Login");
  37. $this->set_description("Login to SWDB");
  38. $this->set_canonical("login/");
  39. $this->add_css("login.css");
  40. error_log("STATUS: " . filter_input(INPUT_GET, "status"));
  41. if (http_response_code() == 401 || filter_input(INPUT_GET, "status") == "401"){
  42. error_log("LOGIN ERROR");
  43. $this->is_error = true;
  44. $this->error_message = "Invalid credentials";
  45. $this->set_message("Invalid credentials");
  46. }
  47. else{
  48. $this->set_code(200);
  49. $this->set_message("OK");
  50. }
  51. }
  52. /**
  53. * Checks if a error has redirected the user to shis page.
  54. *
  55. * @return bool True if there was an error, false otherwise
  56. */
  57. public function is_error(){
  58. return $this->is_error;
  59. }
  60. /**
  61. * Retrieves the error message to show.
  62. *
  63. * @return string Error message.
  64. */
  65. public function get_error_message(){
  66. return $this->error_message;
  67. }
  68. }