mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2024-12-05 02:06:52 +00:00
Possibilité d'ajout d'un administrateur
This commit is contained in:
parent
61bec11bdb
commit
1edc2cbd60
@ -25,6 +25,7 @@ $ROUTES = [];
|
||||
|
||||
$ROUTES["^(|accueil|index|accueil\.php|accueil\.html|accueil\.py|index\.php|index\.html|index\.py)$"] = ["server_files/controllers/index.php"];
|
||||
$ROUTES["^ajouter_equipe$"] = ["server_files/controllers/ajouter_equipe.php"];
|
||||
$ROUTES["^ajouter_admin$"] = ["server_files/controllers/ajouter_admin.php"];
|
||||
$ROUTES["^calendrier$"] = ["server_files/controllers/calendrier.php"];
|
||||
$ROUTES["^confirmer_mail/([a-z0-9]*)/?$"] = ["server_files/controllers/confirmer_mail.php", "token"];
|
||||
$ROUTES["^connexion/(confirmation-mail)/?$"] = ["server_files/controllers/connexion.php", "confirmation-mail"];
|
||||
|
55
server_files/controllers/ajouter_admin.php
Normal file
55
server_files/controllers/ajouter_admin.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
if (!isset($_SESSION["role"]) || $_SESSION["role"] != Role::ADMIN)
|
||||
require_once "server_files/403.php";
|
||||
|
||||
$has_error = false;
|
||||
$error_message = null;
|
||||
|
||||
if (isset($_POST["submitted"])) {
|
||||
$admin = new NewAdmin($_POST);
|
||||
try {
|
||||
$admin->makeVerifications();
|
||||
$admin->register();
|
||||
}
|
||||
catch (AssertionError $e) {
|
||||
$has_error = true;
|
||||
$error_message = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
class NewAdmin {
|
||||
public $surname;
|
||||
public $first_name;
|
||||
public $email;
|
||||
public $password;
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
public function register() {
|
||||
global $DB, $YEAR;
|
||||
|
||||
$this->password = genRandomPhrase(16, true);
|
||||
|
||||
$req = $DB->prepare("INSERT INTO `users`(`email`, `pwd_hash`, `surname`, `first_name`, `role`, `year`)
|
||||
VALUES (?, ?, ?, ?, ?, ?);");
|
||||
$req->execute([$this->email, password_hash($this->password, PASSWORD_BCRYPT), $this->surname, $this->first_name, "ADMIN", $YEAR]);
|
||||
|
||||
Mailer::sendAddAdminMail($this);
|
||||
}
|
||||
}
|
||||
|
||||
require_once "server_files/views/ajouter_admin.php";
|
@ -75,6 +75,18 @@ class Mailer
|
||||
self::sendMail($user->getEmail(), "Mot de passe changé – Correspondances des Jeunes Mathématicien·ne·s", $content);
|
||||
}
|
||||
|
||||
public static function sendAddAdminMail(NewAdmin $new_admin)
|
||||
{
|
||||
global $YEAR;
|
||||
|
||||
$content = self::getTemplate("add_admin");
|
||||
$content = preg_replace("#{FIRST_NAME}#", $new_admin->first_name, $content);
|
||||
$content = preg_replace("#{SURNAME}#", $new_admin->surname, $content);
|
||||
$content = preg_replace("#{PASSWORD}#", $new_admin->password, $content);
|
||||
|
||||
self::sendMail($new_admin->email, "Ajout d'un administrateur – Correspondances des Jeunes Mathématicien·ne·s $YEAR", $content);
|
||||
}
|
||||
|
||||
public static function sendAddTeamMail(User $user, Team $team)
|
||||
{
|
||||
global $YEAR;
|
||||
|
21
server_files/services/mail_templates/add_admin.html
Normal file
21
server_files/services/mail_templates/add_admin.html
Normal file
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Administrateur des Correspondances des Jeunes Mathématicien·ne·s</title>
|
||||
</head>
|
||||
<body>
|
||||
Bonjour {FIRST_NAME} {SURNAME},<br />
|
||||
<br />
|
||||
Vous recevez ce message (envoyé automatiquement) car vous êtes administrateur pour les Correspondances des Jeunes Mathématicien·ne·s.
|
||||
Veuillez trouver ci-dessous vos informations d'utilisateur pour le site officiel des inscriptions. Elles vous permettront de gérer les inscriptions des équipes de votre tournoi.<br />
|
||||
<br />
|
||||
Votre mot de passe est : <strong style="color: red; font-size: 18px;">{PASSWORD}</strong><br />
|
||||
<br />
|
||||
Notez bien que ce mot de passe est temporaire, et pour des raisons de sécurité vous devrez le changer lors de votre prochaine connexion sur le site.<br />
|
||||
<br />
|
||||
Merci beaucoup pour votre aide !<br />
|
||||
<br />
|
||||
L'organisation des Correspondances des Jeunes Mathématicien·ne·s
|
||||
</body>
|
||||
</html>
|
49
server_files/views/ajouter_admin.php
Normal file
49
server_files/views/ajouter_admin.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
require_once "header.php";
|
||||
|
||||
if (isset($admin)) {
|
||||
if ($has_error) {
|
||||
echo "<h2>Erreur : " . $error_message . "</h2>";
|
||||
} else {
|
||||
echo "<h2>Organisateur ajouté avec succès ! Ses identifiants ont été transmis par mail.</h2>";
|
||||
}
|
||||
} ?>
|
||||
|
||||
<form method="POST">
|
||||
<input type="hidden" name="submitted" value="true"/>
|
||||
<table style="width: 100%;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="width: 30%;">
|
||||
<label for="surname">Nom :</label>
|
||||
</td>
|
||||
<td style="width: 70%;">
|
||||
<input style="width: 100%;" type="text" id="surname" name="surname"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="first_name">Prénom :</label>
|
||||
</td>
|
||||
<td>
|
||||
<input style="width: 100%;" type="text" id="first_name" name="first_name"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="email">Email :</label>
|
||||
</td>
|
||||
<td>
|
||||
<input style="width: 100%;" type="email" id="email" name="email"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<input style="width: 100%;" type="submit" value="Ajouter un administrateur"/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<?php require_once "footer.php" ?>
|
@ -42,6 +42,7 @@
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
<?php if ($_SESSION["role"] == Role::ADMIN) { ?>
|
||||
<li><a href="<?= $URL_BASE ?>/ajouter_admin">Ajouter un administrateur</a></li>
|
||||
<?php } ?>
|
||||
<li><a href="<?= $URL_BASE ?>/deconnexion">Déconnexion</a></li>
|
||||
<hr />
|
||||
|
Loading…
Reference in New Issue
Block a user