Fichier "Mon compte" & modifications mineures
This commit is contained in:
parent
57d2bb9bec
commit
fac2b29f4a
|
@ -2,30 +2,30 @@
|
||||||
|
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
private $id;
|
public $id;
|
||||||
private $email;
|
public $email;
|
||||||
private $pwd_hash;
|
public $pwd_hash;
|
||||||
private $surname;
|
public $surname;
|
||||||
private $first_name;
|
public $first_name;
|
||||||
private $birth_date;
|
public $birth_date;
|
||||||
private $gender;
|
public $gender;
|
||||||
private $address;
|
public $address;
|
||||||
private $postal_code;
|
public $postal_code;
|
||||||
private $city;
|
public $city;
|
||||||
private $country;
|
public $country;
|
||||||
private $phone_number;
|
public $phone_number;
|
||||||
private $school;
|
public $school;
|
||||||
private $class;
|
public $class;
|
||||||
private $responsible_name;
|
public $responsible_name;
|
||||||
private $responsible_phone;
|
public $responsible_phone;
|
||||||
private $responsible_email;
|
public $responsible_email;
|
||||||
private $description;
|
public $description;
|
||||||
private $role;
|
public $role;
|
||||||
private $team_id;
|
public $team_id;
|
||||||
private $year;
|
public $year;
|
||||||
private $confirm_email;
|
public $confirm_email;
|
||||||
private $forgotten_password;
|
public $forgotten_password;
|
||||||
private $inscription_date;
|
public $inscription_date;
|
||||||
|
|
||||||
private function __construct() {}
|
private function __construct() {}
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ class User
|
||||||
{
|
{
|
||||||
global $DB;
|
global $DB;
|
||||||
$this->school = $school;
|
$this->school = $school;
|
||||||
$DB->prepare("UPDATE `users` SET `school` = ? WHERE `id` = ?;")->execute([$school, $this->getId()]);
|
$DB->prepare("UPDATE `users` SET `school` = ? WHERE `id` = ?;")->execute([SchoolClass::getName($school), $this->getId()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getClass()
|
public function getClass()
|
||||||
|
|
|
@ -7,8 +7,6 @@ $YEAR = $_ENV["TFJM_YEAR"];
|
||||||
$URL_BASE = $_ENV["TFJM_URL_BASE"];
|
$URL_BASE = $_ENV["TFJM_URL_BASE"];
|
||||||
$LOCAL_PATH = $_ENV["TFJM_LOCAL_PATH"];
|
$LOCAL_PATH = $_ENV["TFJM_LOCAL_PATH"];
|
||||||
$MAIL_DOMAIN = $_ENV["TFJM_MAIL_DOMAIN"];
|
$MAIL_DOMAIN = $_ENV["TFJM_MAIL_DOMAIN"];
|
||||||
// TODO Remove
|
|
||||||
$MAIL_ADDRESS = "contact@" . $MAIL_DOMAIN;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DB infos
|
* DB infos
|
||||||
|
|
|
@ -18,7 +18,6 @@ if (isset($_POST["validate"])) {
|
||||||
if (isset($_POST["select"])) {
|
if (isset($_POST["select"])) {
|
||||||
$team->selectForFinal(true);
|
$team->selectForFinal(true);
|
||||||
$team->setValidationStatus(ValidationStatus::NOT_READY);
|
$team->setValidationStatus(ValidationStatus::NOT_READY);
|
||||||
$tournament = Tournament::fromId($team->getTournamentId());
|
|
||||||
$sols = $tournament->getAllSolutions($team->getId());
|
$sols = $tournament->getAllSolutions($team->getId());
|
||||||
/** @var Solution $sol */
|
/** @var Solution $sol */
|
||||||
foreach ($sols as $sol) {
|
foreach ($sols as $sol) {
|
||||||
|
@ -36,9 +35,9 @@ if (isset($_POST["select"])) {
|
||||||
|
|
||||||
if (isset($_POST["download_zip"])) {
|
if (isset($_POST["download_zip"])) {
|
||||||
$final = isset($_POST["final"]);
|
$final = isset($_POST["final"]);
|
||||||
$tournament = $final ? $FINAL : Tournament::fromId($team->getTournamentId());
|
$tournament_dest = $final ? $FINAL : $tournament;
|
||||||
|
|
||||||
$file_name = getZipFile(DocumentType::PARENTAL_CONSENT, $tournament->getId(), $team->getId());
|
$file_name = getZipFile(DocumentType::PARENTAL_CONSENT, $tournament_dest->getId(), $team->getId());
|
||||||
|
|
||||||
header("Content-Type: application/zip");
|
header("Content-Type: application/zip");
|
||||||
header("Content-Disposition: attachment; filename=\"Documents de l'équipe " . $team->getTrigram() . ".zip\"");
|
header("Content-Disposition: attachment; filename=\"Documents de l'équipe " . $team->getTrigram() . ".zip\"");
|
||||||
|
|
|
@ -6,122 +6,147 @@ if (!isset($_SESSION["user_id"]))
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = $_SESSION["user"];
|
$user = $_SESSION["user"];
|
||||||
|
|
||||||
|
$has_error = false;
|
||||||
|
$error_message = null;
|
||||||
|
|
||||||
if (isset($_POST["submitted"])) {
|
if (isset($_POST["submitted"])) {
|
||||||
$error_message = updateAccount();
|
$my_account = new MyAccount($_POST);
|
||||||
} elseif (isset($_POST["submitted_password"])) {
|
try {
|
||||||
$error_message = updatePassword();
|
$my_account->makeVerifications();
|
||||||
|
$my_account->updateAccount();
|
||||||
|
}
|
||||||
|
catch (AssertionError $e) {
|
||||||
|
$has_error = true;
|
||||||
|
$error_message = $e->getMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateAccount()
|
if (isset($_POST["submitted_password"])) {
|
||||||
|
$new_password = new NewPassword($_POST);
|
||||||
|
try {
|
||||||
|
$new_password->makeVerifications();
|
||||||
|
$new_password->updatePassword();
|
||||||
|
}
|
||||||
|
catch (AssertionError $e) {
|
||||||
|
$has_error = true;
|
||||||
|
$error_message = $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyAccount
|
||||||
{
|
{
|
||||||
global $user;
|
public $email;
|
||||||
|
public $surname;
|
||||||
|
public $first_name;
|
||||||
|
public $birth_date;
|
||||||
|
public $gender;
|
||||||
|
public $address;
|
||||||
|
public $postal_code;
|
||||||
|
public $city;
|
||||||
|
public $country;
|
||||||
|
public $phone_number;
|
||||||
|
public $school;
|
||||||
|
public $class;
|
||||||
|
public $responsible_name;
|
||||||
|
public $responsible_phone;
|
||||||
|
public $responsible_email;
|
||||||
|
public $description;
|
||||||
|
private $user;
|
||||||
|
|
||||||
$surname = htmlspecialchars($_POST["surname"]);
|
public function __construct($data)
|
||||||
if (isset($surname) && $surname != "")
|
|
||||||
$user->setSurname($surname);
|
|
||||||
|
|
||||||
$first_name = htmlspecialchars($_POST["firstname"]);
|
|
||||||
if (isset($first_name) && $first_name != "")
|
|
||||||
$user->setFirstName($first_name);
|
|
||||||
|
|
||||||
$birth_date = htmlspecialchars($_POST["birth_date"]);
|
|
||||||
if (isset($birth_date) && $birth_date != "")
|
|
||||||
$user->setBirthDate($birth_date);
|
|
||||||
|
|
||||||
if (isset($_POST["gender"])) {
|
|
||||||
$gender = htmlspecialchars($_POST["gender"]);
|
|
||||||
if (isset($gender) && ($gender == "M" || $gender == "F"))
|
|
||||||
$user->setGender($gender);
|
|
||||||
}
|
|
||||||
|
|
||||||
$address = htmlspecialchars($_POST["address"]);
|
|
||||||
if (isset($address) && $address != "")
|
|
||||||
$user->setAddress($address);
|
|
||||||
|
|
||||||
$postal_code = htmlspecialchars($_POST["postal_code"]);
|
|
||||||
if (isset($postal_code) && $postal_code != "")
|
|
||||||
$user->setPostalCode($postal_code);
|
|
||||||
|
|
||||||
$city = htmlspecialchars($_POST["city"]);
|
|
||||||
if (isset($city) && $city != "")
|
|
||||||
$user->setCity($city);
|
|
||||||
|
|
||||||
$country = htmlspecialchars($_POST["country"]);
|
|
||||||
if (isset($country) && $country != "")
|
|
||||||
$user->setCountry($country);
|
|
||||||
|
|
||||||
$phone_number = htmlspecialchars($_POST["phone_number"]);
|
|
||||||
if (isset($phone_number) && $phone_number != "")
|
|
||||||
$user->setPhoneNumber($phone_number);
|
|
||||||
|
|
||||||
if (isset($_POST["school"])) {
|
|
||||||
$school = htmlspecialchars($_POST["school"]);
|
|
||||||
if (isset($school) && $school != "")
|
|
||||||
$user->setSchool($school);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_POST["class"])) {
|
|
||||||
$class = htmlspecialchars($_POST["class"]);
|
|
||||||
if (isset($class) && ($class == "terminale" || $class == "premiere" || $class == "seconde"))
|
|
||||||
$user->setClass($class);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_POST["responsible_name"])) {
|
|
||||||
$responsible_name = htmlspecialchars($_POST["responsible_name"]);
|
|
||||||
if (isset($responsible_name) && $responsible_name != "")
|
|
||||||
$user->setResponsibleName($responsible_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_POST["responsible_phone"])) {
|
|
||||||
$responsible_phone = htmlspecialchars($_POST["responsible_phone"]);
|
|
||||||
if (isset($responsible_phone) && $responsible_phone != "")
|
|
||||||
$user->setResponsiblePhone($responsible_phone);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_POST["responsible_email"])) {
|
|
||||||
$responsible_email = htmlspecialchars($_POST["responsible_email"]);
|
|
||||||
if (isset($responsible_email) && $responsible_email != "")
|
|
||||||
$user->setResponsibleEmail($responsible_email);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_POST["description"])) {
|
|
||||||
$description = htmlspecialchars($_POST["description"]);
|
|
||||||
if (isset($description) && $description != "")
|
|
||||||
$user->setDescription($description);
|
|
||||||
}
|
|
||||||
|
|
||||||
$email = htmlspecialchars($_POST["email"]);
|
|
||||||
if (isset($email) && $email != "" && filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
||||||
$confirm_email_token = genRandomPhrase(64);
|
|
||||||
$user->setEmail($email);
|
|
||||||
$user->setConfirmEmailToken($confirm_email_token);
|
|
||||||
|
|
||||||
Mailer::sendChangeEmailAddressMail($user);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function updatePassword()
|
|
||||||
{
|
{
|
||||||
global $user;
|
foreach ($data as $key => $value)
|
||||||
|
$this->$key = htmlspecialchars($value);
|
||||||
|
|
||||||
$old = htmlspecialchars($_POST["old_password"]);
|
$this->user = $_SESSION["user"];
|
||||||
$new = htmlspecialchars($_POST["new_password"]);
|
|
||||||
$confirm = htmlspecialchars($_POST["confirm_password"]);
|
|
||||||
|
|
||||||
if (!$user->checkPassword($old))
|
$keys = ["email", "surname", "first_name", "birth_date", "gender", "address", "postal_code", "city", "country", "phone_number",
|
||||||
return "L'ancien mot de passe est incorrect.";
|
"school", "class", "responsible_name", "responsible_phone", "responsible_email", "description"];
|
||||||
|
|
||||||
if (strlen($new) < 8)
|
if ($this->user->getRole() == Role::PARTICIPANT)
|
||||||
return "Le mot de passe doit comporter au moins 8 caractères.";
|
$this->class = SchoolClass::fromName($this->class);
|
||||||
|
|
||||||
if ($new != $confirm)
|
foreach ($keys as $key)
|
||||||
return "Les deux mots de passe sont différents.";
|
$this->$key = $this->$key != null && $this->$key != "" ? $this->$key : $this->user->$key;
|
||||||
|
}
|
||||||
|
|
||||||
$user->setPassword($new);
|
public function makeVerifications()
|
||||||
|
{
|
||||||
|
global $YEAR;
|
||||||
|
|
||||||
return false;
|
ensure(filter_var($this->email, FILTER_VALIDATE_EMAIL), "L'adresse e-mail entrée est invalide.");
|
||||||
|
$this->email = strtolower($this->email);
|
||||||
|
ensure($this->email == $this->user->getEmail() || !userExists($this->email), "Un compte existe déjà avec cette adresse e-mail.");
|
||||||
|
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.");
|
||||||
|
ensure(strlen($this->phone_number) >= 10, "Le numéro de téléphone est invalide.");
|
||||||
|
|
||||||
|
if ($this->user->getRole() == Role::PARTICIPANT) {
|
||||||
|
if ($this->birth_date > strval($YEAR - 18) . "04-01") {
|
||||||
|
ensure($this->responsible_name != "", "Veuillez spécifier un responsable légal.");
|
||||||
|
ensure(strlen($this->responsible_phone) >= 10, "Veuillez rentrer le numéro de téléphone de votre responsable légal.");
|
||||||
|
ensure(filter_var($this->responsible_email, FILTER_VALIDATE_EMAIL), "Veuillez spécifier un responsable légal.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateAccount()
|
||||||
|
{
|
||||||
|
$this->user->setSurname($this->surname);
|
||||||
|
$this->user->setFirstName($this->first_name);
|
||||||
|
$this->user->setBirthDate($this->birth_date);
|
||||||
|
$this->user->setGender($this->gender);
|
||||||
|
$this->user->setAddress($this->address);
|
||||||
|
$this->user->setPostalCode($this->postal_code);
|
||||||
|
$this->user->setCity($this->city);
|
||||||
|
$this->user->setCountry($this->country);
|
||||||
|
$this->user->setPhoneNumber($this->phone_number);
|
||||||
|
$this->user->setSchool($this->school);
|
||||||
|
$this->user->setClass($this->class);
|
||||||
|
$this->user->setResponsibleName($this->responsible_name);
|
||||||
|
$this->user->setResponsiblePhone($this->responsible_phone);
|
||||||
|
$this->user->setResponsibleEmail($this->responsible_email);
|
||||||
|
$this->user->setDescription($this->description);
|
||||||
|
|
||||||
|
if ($this->email != $this->user->getEmail()) {
|
||||||
|
$this->user->setEmail($this->email);
|
||||||
|
$this->user->setConfirmEmailToken(genRandomPhrase(64));
|
||||||
|
|
||||||
|
Mailer::sendChangeEmailAddressMail($this->user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class NewPassword
|
||||||
|
{
|
||||||
|
private $user;
|
||||||
|
private $old_password;
|
||||||
|
private $new_password;
|
||||||
|
private $confirm_password;
|
||||||
|
|
||||||
|
public function __construct($data)
|
||||||
|
{
|
||||||
|
foreach ($data as $key => $value)
|
||||||
|
$this->$key = htmlspecialchars($value);
|
||||||
|
|
||||||
|
$this->user = $_SESSION["user"];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function makeVerifications()
|
||||||
|
{
|
||||||
|
ensure($this->user->checkPassword($this->old_password), "L'ancien mot de passe est incorrect.");
|
||||||
|
ensure(strlen($this->new_password) >= 8, "Le mot de passe doit comporter au moins 8 caractères.");
|
||||||
|
ensure($this->new_password == $this->confirm_password, "Les deux mots de passe sont différents.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatePassword()
|
||||||
|
{
|
||||||
|
$this->user->setPassword($this->new_password);
|
||||||
|
|
||||||
|
Mailer::sendChangePasswordMail($this->user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once "server_files/views/mon_compte.php";
|
require_once "server_files/views/mon_compte.php";
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
require_once "header.php";
|
require_once "header.php";
|
||||||
|
|
||||||
if (isset($error_message) && $error_message)
|
if ($has_error)
|
||||||
echo "<h2>Erreur : " . $error_message . "</h2>";
|
echo "<h2>Erreur : " . $error_message . "</h2>";
|
||||||
?>
|
|
||||||
|
|
||||||
<?php
|
elseif (isset($my_account) || isset($new_password)) {
|
||||||
if (isset($error_message) && $error_message === FALSE) {
|
|
||||||
?>
|
?>
|
||||||
<h2>Votre compte a bien été mis à jour !</h2>
|
<h2>Votre compte a bien été mis à jour !</h2>
|
||||||
<?php
|
<?php
|
||||||
if (isset($email) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
if (isset($my_account) && $user->getEmail() != $my_account->email) {
|
||||||
echo "Votre adresse mail a bien été changée. Veuillez vérifier votre boîte mail pour valider votre nouvelle adresse, vous en aurez besoin pour vous reconnecter.";
|
echo "Votre adresse mail a bien été changée. Veuillez vérifier votre boîte mail pour valider votre nouvelle adresse, vous en aurez besoin pour vous reconnecter.";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue