diff --git a/server_files/controllers/confirmer_mail.php b/server_files/controllers/confirmer_mail.php index abe2e58..ea06f20 100644 --- a/server_files/controllers/confirmer_mail.php +++ b/server_files/controllers/confirmer_mail.php @@ -2,18 +2,24 @@ $token = $_GET["token"]; +$has_error = false; + if (isset($token)) { $result = $DB->query("SELECT `email` FROM `users` WHERE `confirm_email` = '$token' AND `year` = '$YEAR';"); - if (($data = $result->fetch()) === FALSE) - $error_message = "Le jeton est invalide. Votre compte est peut-être déjà validé ?"; + if (($data = $result->fetch()) === FALSE) { + $has_error = true; + $error_message = "Le jeton est invalide. Votre compte est peut-être déjà validé ?"; + } else { $DB->exec("UPDATE `users` SET `confirm_email` = NULL WHERE `confirm_email` = '$token';"); $error_message = "Votre adresse mail a été validée ! Vous pouvez désormais vous connecter."; } } else { + $has_error = true; $error_message = "Il n'y a pas de compte à valider !"; } require_once "server_files/views/header.php"; -echo "

$error_message

"; +if (!$has_error) +echo "
$error_message
"; require_once "server_files/views/footer.php"; diff --git a/server_files/controllers/inscription.php b/server_files/controllers/inscription.php index 851909d..a0c5bb3 100644 --- a/server_files/controllers/inscription.php +++ b/server_files/controllers/inscription.php @@ -23,6 +23,7 @@ class NewUser public $role; public $school; public $class; + public $receive_animath_mails; public $description; public $confirm_email_token; @@ -33,6 +34,8 @@ class NewUser { foreach ($data as $key => $value) $this->$key = htmlspecialchars($value); + + $this->receive_animath_mails = $this->receive_animath_mails ? 1 : 0; } public function makeVerifications() @@ -63,10 +66,10 @@ class NewUser if (!$DB->query("SELECT `id` FROM `users` WHERE `year` = $YEAR;")->fetch()) $this->role = Role::ADMIN; - $req = $DB->prepare("INSERT INTO `users`(`email`, `pwd_hash`, `confirm_email`, `surname`, `first_name`, `school`, `class`, `role`, `description`, `year`) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); + $req = $DB->prepare("INSERT INTO `users`(`email`, `pwd_hash`, `confirm_email`, `surname`, `first_name`, `school`, `class`, `role`, `description`, `receive_animath_mails`, `year`) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); $req->execute([$this->email, password_hash($this->password, PASSWORD_BCRYPT), $this->confirm_email_token, $this->surname, $this->first_name, - $this->school, SchoolClass::getName($this->class), Role::getName($this->role), $this->description, $YEAR]); + $this->school, SchoolClass::getName($this->class), Role::getName($this->role), $this->description, $this->receive_animath_mails, $YEAR]); Mailer::sendRegisterMail($this); } diff --git a/server_files/views/header.php b/server_files/views/header.php index 8c770ed..5067ade 100644 --- a/server_files/views/header.php +++ b/server_files/views/header.php @@ -106,6 +106,6 @@
- Erreur : + Erreur :
+
+ + receive_animath_mails ? "checked" : "" ?> /> +
+
diff --git a/server_files/views/mon_compte.php b/server_files/views/mon_compte.php index 5010c59..6e822cc 100644 --- a/server_files/views/mon_compte.php +++ b/server_files/views/mon_compte.php @@ -46,8 +46,8 @@ if (!$has_error && (isset($my_account) || isset($new_password))) {
- - J'accepte de recevoir des mails de la part d'Animath (facultatif) : + doReceiveAnimathMails() ? "checked" : "" ?> />
@@ -62,12 +62,12 @@ if (!$has_error && (isset($my_account) || isset($new_password))) {