1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-25 07:40:32 +02:00

Optimisation de l'envoi de mails

This commit is contained in:
Yohann
2019-09-08 12:45:48 +02:00
committed by galaxyoyo
parent bd73e82cb0
commit 5771a15a32
16 changed files with 241 additions and 116 deletions

View File

@ -59,7 +59,7 @@ class NewTeam {
$_SESSION["team"] = Team::fromTrigram($this->trigram);
$_SESSION["user"]->setTeamId($_SESSION["team"]->getId());
sendAddTeamMail($_SESSION["user"], $_SESSION["team"], $this->tournament);
Mailer::sendAddTeamMail($_SESSION["user"], $_SESSION["team"], $this->tournament);
}
}

View File

@ -53,7 +53,7 @@ class NewOrganizer {
VALUES (?, ?, ?, ?, ?, ?);");
$req->execute([$this->email, password_hash($this->password, PASSWORD_BCRYPT), $this->surname, $this->first_name, $this->admin ? "ADMIN" : "ORGANIZER", $YEAR]);
sendAddOrganizerMail($this);
Mailer::sendAddOrganizerMail($this);
}
}

View File

@ -93,10 +93,11 @@ class NewTournament {
$this->tournament = Tournament::fromName($this->name);
/** @var User $organizer */
foreach ($this->organizers as $organizer) {
$req = $DB->prepare("INSERT INTO `organizers`(`organizer`, `tournament`) VALUES(?, ?);");
$req->execute([$organizer->getId(), $this->tournament->getId()]);
sendAddOrganizerForTournamentMail($organizer, $this->tournament);
Mailer::sendAddOrganizerForTournamentMail($organizer, $this->tournament);
}
}
}

View File

@ -1,5 +1,7 @@
<?php
// TODO Arranger tout ça
if (isset($_POST["submitted"]) && !isset($_SESSION["user_id"])) {
$error_message = login();
}
@ -9,7 +11,7 @@ if (isset($_POST["forgotten_password"]) && !isset($_SESSION["user_id"])) {
}
if (isset($_GET["reset_password"]) && isset($_GET["token"]) && !isset($_SESSION["user_id"])) {
$reset_data = $DB->query("SELECT `id`, `email` FROM `users` WHERE `forgotten_password` = '" . htmlspecialchars($_GET["token"]) . "';")->fetch();
$reset_data = $DB->query("SELECT `id` FROM `users` WHERE `forgotten_password` = '" . htmlspecialchars($_GET["token"]) . "';")->fetch();
if ($reset_data === FALSE) {
header("Location: $URL_BASE/connexion");
exit();
@ -34,7 +36,7 @@ function login() {
$password = htmlspecialchars($_POST["password"]);
$user = User::fromEmail($email);
if ($user === FALSE)
if ($user === null)
return "Le compte n'existe pas.";
if ($user->getConfirmEmailToken() !== NULL) {
@ -52,8 +54,6 @@ function login() {
}
function recuperateAccount() {
global $MAIL_ADDRESS, $URL_BASE;
$email = htmlspecialchars($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
@ -66,22 +66,16 @@ function recuperateAccount() {
$token = uniqid();
$user->setForgottenPasswordToken($token);
$msg = "Bonjour,\r\n\r\n"
. "Vous avez indiqué avoir oublié votre mot de passe. Veuillez cliquer ici pour le réinitialiser : $URL_BASE/connexion/reinitialiser_mdp/$token\r\n\r\n"
. "Si vous n'êtes pas à l'origine de cette manipulation, vous pouvez ignorer ce message.\r\n\r\n"
. "Cordialement,\r\n\r\n"
. "Le comité national d'organisation du TFJM².";
mail("$email", "Mot de passe oublié - TFJM²", $msg, "From: $MAIL_ADDRESS\r\n");
Mailer::sendForgottenPasswordProcedureMail($user);
return false;
}
function resetPassword() {
global $DB, $MAIL_ADDRESS, $reset_data;
global $reset_data;
$id = $reset_data["id"];
$email = $reset_data["email"];
$password = htmlspecialchars($_POST["password"]);
$confirm = htmlspecialchars($_POST["confirm_password"]);
@ -91,20 +85,17 @@ function resetPassword() {
if ($password != $confirm)
return "Les deux mots de passe sont différents.";
$hash = password_hash($password, PASSWORD_BCRYPT);
$user = User::fromId($id);
$user->setForgottenPasswordToken(null);
$user->setPassword($password);
$DB->prepare("UPDATE `users` SET `pwd_hash` = ?, `forgotten_password` = NULL WHERE `id` = ?;")->execute([$hash, $id]);
$msg = "Bonjour,\r\n\r\nNous vous informons que votre mot de passe vient d'être modifié. "
. "Si vous n'êtes pas à l'origine de cette manipulation, veuillez immédiatement vérifier vos accès à votre boîte mail et changer votre mot de passe sur la plateforme d'inscription.\r\n\r\n"
. "Cordialement,\r\n\r\nLe comité national d'organisation du TFJM²";
mail($email, "Mot de passe modifié TFJM²", $msg, "From: $MAIL_ADDRESS\r\n");
Mailer::sendChangePasswordMail($user);
return false;
}
function sendConfirmEmail() {
global $URL_BASE, $MAIL_ADDRESS, $YEAR;
global $URL_BASE;
$email = htmlspecialchars($_SESSION["confirm_email"]);
@ -120,12 +111,8 @@ function sendConfirmEmail() {
header("Location: $URL_BASE/connexion");
exit();
}
$confirm_email_uid = $user->getConfirmEmailToken();
$msg = "Bonjour,\r\n\r\nPour confirmer votre adresse mail, cliquez ici : $URL_BASE/confirmer_mail/$confirm_email_uid\r\n\r\n"
. "Cordialement,\r\n\r\nLe comité national d'organisation du TFJM²";
mail($email, "Confirmation d'adresse mail TFJM² $YEAR", $msg, "From: $MAIL_ADDRESS\r\n");
Mailer::sendConfirmEmail($user);
return false;
}

View File

@ -86,7 +86,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]);
sendRegisterMail($this);
Mailer::sendRegisterMail($this);
}
}

View File

@ -14,7 +14,7 @@ if (isset($_POST["submitted"])) {
function updateAccount()
{
global $URL_BASE, $MAIL_ADDRESS, $user;
global $user;
$surname = htmlspecialchars($_POST["surname"]);
if (isset($surname) && $surname != "")
@ -93,10 +93,10 @@ function updateAccount()
$email = htmlspecialchars($_POST["email"]);
if (isset($email) && $email != "" && filter_var($email, FILTER_VALIDATE_EMAIL)) {
$confirm_email_token = uniqid();
$user->setEmail($email);
$user->setConfirmEmailToken($confirm_email_token);
$msg = "Vous venez de changer votre adresse mail. Veuillez désormais confirmer votre adresse mail en cliquant ici : $URL_BASE/confirmer_mail/$confirm_email_token";
mail($email, "Changement d'adresse mail - TFJM²", $msg, "From: $MAIL_ADDRESS\r\n");
Mailer::sendChangeEmailAddressMail($user);
}
return false;

View File

@ -8,7 +8,7 @@ if (isset($_POST["submitted"])) {
}
function joinTeam() {
global $YEAR, $MAIL_ADDRESS, $access_code;
global $access_code;
$access_code = htmlspecialchars($_POST["access_code"]);
@ -42,10 +42,7 @@ function joinTeam() {
$_SESSION["team"] = $team;
$tournament = $_SESSION["tournament"] = Tournament::fromId($team->getTournamentId());
$msg = "Bonjour " . $user->getFirstName() . " " . $user->getSurname() . ",\r\n\r\n";
$msg .= "Vous venez de rejoindre l'équipe « " . $team->getName() . " » (" . $team->getTrigram() . ") pour le TFJM² de " . $tournament->getId() . " et nous vous en remercions.\r\n\r\n";
$msg .= "Cordialement,\r\n\r\nL'organisation du TFJM² $YEAR";
mail($_SESSION["email"], "Équipe rejointe TFJM² $YEAR", $msg, "From: $MAIL_ADDRESS\r\n");
Mailer::sendJoinTeamMail($user, $team, $tournament);
return false;
}