1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2025-06-25 03:40:28 +02: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

@ -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,