Merge pull request #19 from ThomasRubini/user_edit

This commit is contained in:
Thomas Rubini 2023-01-17 15:56:46 +01:00 committed by GitHub
commit d0802ea4c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 22 deletions

View File

@ -108,6 +108,28 @@ final class UserController
$O_userModel = new UserModel();
$A_user = $O_userModel->getUserByID($_SESSION["ID"]);
return View::show("user/view", $A_user);
return View::show("user/edit", $A_user);
}
public function updateAction(Array $A_urlParams = null, Array $A_postParams = null)
{
Session::login_or_die();
$O_userModel = new UserModel();
if (isset($_POST["email"])) {
$S_email = $_POST["email"];
if (!empty($S_email) && filter_var($S_email, FILTER_VALIDATE_EMAIL)) {
$O_userModel->updateEmailByID($_SESSION["ID"], $_POST["email"]);
}
}
if (isset($_POST["username"])) {
$S_username = $_POST["username"];
if (!empty($S_username)) {
$O_userModel->updateUsernameByID($_SESSION["ID"], $_POST["username"]);
}
}
header("Location: /user");
}
}

View File

@ -69,4 +69,20 @@ final class UserModel
if ($row === false) return false;
return $row["DISABLED"] !== 1;
}
public function updateEmailByID($I_id, $S_newEmail){
$O_model = Model::get();
$stmt = $O_model->prepare("UPDATE USER SET EMAIL=:new_email WHERE ID=:id");
$stmt->bindParam("id", $I_id);
$stmt->bindParam("new_email", $S_newEmail);
$stmt->execute();
}
public function updateUsernameByID($I_id, $S_newUsername){
$O_model = Model::get();
$stmt = $O_model->prepare("UPDATE USER SET USERNAME=:new_username WHERE ID=:id");
$stmt->bindParam("id", $I_id);
$stmt->bindParam("new_username", $S_newUsername);
$stmt->execute();
}
}

View File

@ -1,28 +1,24 @@
<?php
$array_account = array(
"username" => "Jean_Michel_du_13",
"email" => "jeanmicheldu13@gmail.com"
);
?>
<main>
<a href="/disconnect">Se déconnecter</a>
<form action="/account/disconnect" method="post">
<?php if($A_view["ADMIN"]) echo "<p>Compte administrateur</p>"; ?>
<a href="/user/logout">Se déconnecter</a>
<form action="/user/update" method="post">
<label for="profilPicture">Changer l'image de profil&nbsp;</label>
<input type="file" name="profilPicture" id="profilPicture" accept="image/*">
<label for="username">Changer le nom d'utilisateur&nbsp;</label>
<input type="text" name="username" id="username" placeholder="<?= $array_account["username"] ?>">
<input type="text" name="username" id="username" placeholder="<?= $A_view["USERNAME"] ?>">
<label for="email">Changer d'e-mail&nbsp;</label>
<input type="email" name="email" id="email" placeholder="<?= $array_account["email"] ?>">
<input type="email" name="email" id="email" placeholder="<?= $A_view["EMAIL"] ?>">
<button type="button">Enregistrer</button>
<input type="submit" value="Enregistrer">
</form>
<hr>
<a href="/account/delete">Supprimer le compte ⚠️</a>
<a href="/user/delete">Supprimer le compte ⚠️</a>
</main>

View File

@ -1,8 +0,0 @@
<p> Your account : </p>
<p> Email : <?= $A_view["EMAIL"] ?> </p>
<p> Name : <?= $A_view["USERNAME"] ?> </p>
<p> Admin status : <?= $A_view["ADMIN"] ? "yes" : "no" ?> </p>
<form method="POST" action="/user/logout">
<input type="submit" value="Se déconnecter">
</form>