mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-01-07 13:02:21 +00:00
Sans utilisateur, le premier inscrit est administrateur
This commit is contained in:
parent
6f9fddd7a8
commit
e878854861
@ -45,10 +45,11 @@ class Config
|
|||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$DB->exec("SET GLOBAL time_zone = 'Europe/Paris';");
|
$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),
|
$DB->exec("INSERT IGNORE INTO `config` VALUES ('inscription_date', CURRENT_TIMESTAMP + INTERVAL 2 DAY),
|
||||||
('start_phase2_date', CURRENT_TIMESTAMP), ('end_phase2_date', CURRENT_TIMESTAMP),
|
('start_phase1_date', CURRENT_TIMESTAMP + INTERVAL 1 DAY), ('end_phase1_date', CURRENT_TIMESTAMP + INTERVAL 3 DAY),
|
||||||
('start_phase3_date', CURRENT_TIMESTAMP), ('end_phase3_date', CURRENT_TIMESTAMP),
|
('start_phase2_date', CURRENT_TIMESTAMP + INTERVAL 4 DAY), ('end_phase2_date', CURRENT_TIMESTAMP + INTERVAL 5 DAY),
|
||||||
('start_phase4_date', CURRENT_TIMESTAMP), ('end_phase4_date', CURRENT_TIMESTAMP);");
|
('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()
|
public function loadConfigValues()
|
||||||
|
@ -48,6 +48,7 @@ class NewUser
|
|||||||
ensure($this->surname != "", "Le nom de famille est obligatoire.");
|
ensure($this->surname != "", "Le nom de famille est obligatoire.");
|
||||||
ensure($this->first_name != "", "Le prénom est obligatoire.");
|
ensure($this->first_name != "", "Le prénom est obligatoire.");
|
||||||
$this->role = Role::fromName(strtoupper($this->role));
|
$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)
|
if ($this->role == Role::PARTICIPANT)
|
||||||
$this->class = SchoolClass::fromName(strtoupper($this->class));
|
$this->class = SchoolClass::fromName(strtoupper($this->class));
|
||||||
@ -59,6 +60,9 @@ class NewUser
|
|||||||
{
|
{
|
||||||
global $DB, $YEAR;
|
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`)
|
$req = $DB->prepare("INSERT INTO `users`(`email`, `pwd_hash`, `confirm_email`, `surname`, `first_name`, `school`, `class`, `role`, `description`, `year`)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
|
||||||
$req->execute([$this->email, password_hash($this->password, PASSWORD_BCRYPT), $this->confirm_email_token, $this->surname, $this->first_name,
|
$req->execute([$this->email, password_hash($this->password, PASSWORD_BCRYPT), $this->confirm_email_token, $this->surname, $this->first_name,
|
||||||
|
@ -9,6 +9,11 @@ function loadUserValues()
|
|||||||
|
|
||||||
if (isset($_SESSION["user_id"])) {
|
if (isset($_SESSION["user_id"])) {
|
||||||
$user = $_SESSION["user"] = User::fromId($_SESSION["user_id"]);
|
$user = $_SESSION["user"] = User::fromId($_SESSION["user_id"]);
|
||||||
|
if ($user == null) {
|
||||||
|
unset($_SESSION["user_id"]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$_SESSION["role"] = $user->getRole();
|
$_SESSION["role"] = $user->getRole();
|
||||||
|
|
||||||
if ($user->getTeamId() !== null)
|
if ($user->getTeamId() !== null)
|
||||||
|
Loading…
Reference in New Issue
Block a user