mirror of
https://github.com/getnamingo/registry.git
synced 2025-08-03 08:11:49 +02:00
Initial upload of the control panel
This commit is contained in:
parent
f21bd93fbc
commit
7eab26586c
791 changed files with 312718 additions and 0 deletions
50
cp/app/Models/User.php
Normal file
50
cp/app/Models/User.php
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue