2019-09-06 11:48:50 +00:00
|
|
|
<?php
|
|
|
|
|
2019-09-06 23:33:05 +00:00
|
|
|
if (!isset($_SESSION["role"]) || $_SESSION["role"] != Role::ADMIN)
|
2019-09-07 11:42:36 +00:00
|
|
|
require_once "server_files/403.php";
|
2019-09-06 11:48:50 +00:00
|
|
|
|
2019-09-07 15:26:49 +00:00
|
|
|
$has_error = false;
|
|
|
|
$error_message = null;
|
|
|
|
|
2020-01-18 16:39:21 +00:00
|
|
|
if (isset($_POST["add_orga"])) {
|
2019-09-07 15:26:49 +00:00
|
|
|
$orga = new NewOrganizer($_POST);
|
|
|
|
try {
|
|
|
|
$orga->makeVerifications();
|
|
|
|
$orga->register();
|
|
|
|
}
|
|
|
|
catch (AssertionError $e) {
|
|
|
|
$has_error = true;
|
|
|
|
$error_message = $e->getMessage();
|
|
|
|
}
|
2019-09-06 11:48:50 +00:00
|
|
|
}
|
|
|
|
|
2019-09-07 15:26:49 +00:00
|
|
|
class NewOrganizer {
|
|
|
|
public $surname;
|
|
|
|
public $first_name;
|
|
|
|
public $email;
|
|
|
|
public $admin;
|
|
|
|
public $password;
|
2020-01-18 22:57:49 +00:00
|
|
|
public $token;
|
2019-09-07 15:26:49 +00:00
|
|
|
|
|
|
|
public function __construct($data)
|
|
|
|
{
|
|
|
|
foreach ($data as $key => $value)
|
|
|
|
$this->$key = htmlspecialchars($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function makeVerifications()
|
|
|
|
{
|
|
|
|
ensure($this->surname != null && $this->surname != "", "Le nom est invalide.");
|
|
|
|
ensure($this->first_name != null && $this->first_name != "", "Le prénom est invalide.");
|
|
|
|
ensure(filter_var($this->email, FILTER_VALIDATE_EMAIL), "L'adresse e-mail est invalide.");
|
|
|
|
$this->email = strtolower($this->email);
|
|
|
|
ensure(!userExists($this->email), "Cette adresse e-mail est déjà utilisée.");
|
2020-01-18 16:45:49 +00:00
|
|
|
$this->admin = isset($this->admin) ? 1 : 0;
|
2019-09-07 15:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function register() {
|
|
|
|
global $DB, $YEAR;
|
|
|
|
|
2019-09-08 22:41:52 +00:00
|
|
|
$this->password = genRandomPhrase(16, true);
|
2020-01-18 22:57:49 +00:00
|
|
|
$this->token = genRandomPhrase(64);
|
2019-09-07 15:26:49 +00:00
|
|
|
|
2020-01-18 22:57:49 +00:00
|
|
|
$req = $DB->prepare("INSERT INTO `users`(`email`, `pwd_hash`, `surname`, `first_name`, `role`, `forgotten_password`, `year`)
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?);");
|
|
|
|
$req->execute([$this->email, password_hash($this->password, PASSWORD_BCRYPT), $this->surname, $this->first_name, $this->admin ? "ADMIN" : "ORGANIZER", $this->token, $YEAR]);
|
2019-09-06 11:48:50 +00:00
|
|
|
|
2019-09-08 10:45:48 +00:00
|
|
|
Mailer::sendAddOrganizerMail($this);
|
2019-09-07 15:26:49 +00:00
|
|
|
}
|
2019-09-06 11:48:50 +00:00
|
|
|
}
|
|
|
|
|
2019-09-07 11:42:36 +00:00
|
|
|
require_once "server_files/views/ajouter_organisateur.php";
|