Skip to content
Snippets Groups Projects
Commit e437574c authored by Ahmad Nadil's avatar Ahmad Nadil
Browse files

feat: user info endpoint

parent ce46aedf
No related merge requests found
<?php
require_once '../../app/core/App.php';
require_once '../../app/core/Database.php';
require_once '../../app/models/User.php';
require_once '../../config/config.php';
session_start();
$user = new User();
if (isset($_GET['userid'])) {
$user_id = $_GET['userid'];
$exec = $user->getUserById($user_id);
if (!$exec) {
echo json_encode(array("error" => "No user found"));
exit();
}
$name = $user->getName();
$email = $user->getEmail();
echo json_encode(array("name" => $name, "email" => $email));
} else {
echo json_encode(array("error" => "No user id provided"));
}
...@@ -173,6 +173,28 @@ class User{ ...@@ -173,6 +173,28 @@ class User{
} }
} }
public function getUserById($userid) {
$query = "SELECT user_id, name, role, email, password FROM $this->table WHERE user_id = ?";
$stmt = $this->db->setSTMT($query);
mysqli_stmt_bind_param($stmt, "s", $userid);
$exists = mysqli_stmt_execute($stmt);
if(!$exists){
/* Tidak ada usernya */
return $exists;
}else{
/* Ambil hasilnya */
$result = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_array($result);
if($row){
$this->role = $row['role'];
$this->name = $row['name'];
$this->email = $row['email'];
$this->userID = $row['user_id'];
return true;
}
}
}
public function createresettoken($email, $token) { public function createresettoken($email, $token) {
$query = "UPDATE $this->table SET reset_token = ? WHERE email = ?"; $query = "UPDATE $this->table SET reset_token = ? WHERE email = ?";
$stmt = $this->db->setSTMT($query); $stmt = $this->db->setSTMT($query);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment