uawdijnntqw1x1x1
IP : 216.73.216.153
Hostname : 6.87.74.97.host.secureserver.net
Kernel : Linux 6.87.74.97.host.secureserver.net 4.18.0-553.83.1.el8_10.x86_64 #1 SMP Mon Nov 10 04:22:44 EST 2025 x86_64
Disable Function : None :)
OS : Linux
PATH:
/
home
/
emeraadmin
/
.razor
/
..
/
public_html
/
ADVIA
/
..
/
node_modules
/
..
/
Service
/
UserService.php
/
/
<?php require_once __DIR__ . '/../Classes/Database.php'; require_once __DIR__ . '/../Classes/User.php'; class UserService { private $db; public function __construct() { $this->db = new Database(); } public function login($email, $password) { $this->db->query('SELECT id, email, password, role FROM users WHERE email = :email and status = :status'); $this->db->bind(':email', $email); $this->db->bind(':status', 'active'); $row = $this->db->single(); if ($row) { // Verify the password using password_verify() if (password_verify($password, $row->password)) { return $row; // Return the entire user row, which includes the role } } return false; } public function getAllUsers() { $this->db->query('SELECT id, first_name, last_name, email,phone,status, role ,last_login FROM users'); return $this->db->resultSet(); } public function authenticate($email, $password) { $this->db->query('SELECT * FROM users WHERE email = :email'); $this->db->bind(':email', $email); $row = $this->db->single(); if ($row && password_verify($password, $row->password)) { return true; } return false; } public function addUser($firstName, $lastName, $email, $phone, $role, $status, $password) { // Hash the password $passwordHash = password_hash($password, PASSWORD_DEFAULT); // Prepare and execute the SQL query $this->db->query('INSERT INTO users (first_name, last_name, email, phone, role, status, password) VALUES (:first_name, :last_name, :email, :phone, :role, :status, :password)'); $this->db->bind(':first_name', $firstName); $this->db->bind(':last_name', $lastName); $this->db->bind(':email', $email); $this->db->bind(':phone', $phone); $this->db->bind(':role', $role); $this->db->bind(':status', $status); $this->db->bind(':password', $passwordHash); $this->db->execute(); return $this->db->lastInsertId(); } public function updateUser($id, $firstName, $lastName, $email, $phone, $role) { $this->db->query('UPDATE users SET first_name = :first_name, last_name = :last_name, email = :email, phone = :phone, role = :role WHERE id = :id'); $this->db->bind(':id', $id); $this->db->bind(':first_name', $firstName); $this->db->bind(':last_name', $lastName); $this->db->bind(':email', $email); $this->db->bind(':phone', $phone); $this->db->bind(':role', $role); $this->db->execute(); } public function deleteUser($id) { // Soft delete if already active make it inactive or vice versa $this->db->query('SELECT status FROM users WHERE id = :id'); $this->db->bind(':id', $id); $row = $this->db->single(); $status = $row->status == 'active' ? 'inactive' : 'active'; $this->db->query('UPDATE users SET status = :status WHERE id = :id'); $this->db->bind(':id', $id); $this->db->bind(':status', $status); $this->db->execute(); } public function getUserById($id) { $this->db->query('SELECT id, first_name, last_name, email, phone, role, status FROM users WHERE id = :id'); $this->db->bind(':id', $id); return $this->db->single(); } public function isEmailExists($email) { $this->db->query('SELECT id FROM users WHERE email = :email'); $this->db->bind(':email', $email); $row = $this->db->single(); return $row ? true : false; } public function isEmailExistsForOthers($id, $email) { $this->db->query('SELECT id FROM users WHERE email = :email AND id != :id'); $this->db->bind(':email', $email); $this->db->bind(':id', $id); $row = $this->db->single(); return $row ? true : false; } public function resetPassword($id, $password) { $passwordHash = password_hash($password, PASSWORD_DEFAULT); $this->db->query('UPDATE users SET password = :password WHERE id = :id'); $this->db->bind(':id', $id); $this->db->bind(':password', $passwordHash); $this->db->execute(); } public function fetchUserName(int $userId) { $this->db->query('SELECT first_name, last_name FROM users WHERE id = :id'); $this->db->bind(':id', $userId); $row = $this->db->single(); return $row->first_name . ' ' . $row->last_name; } // Function to verify the user's password public function verifyUserPassword($email, $password) { // Call the getUserByEmail method from within the class $user = $this->getUserByEmail($email); if ($user) { // Verify the password using password_verify return password_verify($password, $user->password); } return false; // Return false if the user is not found } // Function to retrieve the user by email public function getUserByEmail($email) { // Get the database connection from the Database class $db = $this->db->getConn(); // Ensure the database object is properly initialized // Prepare and execute the query $stmt = $db->prepare("SELECT * FROM users WHERE email = :email"); $stmt->bindParam(':email', $email); $stmt->execute(); // Fetch the user as an object return $stmt->fetch(PDO::FETCH_OBJ); } }
/home/emeraadmin/.razor/../public_html/ADVIA/../node_modules/../Service/UserService.php