2023-10-22 01:46:22 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class User extends Model {
|
|
|
|
protected $dbTable = "users";
|
|
|
|
protected $dbFields = Array (
|
2023-10-27 11:02:35 +02:00
|
|
|
'uuid' => ['type'=>'text','required','unique','autoValMethod'=>'gen_ulid'],
|
2023-10-22 01:46:22 +02:00
|
|
|
'password' => ['type'=>'text'],
|
2023-10-29 17:37:28 +01:00
|
|
|
'registered' => ['type'=>'datetime','required','autoValMethod'=>'getDateTime'],
|
2023-10-22 01:46:22 +02:00
|
|
|
'email' => ['type'=>'email','unique'],
|
|
|
|
'firstname' => ['type'=>'text'],
|
|
|
|
'lastname' => ['type'=>'text'],
|
2023-10-30 19:27:44 +01:00
|
|
|
'birthday' => ['type' => 'text'],
|
|
|
|
'club' => ['type'=>'text'],
|
2023-10-22 01:46:22 +02:00
|
|
|
'last_login' => ['type'=>'datetime','required','unique','autoValMethod'=>'getDateTime'],
|
|
|
|
'token' => ['type'=>'text','required','unique','autoValMethod'=>'uuid4'],
|
|
|
|
'timezone' => ['type'=>'int'],
|
2023-10-22 23:05:24 +02:00
|
|
|
'dogs' => ['type'=> 'array','default'=>[]],
|
2023-10-26 20:26:28 +02:00
|
|
|
'tournaments' => ['type'=> 'array','default'=>[]],
|
2023-10-29 17:37:28 +01:00
|
|
|
'photo' => ['type'=>'text','default'=>'https://pictshare.net/pj7vzx.jpg'],
|
2023-10-30 22:41:11 +01:00
|
|
|
'active' => ['type'=>'bool','default'=>0]
|
2023-10-22 01:46:22 +02:00
|
|
|
);
|
|
|
|
protected $hidden = ['password','token'];
|
|
|
|
|
|
|
|
function login()
|
|
|
|
{
|
|
|
|
if(!$this->id) return false;
|
2023-10-30 22:36:18 +01:00
|
|
|
$this->load();
|
2023-10-22 01:46:22 +02:00
|
|
|
$this->last_login = $this->getDateTime();
|
|
|
|
|
|
|
|
$_SESSION['user'] = $this;
|
|
|
|
$_SESSION['userid'] = $this->id;
|
2023-10-30 23:13:44 +01:00
|
|
|
|
2023-10-30 23:30:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
$_SESSION['user']->save();
|
2023-10-30 23:27:01 +01:00
|
|
|
|
2023-10-30 23:37:40 +01:00
|
|
|
var_dump($_SESSION['user']->active);
|
|
|
|
exit();
|
2023-10-22 01:46:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function logout()
|
|
|
|
{
|
|
|
|
if(!$this->id) return false;
|
|
|
|
unset($_SESSION['user']);
|
|
|
|
}
|
|
|
|
|
2023-10-26 17:50:54 +02:00
|
|
|
function removeDog($dogid)
|
|
|
|
{
|
|
|
|
if(!$this->id) return false;
|
|
|
|
if (in_array($dogid, $this->data['dogs']))
|
|
|
|
{
|
|
|
|
$this->data['dogs'] = array_diff($this->data['dogs'],[$dogid]);
|
|
|
|
$this->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-22 01:46:22 +02:00
|
|
|
function getAll($filtered = true)
|
|
|
|
{
|
2023-10-29 17:37:28 +01:00
|
|
|
$keys = $GLOBALS['redis']->keys($this->dbTable.':*');
|
2023-10-22 01:46:22 +02:00
|
|
|
$users = [];
|
|
|
|
foreach($keys as $key)
|
|
|
|
{
|
|
|
|
$id = end(explode(':',$key));
|
|
|
|
$u = new User();
|
|
|
|
$u->load($id);
|
|
|
|
if($filtered===true)
|
2023-10-29 09:45:58 +01:00
|
|
|
$thisdata = $u->getDataFiltered();
|
2023-10-22 01:46:22 +02:00
|
|
|
else
|
2023-10-29 09:45:58 +01:00
|
|
|
$thisdata = $u->data;
|
|
|
|
|
|
|
|
$thisdata['id'] = $id;
|
|
|
|
|
|
|
|
$users[] = $thisdata;
|
2023-10-22 01:46:22 +02:00
|
|
|
}
|
|
|
|
return $users;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|