1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2025-01-06 00:22:21 +00:00

Sans utilisateur, le premier inscrit est administrateur

This commit is contained in:
galaxyoyo 2019-09-24 11:00:44 +02:00
parent 6f9fddd7a8
commit e878854861
3 changed files with 14 additions and 4 deletions

View File

@ -45,10 +45,11 @@ class Config
global $DB;
$DB->exec("SET GLOBAL time_zone = 'Europe/Paris';");
$DB->exec("INSERT IGNORE INTO `config` VALUES ('inscription_date', CURRENT_TIMESTAMP), ('start_phase1_date', CURRENT_TIMESTAMP), ('end_phase1_date', CURRENT_TIMESTAMP),
('start_phase2_date', CURRENT_TIMESTAMP), ('end_phase2_date', CURRENT_TIMESTAMP),
('start_phase3_date', CURRENT_TIMESTAMP), ('end_phase3_date', CURRENT_TIMESTAMP),
('start_phase4_date', CURRENT_TIMESTAMP), ('end_phase4_date', CURRENT_TIMESTAMP);");
$DB->exec("INSERT IGNORE INTO `config` VALUES ('inscription_date', CURRENT_TIMESTAMP + INTERVAL 2 DAY),
('start_phase1_date', CURRENT_TIMESTAMP + INTERVAL 1 DAY), ('end_phase1_date', CURRENT_TIMESTAMP + INTERVAL 3 DAY),
('start_phase2_date', CURRENT_TIMESTAMP + INTERVAL 4 DAY), ('end_phase2_date', CURRENT_TIMESTAMP + INTERVAL 5 DAY),
('start_phase3_date', CURRENT_TIMESTAMP + INTERVAL 6 DAY), ('end_phase3_date', CURRENT_TIMESTAMP + INTERVAL 7 DAY),
('start_phase4_date', CURRENT_TIMESTAMP + INTERVAL 8 DAY), ('end_phase4_date', CURRENT_TIMESTAMP + INTERVAL 9 DAY);");
}
public function loadConfigValues()

View File

@ -48,6 +48,7 @@ class NewUser
ensure($this->surname != "", "Le nom de famille est obligatoire.");
ensure($this->first_name != "", "Le prénom est obligatoire.");
$this->role = Role::fromName(strtoupper($this->role));
ensure($this->role == Role::PARTICIPANT || $this->role == Role::ENCADRANT, "Vous devez être participant ou encadrant.");
if ($this->role == Role::PARTICIPANT)
$this->class = SchoolClass::fromName(strtoupper($this->class));
@ -59,6 +60,9 @@ class NewUser
{
global $DB, $YEAR;
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->execute([$this->email, password_hash($this->password, PASSWORD_BCRYPT), $this->confirm_email_token, $this->surname, $this->first_name,

View File

@ -9,6 +9,11 @@ function loadUserValues()
if (isset($_SESSION["user_id"])) {
$user = $_SESSION["user"] = User::fromId($_SESSION["user_id"]);
if ($user == null) {
unset($_SESSION["user_id"]);
return;
}
$_SESSION["role"] = $user->getRole();
if ($user->getTeamId() !== null)