Enhances the user profile

main
Yasen Pramatarov 2024-09-07 23:05:22 +03:00
parent 993474a754
commit 189d30bad5
4 changed files with 103 additions and 10 deletions

View File

@ -33,6 +33,33 @@ class User {
} }
} }
// get user ID from username
// FIXME not used now?
public function getUserId($username) {
$sql = 'SELECT id FROM users WHERE username = :username';
$query = $this->db->prepare($sql);
$query->bindParam(':username', $username);
$query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC);
}
// get user details
public function getUserDetails($username) {
$sql = 'SELECT * FROM users_meta um
LEFT JOIN users u
ON um.user_id = u.id
WHERE u.username = :username';
$query = $this->db->prepare($sql);
$query->execute([
':username' => $username,
]);
return $query->fetchAll(PDO::FETCH_ASSOC);
}
} }
?> ?>

View File

@ -1,5 +1,12 @@
<?php <?php
include '../app/templates/widget-profile.php'; require '../app/classes/user.php';
$userObject = new User($dbWeb);
$userDetails = $userObject->getUserDetails($user);
include '../app/templates/profile.php';
?> ?>

View File

@ -0,0 +1,68 @@
<!-- user profile -->
<div class="card text-center w-50 mx-auto">
<p class="h4 card-header">Profile of <?= $userDetails[0]['username'] ?></p>
<div class="card-body">
<div class="row">
<div class="col-md-4">
<div class="border" style="width:150px; height: 250px;"><img src="" alt="avatar" /></div>
</div>
<div class="col-md-8">
<div class="row mb-3">
<div class="col-md-4 text-end">
<label class="form-label"><small>username:</small></label>
</div>
<div class="col-md-8 text-start bg-light">
<?= $userDetails[0]['username'] ?>
</div>
</div>
<div class="row mb-3">
<div class="col-md-4 text-end">
<label class="form-label"><small>name:</small></label>
</div>
<div class="col-md-8 text-start bg-light">
<?= $userDetails[0]['name'] ?>
</div>
</div>
<div class="row mb-3">
<div class="col-md-4 text-end">
<label class="form-label"><small>email:</small></label>
</div>
<div class="col-md-8 text-start bg-light">
<?= $userDetails[0]['email'] ?>
</div>
</div>
<div class="row mb-3">
<div class="col-md-4 text-end">
<label class="form-label"><small>bio:</small></label>
</div>
<div class="col-md-8 text-start bg-light">
<?= $userDetails[0]['bio'] ?? '' ?>
</div>
</div>
<div class="row mb-3">
<div class="col-md-4 text-end">
<label class="form-label"><small>rights:</small></label>
</div>
<div class="col-md-8 text-start bg-light">
<?= $userDetails[0]['rights'] ?? '' ?>
</div>
</div>
<p><a href="<?= $app_root ?>?page=profile&action=edit" class="btn btn-primary">edit</a></p>
</div>
</div>
</div>
</div>
<!-- /user profile -->

View File

@ -1,9 +0,0 @@
<!-- widget "user profile" -->
<div>
<p>Profile of <?= $user ?></p>
<ul>
<li>username: <?= $_SESSION['username'] ?></li>
</ul>
</div>
<!-- /widget "user profile" -->