Adds basic profile editing
parent
06a534c2da
commit
f0f7d5b2d3
|
@ -45,6 +45,7 @@ class User {
|
||||||
return $query->fetchAll(PDO::FETCH_ASSOC);
|
return $query->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get user details
|
// get user details
|
||||||
public function getUserDetails($username) {
|
public function getUserDetails($username) {
|
||||||
$sql = 'SELECT * FROM users_meta um
|
$sql = 'SELECT * FROM users_meta um
|
||||||
|
@ -60,6 +61,30 @@ class User {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update an existing user
|
||||||
|
public function editUser($user_id, $updatedUser) {
|
||||||
|
try {
|
||||||
|
$sql = 'UPDATE users_meta SET
|
||||||
|
name = :name,
|
||||||
|
email = :email,
|
||||||
|
bio = :bio
|
||||||
|
WHERE user_id = :user_id';
|
||||||
|
$query = $this->db->prepare($sql);
|
||||||
|
$query->execute([
|
||||||
|
':user_id' => $user_id,
|
||||||
|
':name' => $updatedUser['name'],
|
||||||
|
':email' => $updatedUser['email'],
|
||||||
|
':bio' => $updatedUser['bio']
|
||||||
|
]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -5,9 +5,33 @@ require '../app/classes/user.php';
|
||||||
|
|
||||||
$userObject = new User($dbWeb);
|
$userObject = new User($dbWeb);
|
||||||
|
|
||||||
$userDetails = $userObject->getUserDetails($user);
|
// if a form is submitted, it's from the edit page
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||||
|
|
||||||
switch ($action) {
|
$user_id = $userObject->getUserId($user)[0]['id'];
|
||||||
|
|
||||||
|
// update the profile
|
||||||
|
$updatedUser = [
|
||||||
|
'name' => $_POST['name'] ?? '',
|
||||||
|
'email' => $_POST['email'] ?? '',
|
||||||
|
// 'avatar' => ,
|
||||||
|
'bio' => $_POST['bio'] ?? '',
|
||||||
|
];
|
||||||
|
$result = $userObject->editUser($user_id, $updatedUser);
|
||||||
|
if ($result === true) {
|
||||||
|
$_SESSION['notice'] = "User details for \"{$updatedUser['name']}\" are edited.";
|
||||||
|
} else {
|
||||||
|
$_SESSION['error'] = "Editing the user details failed. Error: $result";
|
||||||
|
}
|
||||||
|
|
||||||
|
header("Location: $app_root?page=profile");
|
||||||
|
exit();
|
||||||
|
|
||||||
|
// no form submitted, show the templates
|
||||||
|
} else {
|
||||||
|
$userDetails = $userObject->getUserDetails($user);
|
||||||
|
|
||||||
|
switch ($action) {
|
||||||
|
|
||||||
case 'edit':
|
case 'edit':
|
||||||
include '../app/templates/profile-edit.php';
|
include '../app/templates/profile-edit.php';
|
||||||
|
@ -15,6 +39,7 @@ switch ($action) {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
include '../app/templates/profile.php';
|
include '../app/templates/profile.php';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
<!-- widget "agents" -->
|
<!-- agents -->
|
||||||
<div class="card text-center w-50 mx-auto">
|
<div class="card text-center w-50 mx-auto">
|
||||||
<p class="h4 card-header">Jilo Agent configuration for Jitsi platform <strong>"<?= htmlspecialchars($platformDetails[0]['name']) ?>"</strong></p>
|
<p class="h4 card-header">Jilo Agent configuration for Jitsi platform <strong>"<?= htmlspecialchars($platformDetails[0]['name']) ?>"</strong></p>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
@ -47,4 +47,4 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- /widget "agents" -->
|
<!-- /agents -->
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
<p class="h4 card-header">Profile of <?= $userDetails[0]['username'] ?></p>
|
<p class="h4 card-header">Profile of <?= $userDetails[0]['username'] ?></p>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
|
||||||
|
<form method="POST" action="<?= $app_root ?>?page=profile">
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<p class="border rounded bg-light mb-4"><small>edit the profile fields</small></p>
|
<p class="border rounded bg-light mb-4"><small>edit the profile fields</small></p>
|
||||||
|
|
||||||
|
@ -14,7 +16,7 @@
|
||||||
|
|
||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
|
|
||||||
<div class="row mb-3">
|
<!--div class="row mb-3">
|
||||||
<div class="col-md-4 text-end">
|
<div class="col-md-4 text-end">
|
||||||
<label for="username" class="form-label"><small>username:</small></label>
|
<label for="username" class="form-label"><small>username:</small></label>
|
||||||
<span class="text-danger" style="margin-right: -12px;">*</span>
|
<span class="text-danger" style="margin-right: -12px;">*</span>
|
||||||
|
@ -22,7 +24,7 @@
|
||||||
<div class="col-md-8 text-start bg-light">
|
<div class="col-md-8 text-start bg-light">
|
||||||
<input class="form-control" type="text" name="username" value="<?= $userDetails[0]['username'] ?>" required />
|
<input class="form-control" type="text" name="username" value="<?= $userDetails[0]['username'] ?>" required />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div-->
|
||||||
|
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-md-4 text-end">
|
<div class="col-md-4 text-end">
|
||||||
|
@ -63,12 +65,12 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<a href="<?= $app_root ?>?page=profile" class="btn btn-primary">Cancel</a>
|
<a href="<?= $app_root ?>?page=profile" class="btn btn-secondary">Cancel</a>
|
||||||
<a href="<?= $app_root ?>?page=profile&action=edit" class="btn btn-danger">Save</a>
|
<input type="submit" class="btn btn-primary" value="Save" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- /user profile -->
|
<!-- /user profile -->
|
||||||
|
|
|
@ -13,14 +13,14 @@
|
||||||
|
|
||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
|
|
||||||
<div class="row mb-3">
|
<!--div class="row mb-3">
|
||||||
<div class="col-md-4 text-end">
|
<div class="col-md-4 text-end">
|
||||||
<label class="form-label"><small>username:</small></label>
|
<label class="form-label"><small>username:</small></label>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-8 text-start bg-light">
|
<div class="col-md-8 text-start bg-light">
|
||||||
<?= $userDetails[0]['username'] ?>
|
<?= $userDetails[0]['username'] ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div-->
|
||||||
|
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-md-4 text-end">
|
<div class="col-md-4 text-end">
|
||||||
|
|
Loading…
Reference in New Issue