Initial upload of the control panel

This commit is contained in:
Pinga 2023-08-07 13:14:05 +03:00
parent f21bd93fbc
commit 7eab26586c
791 changed files with 312718 additions and 0 deletions

50
cp/app/Models/User.php Normal file
View file

@ -0,0 +1,50 @@
<?php
namespace App\Models;
use Pinga\Db\PdoDatabase;
class User
{
private $db;
public function __construct(PdoDatabase $db)
{
$this->db = $db;
}
public function getAllUsers()
{
return $this->db->select('SELECT * FROM users');
}
public function getUserById($id)
{
return $this->db->select('SELECT * FROM users WHERE id = ?', [$id])->fetch();
}
public function createUser($username, $email, $password)
{
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
$this->db->insert('INSERT INTO users (username, email, password) VALUES (?, ?, ?)', [$username, $email, $hashedPassword]);
return $this->db->lastInsertId();
}
public function updateUser($id, $username, $email, $password)
{
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
$this->db->update('UPDATE users SET username = ?, email = ?, password = ? WHERE id = ?', [$username, $email, $hashedPassword, $id]);
return true;
}
public function deleteUser($id)
{
$this->db->delete('DELETE FROM users WHERE id = ?', [$id]);
return true;
}
}