-
Notifications
You must be signed in to change notification settings - Fork 2
/
Code.php
45 lines (32 loc) · 913 Bytes
/
Code.php
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
<?php
namespace IdnoPlugins\OAuth2 {
class Code extends \Idno\Common\Entity
{
function __construct()
{
parent::__construct();
$this->code = hash('sha256', mt_rand() . microtime(true));
$this->expires = strtotime('now + 10 minutes');
$this->setTitle($this->code); // better stub generation, not that it matters
}
function saveDataFromInput()
{
if (empty($this->_id)) {
$new = true;
} else {
$new = false;
}
$this->setAccess('PRIVATE');
return $this->save();
}
function jsonSerialize()
{
// Code is only ever serialised as part of something else
return $this->code;
}
function __toString()
{
return $this->code;
}
}
}