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

78 lines
2.3 KiB
PHP
Raw Normal View History

2023-10-22 01:46:22 +02:00
<?php
class User extends Model {
protected $dbTable = "users";
protected $dbFields = Array (
'uuid' => ['type'=>'text','required','unique','autoValMethod'=>'gen_ulid'],
2023-10-22 01:46:22 +02:00
'password' => ['type'=>'text'],
'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'=>[]],
'tournaments' => ['type'=> 'array','default'=>[]],
'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:39:07 +01:00
var_dump("before save: ".$_SESSION['user']->active);
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);
2023-10-30 23:39:07 +01:00
exit("bye");
2023-10-22 01:46:22 +02:00
}
function logout()
{
if(!$this->id) return false;
unset($_SESSION['user']);
}
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)
{
$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;
}
}