Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'inc/function.php';
  4.  
  5. session_start();
  6.  
  7. if(!empty($_POST)){
  8.  
  9. $errors = array();
  10. require_once 'inc/db.php';
  11. //$pdo = new PDO('mysql:host=localhost;dbname=ProjetWeb;charset=utf8', 'root', 'root');
  12.  
  13. if(empty($_POST['username']) || !preg_match('/^[a-zA-Z0-9_]+$/',$_POST['username'])){
  14. $errors['username'] = "vous n'avez pas rentré de pseudo";
  15. } else{
  16. $req = $pdo->prepare('SELECT id FROM membres WHERE username = ?');
  17. $req->execute([$_POST['username']]);
  18. $user = $req->fetch();
  19.  
  20. if($user){
  21. $errors['username'] = 'ce pseudo est déjà pris';
  22. }
  23. }
  24.  
  25. if(empty($_POST['email'])){
  26. $errors['email'] = "email invalide";
  27. } else{
  28. $req = $pdo->prepare('SELECT id FROM membres WHERE email = ?');
  29. $req->execute([$_POST['email']]);
  30. $email = $req->fetch();
  31.  
  32. if($email){
  33. $errors['email'] = 'cet email est déjà pris';
  34. }
  35. }
  36.  
  37. if(empty($_POST['password']) || $_POST['password'] != $_POST['password-confirm'] ){
  38. $errors['password'] = "Veuillez rentrer le même mot de passe";
  39. }
  40.  
  41. if(empty($errors)) {
  42.  
  43. $req = $pdo->prepare("INSERT INTO membres SET username = ?, password = ?,email = ?,confirmation_token = ?");
  44. $password = password_hash($_POST['password'], PASSWORD_BCRYPT);
  45. $token = str_random(60);
  46. $req->execute(array($_POST['username'], $password, $_POST['email'],$token));
  47. $user_id = $pdo->lastInsertId();
  48. mail($_POST['email'],'Confirmation de votre compte ',"Afin de valider votre compte merci de cliquer csur ce lien\n\nhttp://localhost/confirm.php?id=$user_id&token=$token");
  49. echo 'http://localhost/confirm.php?id=$user_id&token=$token';
  50. $_SESSION['flash']['success'] = 'un email de confirmation vous a été envoyé';
  51.  
  52. header('Location: login.php');
  53.  
  54. exit();
  55. }
  56.  
  57.  
  58.  
  59.  
  60. }
  61.  
  62. ?>
  63.  
  64. <?php require 'inc/header.php'; ?>
  65.  
  66. <h1>S'inscrire</h1>
  67.  
  68. <?php if (!empty($errors)): ?>
  69.  
  70. <div class="alert alert danger">
  71. <p>Vous n'avez pas rempli le formulaire correctement</p>
  72. <ul>
  73. <?php foreach ($errors as $error): ?>
  74. <li><?= $error; ?></li>
  75. <?php endforeach; ?>
  76. </ul>
  77. </div>
  78. <?php endif; ?>
  79.  
  80.  
  81.  
  82. <form action="" method="POST">
  83. <div class="form-group"></div>
  84. <label for="">Pseudo</label>
  85. <input type="text" name="username" class= "form-control"/>
  86.  
  87. <div class="form-group"></div>
  88. <label for="">Email</label>
  89. <input type="email" name="email" class="form-control"/>
  90.  
  91. <div class="form-group"></div>
  92. <label for="">Mot de passe</label>
  93. <input type="password" name="password" class="form-control"/>
  94.  
  95. <div class="form-group"></div>
  96. <label for="">Confirmer Mot de passe</label>
  97. <input type="password" name="password-confirm" class="form-control"/>
  98.  
  99.  
  100. <button type="submit" class="btn btn-primary">S'enregistrer</button>
  101. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement