X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fformregister.php;h=4abaa5001fd1a712dcef5c3f782199814afc2dee;hb=1f4879b9c1089889355c57ce1e2dda1d3f032872;hp=53b5f6d0f88b7d177e8367af6cb931b5a1f25501;hpb=b5f60f89589412e18b51326378ab13b9a4fa0f19;p=Project_webapp.git
diff --git a/includes/formregister.php b/includes/formregister.php
index 53b5f6d..4abaa50 100644
--- a/includes/formregister.php
+++ b/includes/formregister.php
@@ -4,41 +4,50 @@ $form_firstname = filter_input(INPUT_POST, "firstname", FILTER_SANITIZE_STRING);
$form_numstreet = filter_input(INPUT_POST, "numstreet", FILTER_VALIDATE_INT);
$form_street = filter_input(INPUT_POST, "street", FILTER_SANITIZE_STRING);
$form_postalcode = filter_input(INPUT_POST, "postalcode", FILTER_VALIDATE_INT);
-$form_town = filter_input(INPUT_POST, "postalcode", FILTER_SANITIZE_STRING);
+$form_city = filter_input(INPUT_POST, "city", FILTER_SANITIZE_STRING);
$form_email = filter_input(INPUT_POST, "email", FILTER_VALIDATE_EMAIL);
$form_password = filter_input(INPUT_POST, "password", FILTER_SANITIZE_STRING);
$form_confirmpassword = filter_input(INPUT_POST, "confirmpassword", FILTER_SANITIZE_STRING);
-$error_numstreet = false;
-$error_postalcode = false;
-$error_email = false;
-$error_password = false;
+$input_failure = false;
if (!$form_numstreet) {
- echo "The street number is not valid
" ;
- $error_numstreet = true;
+ echo "The street number is not valid.
" ;
+ $input_failure = true;
}
if (!$form_postalcode) {
- echo "The postal code is not valid
";
- $error_postalcode = true;
+ echo "The postal code is not valid.
";
+ $input_failure = true;
}
if (!$form_email) {
- echo "The email is not valid
";
- $error_email = true;
+ echo "The email is not valid.
";
+ $input_failure = true;
}
-if (strcmp($form_password, $form_confirmpassword) === 0) {
- echo "Password do not match
";
- $error_password = true;
+if (strcmp($form_password, $form_confirmpassword) !== 0) {
+ echo "Password do not match.
";
+ $input_failure = true;
}
if (!empty($form_name) && !empty($form_firstname) && !empty($form_numstreet) && !empty($form_street) &&
- !empty($form_postalcode) && !empty($form_town) && !empty($form_email) && !empty($form_password)){
- global $connection;
- $sql_pquery = "select count(NumCl) from CLIENTS where EmailCl = ?";
- $stmt = $connection->prepare_query($sql_pquery);
- $stmt->bind_param("s", $form_email);
- //$connection->prepared_query_bind_param("s", $form_email);
- $connection->run_prepared_query();
- $connection->close_prepared_query();
+ !empty($form_postalcode) && !empty($form_city) && !empty($form_email) && !empty($form_password) &&
+ !$input_failure) {
+ if (!chk_account($form_email)) {
+ global $connection;
+ $hashed_password = password_hash($form_password, PASSWORD_DEFAULT);
+ $sql_pquery = "insert into CLIENTS (NomCl, PrenomCl, EmailCl, PasswordCl, NumRueCl, NomRueCl, CodePosteCl, VilleCl)
+ values (?, ?, ?, ?, ?, ?, ?, ?)";
+ $connection->prepare_query($sql_pquery);
+ $connection->prepared_query_bind_param("ssssisis", array($form_name, $form_firstname, $form_email, $hashed_password, $form_numstreet, $form_street, $form_postalcode, $form_city));
+ $connection->run_prepared_query();
+ $connection->close_prepared_query();
+ echo "You've successfully registered, you will be redirected to the login form in 3 seconds.
";
+ redirect("index.php?page=login", 3);
+ } else {
+ echo "You're already registered, you will be redirected to the login form in 3 seconds.
";
+ redirect("index.php?page=login", 3);
+ }
+} else {
+ echo "There's a required non filled field or the input in a field do not match the required pattern.
";
+ echo "Retour";
}
?>