blob: 18ef6a72d5a3fd15bbd416af85281a2f43bbf229 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<?php
namespace Wcms;
use JamesMoss\Flywheel\Document;
class Modelauthtoken extends Modeldb
{
const AUTHTOKEN_REPO_NAME = 'authtoken';
const AUTHTOKEN_ID_LENGTH = 30;
public function __construct()
{
parent::__construct();
$this->storeinit(self::AUTHTOKEN_REPO_NAME);
}
/**
* Add a Token in the database according to the Users datas
*
* @param User $user
*/
public function add(User $user)
{
$datas = [
'user' => $user->id(),
'ip' => $_SERVER['SERVER_ADDR'],
'creationdate' => '1'
];
$tokendata = new Document($datas);
$exist = true;
while ($exist !== false) {
$id = bin2hex(random_bytes(self::AUTHTOKEN_ID_LENGTH));
$exist = $this->repo->findById($id);
}
$tokendata->setId($id);
return $this->repo->store($tokendata);
}
public function getbytoken(string $token)
{
return $this->repo->findById($token);
}
public function delete(string $token)
{
return $this->repo->delete($token);
}
}
?>
|