1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-11-30 06:13:01 +00:00
plateforme-tfjm2/server_files/controllers/mon_compte.php

128 lines
4.0 KiB
PHP
Raw Normal View History

2019-09-06 11:48:50 +00:00
<?php
2019-09-07 15:26:30 +00:00
if (!isset($_SESSION["user_id"]))
require_once "server_files/403.php";
/** @var User $user */
$user = $_SESSION["user"];
2019-09-06 11:48:50 +00:00
if (isset($_POST["submitted"])) {
$error_message = updateAccount();
} elseif (isset($_POST["submitted_password"])) {
$error_message = updatePassword();
}
function updateAccount()
{
global $URL_BASE, $MAIL_ADDRESS, $user;
2019-09-06 11:48:50 +00:00
$surname = htmlspecialchars($_POST["surname"]);
if (isset($surname) && $surname != "")
$user->setSurname($surname);
2019-09-06 11:48:50 +00:00
$first_name = htmlspecialchars($_POST["firstname"]);
if (isset($first_name) && $first_name != "")
$user->setFirstName($first_name);
2019-09-06 11:48:50 +00:00
$birth_date = htmlspecialchars($_POST["birth_date"]);
if (isset($birth_date) && $birth_date != "")
$user->setBirthDate($birth_date);
2019-09-06 11:48:50 +00:00
if (isset($_POST["gender"])) {
$gender = htmlspecialchars($_POST["gender"]);
if (isset($gender) && ($gender == "M" || $gender == "F"))
$user->setGender($gender);
2019-09-06 11:48:50 +00:00
}
$address = htmlspecialchars($_POST["address"]);
if (isset($address) && $address != "")
$user->setAddress($address);
2019-09-06 11:48:50 +00:00
$postal_code = htmlspecialchars($_POST["postal_code"]);
if (isset($postal_code) && $postal_code != "")
$user->setPostalCode($postal_code);
2019-09-06 11:48:50 +00:00
$city = htmlspecialchars($_POST["city"]);
if (isset($city) && $city != "")
$user->setCity($city);
2019-09-06 11:48:50 +00:00
$country = htmlspecialchars($_POST["country"]);
if (isset($country) && $country != "")
$user->setCountry($country);
2019-09-06 11:48:50 +00:00
$phone_number = htmlspecialchars($_POST["phone_number"]);
if (isset($phone_number) && $phone_number != "")
$user->setPhoneNumber($phone_number);
2019-09-06 11:48:50 +00:00
if (isset($_POST["school"])) {
$school = htmlspecialchars($_POST["school"]);
if (isset($school) && $school != "")
$user->setSchool($school);
2019-09-06 11:48:50 +00:00
}
if (isset($_POST["class"])) {
$class = htmlspecialchars($_POST["class"]);
if (isset($class) && ($class == "terminale" || $class == "premiere" || $class == "seconde"))
$user->setClass($class);
2019-09-06 11:48:50 +00:00
}
if (isset($_POST["responsible_name"])) {
$responsible_name = htmlspecialchars($_POST["responsible_name"]);
if (isset($responsible_name) && $responsible_name != "")
$user->setResponsibleName($responsible_name);
2019-09-06 11:48:50 +00:00
}
if (isset($_POST["responsible_phone"])) {
$responsible_phone = htmlspecialchars($_POST["responsible_phone"]);
if (isset($responsible_phone) && $responsible_phone != "")
$user->setResponsiblePhone($responsible_phone);
2019-09-06 11:48:50 +00:00
}
if (isset($_POST["responsible_email"])) {
$responsible_email = htmlspecialchars($_POST["responsible_email"]);
if (isset($responsible_email) && $responsible_email != "")
$user->setResponsibleEmail($responsible_email);
2019-09-06 11:48:50 +00:00
}
if (isset($_POST["description"])) {
$description = htmlspecialchars($_POST["description"]);
if (isset($description) && $description != "")
$user->setDescription($description);
2019-09-06 11:48:50 +00:00
}
$email = htmlspecialchars($_POST["email"]);
if (isset($email) && $email != "" && filter_var($email, FILTER_VALIDATE_EMAIL)) {
$confirm_email_token = uniqid();
$user->setConfirmEmailToken($confirm_email_token);
2019-09-06 11:48:50 +00:00
$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";
2019-09-06 11:48:50 +00:00
mail($email, "Changement d'adresse mail - TFJM²", $msg, "From: $MAIL_ADDRESS\r\n");
}
return false;
}
function updatePassword()
{
global $user;
2019-09-06 11:48:50 +00:00
$old = htmlspecialchars($_POST["old_password"]);
$new = htmlspecialchars($_POST["new_password"]);
$confirm = htmlspecialchars($_POST["confirm_password"]);
if (!$user->checkPassword($old))
2019-09-06 11:48:50 +00:00
return "L'ancien mot de passe est incorrect.";
if (strlen($new) < 8)
return "Le mot de passe doit comporter au moins 8 caractères.";
if ($new != $confirm)
return "Les deux mots de passe sont différents.";
$user->setPassword($new);
2019-09-06 11:48:50 +00:00
return false;
}
require_once "server_files/views/mon_compte.php";