This repository has been archived on 2023-12-29. You can view files and clone it, but cannot push or open issues or pull requests.
dogstats/web/models/User.model.php
Chris f7a7c3457b
All checks were successful
Build and push / Pulling repo on server (push) Successful in 18s
man kann hunde anlegen yay
2023-10-22 23:05:24 +02:00

58 lines
1.7 KiB
PHP

<?php
class User extends Model {
protected $dbTable = "users";
protected $dbFields = Array (
'uuid' => ['type'=>'text','required','unique','autoValMethod'=>'gen_ulid'],
'password' => ['type'=>'text'],
'registered' => ['type'=>'datetime','required','unique','autoValMethod'=>'getDateTime'],
'email' => ['type'=>'email','unique'],
'firstname' => ['type'=>'text'],
'lastname' => ['type'=>'text'],
'last_login' => ['type'=>'datetime','required','unique','autoValMethod'=>'getDateTime'],
'token' => ['type'=>'text','required','unique','autoValMethod'=>'uuid4'],
'timezone' => ['type'=>'int'],
'dogs' => ['type'=> 'array','default'=>[]],
'active' => ['type'=>'int','default'=>0]
);
protected $hidden = ['password','token'];
function login()
{
if(!$this->id) return false;
$this->last_login = $this->getDateTime();
$this->save();
$_SESSION['user'] = $this;
$_SESSION['userid'] = $this->id;
}
function logout()
{
if(!$this->id) return false;
unset($_SESSION['user']);
}
function exists($id)
{
return $this->redis->exists($this->dbTable.':'.$id);
}
function getAll($filtered = true)
{
$keys = $this->redis->keys($this->dbTable.':*');
$users = [];
foreach($keys as $key)
{
$id = end(explode(':',$key));
$u = new User();
$u->load($id);
if($filtered===true)
$users[] = $u->getDataFiltered();
else
$users[] = $u->data;
}
return $users;
}
}