Advertisement
Guest User

Untitled

a guest
Mar 28th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1.  
  2. <?php
  3. error_reporting(E_ALL & ~E_NOTICE);
  4. session_start();
  5. if (isset($_SESSION["username"])) {
  6. header("location: list.php");
  7. }
  8. require_once "db.php";
  9. $db = db::get();
  10. if (isset($_GET["success"])) {
  11. $success = $db->escape($_GET["success"]);
  12. }
  13. if (isset($_GET["error"])) {
  14. $error = $db->escape($_GET["error"]);
  15. }
  16. ?>
  17. <!DOCTYPE html>
  18. <html>
  19. <head>
  20. <?php require_once("head.php"); ?>
  21. <link rel="stylesheet" href="css/sweetalert2.min.css">
  22. <script src="js/sweetalert2.all.min.js"></script>
  23. <style>
  24. body
  25. {
  26. background-image: url("image/bg.jpg");
  27. background-repeat: no-repeat;
  28. background-size: cover;
  29. }
  30. .jumbotrontext
  31. {
  32. background-color: rgba(255,255,255,.3);
  33. }
  34. .input
  35. {
  36. -webkit-box-shadow: inset 13px 6px 26px -2px rgba(0,0,0,0.75);
  37. -moz-box-shadow: inset 13px 6px 26px -2px rgba(0,0,0,0.75);
  38. box-shadow: inset 13px 6px 26px -2px rgba(0,0,0,0.75);
  39. }
  40. </style>
  41. <script>
  42. function errormsg(errortext)
  43. {
  44. Swal.fire({
  45. type: 'error',
  46. title: 'Hiba',
  47. text: errortext + "!",
  48. })
  49. }
  50. </script>
  51. </head>
  52. <body>
  53. <?php
  54. switch ($error) {
  55. case 'noMatch':
  56. echo "<script>errortext = 'A jelszavak nem egyeznek!'; errormsg(errortext);</script>";
  57. break;
  58. case 'wrongE':
  59. echo "<script>errortext = 'Az e-mail cím hibás formátumu!'; errormsg(errortext);</script>";
  60. break;
  61. case 'empty':
  62. echo "<script>errortext = 'Töltsön ki minden mezőt!'; errormsg(errortext);</script>";
  63. break;
  64. case 'shortPW':
  65. echo "<script>errortext = 'A jelszó nincs minimum 8 karakter!'; errormsg(errortext);</script>";
  66. break;
  67. default:
  68. # code...
  69. break;
  70. }
  71. ?>
  72. <div class="container">
  73. <div class="jumbotron jumbotrontext text-center"><h2>Üdvözöllek!</h2></div>
  74. <form class="container form-group" action="" method="POST" style="color: white;">
  75. <div class="form-row">
  76. <label for="username">Felhasználónév: </label>
  77. <input type="text" id="username" name="username" class="input form-control" id="username" value="<?php echo (isset($users)) ? $users["username"] : "" ; ?>">
  78. </div>
  79. <div class="form-row">
  80. <label>Jelszó: </label>
  81. <input type="password" class="input form-control" name="password" id="password" value="<?php echo (isset($users)) ? $users["password"] :"";?>">
  82. </div>
  83. <div class="form-row">
  84. <label>Jelszó ellenörzés: </label>
  85. <input type="password" class="input form-control" name="password_confirmation" id="passwordConfirmation" value="<?php echo (isset($users)) ? $users["password"] :"";?>">
  86. </div>
  87. <div class="form-row">
  88. <label>Email: </label>
  89. <input type="email" class="input form-control" name="email" id="email" value="<?php echo (isset($users)) ? $users["email"] :"";?>"><br>
  90. </div>
  91.  
  92. <div class="form-row">
  93. <label>Születésnap: </label>
  94. <input type="date" class="input form-control" name="birthday" id="birthday" value="<?php echo (isset($users)) ? $users["birthday"] :""; ?>">
  95. </div>
  96. <hr>
  97. <div class="form-row">
  98. <button class="btn btn-success" type="submit" name="submitForm">Mentés</button>
  99. <a class="btn btn-info" href="login.php" class="btn btn-primary">Bejelentkezés</a>
  100. </div>
  101. </form>
  102. </div>
  103.  
  104. </body>
  105. </html>
  106. <?php
  107. if(true){
  108. if(isset($_POST["submitForm"])){
  109. $username = $db->escape($_POST["username"]);
  110. $password = $db->escape($_POST["password"]);
  111. $email = $db->escape($_POST["email"]);
  112. $birthday = $db->escape($_POST["birthday"]);
  113. $password_confirmation = $db->escape($_POST["password_confirmation"]);
  114. if(empty($username) || empty($password) || empty($email) || empty($birthday)){
  115. echo "<script>window.location.href='index.php?error=empty'</script>";
  116. }else{
  117. if(!filter_var($email,FILTER_VALIDATE_EMAIL)){
  118. echo "<script>window.location.href='index.php?error=wrongE'</script>";
  119. }else if(strlen(trim($password)) < 8){
  120. echo "<script>window.location.href='index.php?error=shortPW'</script>";
  121. }else if($password != $password_confirmation){
  122. echo "<script>window.location.href='index.php?error=noMatch'</script>";
  123. }else{
  124. $checkIfUserExistQuery = "SELECT * FROM users WHERE username ='".$username."'";
  125. $check = $db->getArray($checkIfUserExistQuery);
  126.  
  127. if (empty($check)) {
  128. $insertString = "INSERT INTO users(
  129. `username`,
  130. `password`,
  131. `email`,
  132. `birthday`
  133. ) VALUE(
  134. '".$username."',
  135. '".md5($password)."',
  136. '".$email."',
  137. '".$birthday."'
  138. );";
  139. $db->query($insertString);
  140. $_SESSION["username"] = $username;
  141. header("location: list.php");
  142. }
  143. else
  144. {
  145. echo "<script>window.location.href='index.php?error=userWxists'</script>";
  146. }
  147.  
  148. }
  149. }
  150. }
  151. }
  152. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement