Advertisement
Guest User

Untitled

a guest
Sep 10th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. <?php
  2.  
  3. require_once '../app/db.php';
  4.  
  5. if (isset($_POST['submit'])) {
  6. $name = htmlspecialchars(trim($_POST['name']));
  7. $email = htmlspecialchars(trim($_POST['email']));
  8. $password = htmlspecialchars(trim($_POST['password']));
  9. $password_confirm = htmlspecialchars(trim($_POST['password-confirm']));
  10.  
  11.  
  12. if (empty(($name) || ($email) || ($password) || ($password_confirm))) {
  13. header("Location: /register-view?signup=empty");
  14. exit();
  15. }
  16. else {
  17. if (!preg_match('/^([A-Za-zА-Яа-яЁё]+[\s\,\.\-]*)+$/u', $name)) {
  18. header("Location: /register-view?signup=invalid");
  19. exit();
  20. }
  21. else {
  22. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  23. header("Location: /register-view?signup=invalid_email");
  24. exit();
  25. }
  26. else {
  27. if ($password !== $password_confirm) {
  28. header("Location: /register-view?signup=different_passwords");
  29. exit();
  30. }
  31. else {
  32. $selectEmail = $db->prepare("SELECT COUNT(*) as count FROM users WHERE email = ?");
  33. $email = $_POST['email'];
  34. $selectEmail->execute(array($email));
  35. $resultCountEmail = $selectEmail->fetch(PDO::FETCH_OBJ);
  36. if ($resultCountEmail->count > 0) {
  37. header("Location: /register-view?signup=user_exists");
  38. exit();
  39. }
  40. else {
  41. $len = strlen($_POST['password']);
  42. if ($len < 6) {
  43. header("Location: /register-view?signup=short_password");
  44. exit();
  45. }
  46. else {
  47. $password = password_hash($password, PASSWORD_BCRYPT);
  48. $insertUser = $db->prepare("
  49. INSERT INTO users(name, email, password)
  50. VALUES(:name, :email, :password)");
  51. $insertUser->bindParam(':name', $name);
  52. $insertUser->bindParam(':email', $email);
  53. $insertUser->bindParam(':password', $password);
  54. $insertUser->execute();
  55. header("Location: /auth-view?signup=success");
  56. exit();
  57. }
  58. }
  59. }
  60. }
  61. }
  62. }
  63. } else {
  64. header("Location: /");
  65. exit();
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement