function insert_user_to_db($name, $mail, $pass, $pass2) { global $db; if (name_already_use($name)) { header("Location:?href=inscription&error=name_use"); exit; } if (!filter_var($mail, FILTER_VALIDATE_EMAIL)) { header("Location:?href=inscription&error=bad_mail"); exit; } if ($pass !== $pass2) { header("Location:?href=inscription&error=not_same_pass"); exit; } if (strlen($pass) < 8) { header("Location:?href=inscription&error=small_pass"); exit; } $token = send_token_mail($mail); if ($token == false) { header("Location:?href=inscription&error=err_mail"); exit; } $req = $db->prepare("INSERT INTO `camagru`.`users` (`name`, `mail`, `password`, `token_verif`) VALUES (:name, :mail, :pass, :token)"); $req->execute(array(':name' => $name, ':mail' => $mail, ':pass' => sha1($pass), ':token' => $token)); }
<?php require_once "model/user.model.php"; if (isset($_GET['action'])) { if ($_GET['action'] == "valide" && isset($_POST['name']) && isset($_POST['mail']) && isset($_POST['pass']) && isset($_POST['pass2'])) { insert_user_to_db($_POST['name'], $_POST['mail'], $_POST['pass'], $_POST['pass2']); header("Location:index.php"); } if ($_GET['action'] == "validation" && isset($_GET['token'])) { valide_account($_GET['token']); header("Location:index.php"); } if ($_GET['action'] == 'js' && isset($_POST['name'])) { if (name_already_use($_POST['name'])) { echo "ok"; } else { echo "nope"; } } } else { if (isset($_GET['error'])) { if ($_GET['error'] == "name_use") { echo "Ce nom d'utilisateur est deja utilise."; } if ($_GET['error'] == "bad_mail") { echo "Votre email n'a pas l'air valide."; } if ($_GET['error'] == "not_same_pass") { echo "Les mots de passe ne corresponde pas."; } if ($_GET['error'] == "small_pass") {