dragon-forks/kernel/repositories/users.php
2025-04-12 15:12:41 +02:00

42 lines
No EOL
1.5 KiB
PHP

<?php
/**
* Repository pour les utilisateurs, contient les différents appels
*/
class UserRepository extends Repository {
public function __construct() {
parent::__construct('users');
}
public function getByUsername($username) {
return $this->fetchOne("SELECT * FROM {{table}} WHERE username = :username", ["username" => $username]);
}
public function getByUsernameAndPassword($username, $password) {
return $this->fetchOne("SELECT * FROM {{table}} WHERE username = :username AND password = :pass", [
"username" => $username,
"pass" => $this->cryptPassword($password)
]);
}
public function updateOnlineTime($id) {
$this->doquery("UPDATE {{table}} SET onlinetime=NOW() WHERE id=:id LIMIT 1", ["id" => $id]);
}
public function createUser($username, $password, $email, $charname, $charclass, $difficulty, $verifycode) {
return $this->doquery("INSERT INTO {{table}} SET regdate=NOW(),verify=:verifycode,username=:username,password=:password,email=:email,charname=:charname,charclass=:charclass,difficulty=:difficulty", [
"username" => $username,
"password" => $this->cryptPassword($password),
"email" => $email,
"charname" => $charname,
"charclass" => $charclass,
"difficulty" => $difficulty,
"verifycode" => $verifycode
]);
}
private function cryptPassword($password) {
// TODO: change the password encryption method
return md5($password);
}
}