Advertisement
Guest User

Untitled

a guest
May 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. <?php
  2. class PortalFront extends Portal
  3. {
  4. public $zalogowany = null;
  5.  
  6. function __construct($host, $user, $pass, $db)
  7. {
  8. $this->dbo = $this->initDB($host, $user, $pass, $db);
  9. $this->zalogowany = $this->getActualUser();
  10. }
  11.  
  12. function getActualUser()
  13. {
  14. if(isset($_SESSION['zalogowany'])){
  15. return $_SESSION['zalogowany'];
  16. }
  17. else{
  18. return null;
  19. }
  20. }
  21.  
  22. function setMessage($komunikat)
  23. {
  24. $_SESSION['komunikat'] = $komunikat;
  25. }
  26.  
  27. function getMessage()
  28. {
  29. if(isset($_SESSION['komunikat'])){
  30. $komunikat = $_SESSION['komunikat'];
  31. unset($_SESSION['komunikat']);
  32. return $komunikat;
  33. }
  34. else {
  35. return null;
  36. }
  37. }
  38.  
  39. function login()
  40. {
  41. if (!$this->dbo){
  42. return SERVER_ERROR;
  43. }
  44. if ($this->zalogowany){
  45. return NO_LOGIN_REQUIRED;
  46. }
  47. if(!isset($_POST["email"]) || !isset($_POST["haslo"])){
  48. return FORM_DATA_MISSING;
  49.  
  50. }
  51. $user = $_POST["email"];
  52. $pass = $_POST["hasło"];
  53. $userEmailLength = mb_strlen($user, 'utf8');
  54. $userPassLength = mb_strlen($pass, 'utf8');
  55. if ($userEmailLength < 5 || $userEmailLength >250 || $userPassLength<6 || $userPassLength >100){
  56. return ACTION_FAILED;
  57. }
  58. $email = $this->dbo->real_escape_string($user);
  59. $pass = $this->dbo->real_escape_string($pass);
  60. $query = "SELECT 'Id, 'Imię', 'Nazwisko', 'Hasło' FROM Klienci WHERE 'Email' = '$email'";
  61. if (!$result = $this->dbo->query($query)){
  62. echo 'Wystąpił błąd: nieprawidłowe zapytanie...';
  63. return SERVER_ERROR;
  64. }
  65. if ($result->num_rows <>1){
  66. return ACTION_FAILED;
  67. }else{
  68. $row = $result->fetch_row();
  69. $pass_db = $row[3];
  70. if($pass != $pass_db){
  71. return ACTION_FAILED;
  72. }else{
  73. $nazwa=$row[1] . '' . $row[2];
  74. $_SESSION['zalogowany'] = new USER ($row[0], $nazwa);
  75. return ACTION_OK;
  76. }
  77. }
  78. }
  79.  
  80. function logout()
  81. {
  82. $this->userId = 0;
  83. $this->zalogowany =null;
  84. if(isset($_SESSION['zalogowany'])){
  85. unset($_SESSION['zalogowany']);
  86. $this->zalogowany = null;
  87. }
  88. }
  89.  
  90. function showRegistrationForm()
  91. {
  92. $reg = new Registration($this->dbo);
  93. return $reg->showRegistrationForm();
  94. }
  95.  
  96. function registerUser()
  97. {
  98. $reg = new Registration($this->dbo);
  99. return $reg->registerUser();
  100. }
  101.  
  102. function showSearchForm()
  103. {
  104.  
  105. }
  106.  
  107. function showSearchResults()
  108. {
  109.  
  110. }
  111.  
  112. function showBookDetails()
  113. {
  114.  
  115. }
  116.  
  117. function addToBasket()
  118. {
  119.  
  120. }
  121.  
  122. function showBasket()
  123. {
  124.  
  125. }
  126.  
  127. function modifyBasket()
  128. {
  129.  
  130. }
  131.  
  132. function checkout()
  133. {
  134.  
  135. }
  136. }
  137. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement