mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-25 06:22:22 +00:00
Début de gestion des mails et quelques modifications
This commit is contained in:
parent
7266fe8e24
commit
e5e197dd38
@ -8,6 +8,8 @@ require_once "server_files/classes/Team.php";
|
||||
require_once "server_files/classes/Tournament.php";
|
||||
require_once "server_files/classes/User.php";
|
||||
require_once "server_files/classes/ValidationStatus.php";
|
||||
require_once "server_files/services/mail.php";
|
||||
require_once "server_files/utils.php";
|
||||
require_once "server_files/model.php";
|
||||
|
||||
loadUserValues();
|
||||
|
@ -6,7 +6,9 @@
|
||||
$YEAR = $_ENV["TFJM_YEAR"];
|
||||
$URL_BASE = $_ENV["TFJM_URL_BASE"];
|
||||
$LOCAL_PATH = $_ENV["TFJM_LOCAL_PATH"];
|
||||
$MAIL_ADDRESS = $_ENV["TFJM_MAIL_ADDRESS"];
|
||||
$MAIL_DOMAIN = $_ENV["TFJM_MAIL_DOMAIN"];
|
||||
// TODO Remove
|
||||
$MAIL_ADDRESS = "contact@" . $MAIL_DOMAIN;
|
||||
|
||||
/**
|
||||
* DB infos
|
||||
|
@ -17,26 +17,26 @@ if (isset($_POST["submitted"])) {
|
||||
|
||||
class NewUser
|
||||
{
|
||||
public $email = null;
|
||||
public $first_name = null;
|
||||
public $surname = null;
|
||||
public $birth_date = null;
|
||||
public $gender = null;
|
||||
public $email;
|
||||
public $first_name;
|
||||
public $surname;
|
||||
public $birth_date;
|
||||
public $gender;
|
||||
public $address = "";
|
||||
public $postal_code = null;
|
||||
public $postal_code;
|
||||
public $city = "";
|
||||
public $country = null;
|
||||
public $phone_number = null;
|
||||
public $role = null;
|
||||
public $school = null;
|
||||
public $class = null;
|
||||
public $responsible_name = null;
|
||||
public $responsible_phone = null;
|
||||
public $responsible_email = null;
|
||||
public $description = null;
|
||||
public $confirm_email_token = null;
|
||||
private $password = null;
|
||||
private $confirm_password = null;
|
||||
public $country;
|
||||
public $phone_number;
|
||||
public $role;
|
||||
public $school;
|
||||
public $class;
|
||||
public $responsible_name;
|
||||
public $responsible_phone;
|
||||
public $responsible_email;
|
||||
public $description;
|
||||
public $confirm_email_token;
|
||||
private $password;
|
||||
private $confirm_password;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
@ -46,15 +46,15 @@ class NewUser
|
||||
|
||||
public function makeVerifications()
|
||||
{
|
||||
global $DB, $YEAR;
|
||||
global $YEAR;
|
||||
|
||||
ensure(filter_var($this->email, FILTER_VALIDATE_EMAIL), "L'adresse e-mail entrée est invalide.");
|
||||
ensure(!$DB->query("SELECT `email` FROM `users` WHERE `email` = '" . $this->email . "' AND `year` = '$YEAR';")->fetch(), "Un compte existe déjà avec cette adresse e-mail.");
|
||||
ensure(userExists($this->email), "Un compte existe déjà avec cette adresse e-mail.");
|
||||
ensure(strlen($this->password) >= 8, "Le mot de passe doit comporter au moins 8 caractères.");
|
||||
ensure($this->password == $this->confirm_password, "Les deux mots de passe sont différents.");
|
||||
ensure($this->surname != "", "Le nom de famille est obligatoire.");
|
||||
ensure($this->first_name != "", "Le prénom est obligatoire.");
|
||||
ensure(date_parse_from_format("yyyy-mm-dd", $this->birth_date) !== false, "La date de naissance est invalide.");
|
||||
ensure(dateWellFormed($this->birth_date), "La date de naissance est invalide.");
|
||||
ensure($this->birth_date < $YEAR . "-01-01", "Vous devez être né.");
|
||||
ensure($this->gender == "M" || $this->gender == "F", "Le sexe indiqué est invalide.");
|
||||
ensure(preg_match("#^[0-9]{4}[0-9]?$#", $this->postal_code) && intval($this->postal_code) >= 01000 && intval($this->postal_code) <= 95999, "Le code postal est invalide.");
|
||||
@ -73,13 +73,11 @@ class NewUser
|
||||
}
|
||||
|
||||
$this->confirm_email_token = uniqid();
|
||||
|
||||
throw new AssertionError("erreur");
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
global $DB, $YEAR, $URL_BASE, $MAIL_ADDRESS;
|
||||
global $DB, $YEAR;
|
||||
|
||||
$req = $DB->prepare("INSERT INTO `users`(`email`, `pwd_hash`, `confirm_email`, `surname`, `first_name`, `birth_date`, `gender`,
|
||||
`address`, `postal_code`, `city`, `country`, `phone_number`, `school`, `class`, `role`, `description`, `year`)
|
||||
@ -87,10 +85,7 @@ class NewUser
|
||||
$req->execute([$this->email, password_hash($this->password, PASSWORD_BCRYPT), $this->confirm_email_token, $this->surname, $this->first_name, $this->birth_date, $this->gender, $this->address,
|
||||
$this->postal_code, $this->city, $this->country, $this->phone_number, $this->school, SchoolClass::getName($this->class), Role::getName($this->role), $this->description, $YEAR]);
|
||||
|
||||
// TODO Mieux gérer l'envoi des mails avec une classe à part
|
||||
|
||||
$msg = "Merci pour votre inscription au TFJM² $YEAR ! Veuillez désormais confirmer votre adresse mail en cliquant ici : $URL_BASE/confirmer_mail/" . $this->confirm_email_token;
|
||||
mail($this->email, "Inscription au TFJM² $YEAR", $msg, "From: $MAIL_ADDRESS\r\n");
|
||||
sendRegisterMail($this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,13 +44,6 @@ function loadUserValues() {
|
||||
}
|
||||
}
|
||||
|
||||
function echoDate($date = NULL, $with_time = false) {
|
||||
if ($date == NULL)
|
||||
$date = date("yyyy-mm-dd");
|
||||
|
||||
return strftime("%d %B %G" . ($with_time ? " %H:%M" : ""), strtotime($date));
|
||||
}
|
||||
|
||||
function quitTeam() {
|
||||
global $DB, $URL_BASE;
|
||||
|
||||
@ -96,7 +89,10 @@ function quitTeam() {
|
||||
unset($_SESSION["team"]);
|
||||
}
|
||||
|
||||
function ensure($bool, $error_msg = "") {
|
||||
if (!$bool)
|
||||
throw new AssertionError($error_msg);
|
||||
function userExists($email) {
|
||||
global $DB, $YEAR;
|
||||
|
||||
$req = $DB->prepare("SELECT `email` FROM `users` WHERE `email` = ? AND `year` = '$YEAR';");
|
||||
$req->execute([$email]);
|
||||
return !$req->fetch();
|
||||
}
|
30
server_files/services/mail.php
Normal file
30
server_files/services/mail.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
function sendMail($email, $subject, $content, $from = "contact")
|
||||
{
|
||||
global $MAIL_DOMAIN, $URL_BASE, $YEAR;
|
||||
|
||||
$content = preg_replace("#{URL_BASE}#", $URL_BASE, $content);
|
||||
$content = preg_replace("#{YEAR}#", $YEAR, $content);
|
||||
|
||||
$headers = "From: " . $from . "@" . $MAIL_DOMAIN . "\r\n";
|
||||
$headers .= "Reply-To: contact@" . $MAIL_DOMAIN . "\r\n";
|
||||
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
|
||||
|
||||
mail($email, $subject, $content, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param NewUser
|
||||
*/
|
||||
function sendRegisterMail($new_user)
|
||||
{
|
||||
global $LOCAL_PATH, $YEAR;
|
||||
|
||||
$content = file_get_contents("$LOCAL_PATH/server_files/services/mail_templates/register.html");
|
||||
$content = preg_replace("#{FIRST_NAME}#", $new_user->first_name, $content);
|
||||
$content = preg_replace("#{SURNAME}#", $new_user->surname, $content);
|
||||
$content = preg_replace("#{TOKEN}#", $new_user->confirm_email_token, $content);
|
||||
|
||||
sendMail($new_user->email, "Inscription au TFJM² $YEAR", $content);
|
||||
}
|
15
server_files/services/mail_templates/register.html
Normal file
15
server_files/services/mail_templates/register.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Inscription au TFJM² {YEAR}</title>
|
||||
</head>
|
||||
<body>
|
||||
Bonjour {FIRST_NAME} {SURNAME},<br />
|
||||
<br />
|
||||
Vous venez de vous inscrire au TFJM<sup>2</sup> {YEAR} et nous vous en remercions.<br />
|
||||
Pour valider votre adresse e-mail, veuillez cliquer sur le lien : <a href="{URL_BASE}/confirmer_mail/{TOKEN}">{URL_BASE}/confirmer_mail/{TOKEN}</a><br />
|
||||
<br />
|
||||
Le comité national d'organisation du TFJM<sup>2</sup>
|
||||
</body>
|
||||
</html>
|
17
server_files/utils.php
Normal file
17
server_files/utils.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
function ensure($bool, $error_msg = "") {
|
||||
if (!$bool)
|
||||
throw new AssertionError($error_msg);
|
||||
}
|
||||
|
||||
function formatDate($date = NULL, $with_time = false) {
|
||||
if ($date == NULL)
|
||||
$date = date("yyyy-mm-dd");
|
||||
|
||||
return strftime("%d %B %G" . ($with_time ? " %H:%M" : ""), strtotime($date));
|
||||
}
|
||||
|
||||
function dateWellFormed($date, $format = "yyyy-mm-dd") {
|
||||
return date_parse_from_format($format, $date) !== false;
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
<?php if ($user->getRole() == Role::PARTICIPANT || $user->getRole() == Role::ENCADRANT) { ?>
|
||||
Équipe : <?= $team === null ? "Pas d'équipe" : "<a href=\"$URL_BASE/equipe/" . $team->getTrigram() . "\">" . $team->getName() . " (" . $team->getTrigram() . ")</a>" ?><br />
|
||||
<?php } ?>
|
||||
Date de naissance : <?= echoDate($user->getBirthDate()) ?><br />
|
||||
Date de naissance : <?= formatDate($user->getBirthDate()) ?><br />
|
||||
Sexe : <?= $user->getGender() == "M" ? "Masculin" : "Féminin" ?><br />
|
||||
Adresse : <?= $user->getAddress() . ", " . $user->getPostalCode() . " " . $user->getCity() . ($user->getCountry() == "France" ? "" : ", " . $user->getCountry()) ?><br />
|
||||
Adresse e-mail : <a href="mailto:<?= $user->getEmail() ?>"><?= $user->getEmail() ?></a><br />
|
||||
|
@ -42,7 +42,7 @@ if (isset($error_message) && $error_message === FALSE) {
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="birth_date">Date de naissance :</label></td>
|
||||
<td><?= echoDate($user->getBirthDate()) ?></td>
|
||||
<td><?= formatDate($user->getBirthDate()) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><input style="width: 100%" type="date" id="birth_date" name="birth_date"/></td>
|
||||
|
@ -21,10 +21,10 @@ echo substr($s, 0, -2);
|
||||
<strong>Nombre d'équipes maximal :</strong> <?= $tournament->getSize() ?><br />
|
||||
<strong>Lieu :</strong> <?= $tournament->getPlace() ?><br />
|
||||
<strong>Prix par partipant :</strong> <?= $tournament->getPrice() == 0 ? "Gratuit" : $tournament->getPrice() . " €" ?><br />
|
||||
<strong>Dates :</strong> Du <?= echoDate($tournament->getStartDate()) ?> au <?= echoDate($tournament->getEndDate()) ?><br />
|
||||
<strong>Clôture des inscriptions :</strong> <?= echoDate($tournament->getInscriptionDate(), true) ?><br />
|
||||
<strong>Date limite d'envoi des solutions :</strong> <?= echoDate($tournament->getSolutionsDate(), true) ?><br />
|
||||
<strong>Date limite d'envoi des notes de synthèse :</strong> <?= echoDate($tournament->getSynthesesDate(), true) ?><br />
|
||||
<strong>Dates :</strong> Du <?= formatDate($tournament->getStartDate()) ?> au <?= formatDate($tournament->getEndDate()) ?><br />
|
||||
<strong>Clôture des inscriptions :</strong> <?= formatDate($tournament->getInscriptionDate(), true) ?><br />
|
||||
<strong>Date limite d'envoi des solutions :</strong> <?= formatDate($tournament->getSolutionsDate(), true) ?><br />
|
||||
<strong>Date limite d'envoi des notes de synthèse :</strong> <?= formatDate($tournament->getSynthesesDate(), true) ?><br />
|
||||
<strong>Description :</strong> <?= $tournament->getDescription() ?><br />
|
||||
<?php
|
||||
if ($tournament->isFinal())
|
||||
@ -73,7 +73,7 @@ if ($tournament->isFinal())
|
||||
?>
|
||||
</td>
|
||||
<td style="border: 1px solid black; text-align: center"><?= $team_data["trigram"] ?></td>
|
||||
<td style="border: 1px solid black; text-align: center"><?= echoDate($team_data["inscription_date"]) ?></td>
|
||||
<td style="border: 1px solid black; text-align: center"><?= formatDate($team_data["inscription_date"]) ?></td>
|
||||
<td style="border: 1px solid black; text-align: center">
|
||||
<?php
|
||||
switch (ValidationStatus::fromName($team_data["validation_status"])) {
|
||||
|
@ -18,9 +18,9 @@
|
||||
?>
|
||||
<tr style="border: 1px solid black">
|
||||
<td style="border: 1px solid black; text-align: center"><a href="<?= $URL_BASE ?>/tournoi/<?= $data["name"] ?>"><?= $data["name"] ?></a></td>
|
||||
<td style="border: 1px solid black; text-align: center">Du <?= echoDate($data["date_start"]) ?> au <?= echoDate($data["date_end"]) ?></td>
|
||||
<td style="border: 1px solid black; text-align: center"><?= echoDate($data["date_inscription"]) ?></td>
|
||||
<td style="border: 1px solid black; text-align: center"><?= echoDate($data["date_solutions"]) ?></td>
|
||||
<td style="border: 1px solid black; text-align: center">Du <?= formatDate($data["date_start"]) ?> au <?= formatDate($data["date_end"]) ?></td>
|
||||
<td style="border: 1px solid black; text-align: center"><?= formatDate($data["date_inscription"]) ?></td>
|
||||
<td style="border: 1px solid black; text-align: center"><?= formatDate($data["date_solutions"]) ?></td>
|
||||
<td style="border: 1px solid black; text-align: center"><?= $data["size"] ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
@ -28,9 +28,9 @@
|
||||
?>
|
||||
<tr style="border: 1px solid black">
|
||||
<td style="border: 1px solid black; text-align: center"><a href="<?= $URL_BASE ?>/tournoi/<?= $final_data["name"] ?>"><?= $final_data["name"] ?></a></td>
|
||||
<td colspan="2" style="border: 1px solid black; text-align: center">Du <?= echoDate($final_data["date_start"]) ?> au <?= echoDate($final_data["date_end"]) ?></td>
|
||||
<!-- <td style="border: 1px solid black; text-align: center"><?= echoDate($final_data["date_inscription"]) ?></td> -->
|
||||
<td style="border: 1px solid black; text-align: center"><?= echoDate($final_data["date_solutions"]) ?></td>
|
||||
<td colspan="2" style="border: 1px solid black; text-align: center">Du <?= formatDate($final_data["date_start"]) ?> au <?= formatDate($final_data["date_end"]) ?></td>
|
||||
<!-- <td style="border: 1px solid black; text-align: center"><?= formatDate($final_data["date_inscription"]) ?></td> -->
|
||||
<td style="border: 1px solid black; text-align: center"><?= formatDate($final_data["date_solutions"]) ?></td>
|
||||
<td style="border: 1px solid black; text-align: center"><?= $final_data["size"] ?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
Loading…
Reference in New Issue
Block a user