|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Palladium\Mapper; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* SQL code for locating identity data by token and updating last usage. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
use Palladium\Component\SqlMapper; |
|
10
|
|
|
use Palladium\Entity\Authentication as Entity; |
|
11
|
|
|
use Palladium\Contract\CanPersistIdentity; |
|
12
|
|
|
|
|
13
|
|
|
class Identity extends SqlMapper implements CanPersistIdentity |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @param Entity\Identity $entity |
|
18
|
|
|
*/ |
|
19
|
|
|
public function store(Entity\Identity $entity) |
|
20
|
|
|
{ |
|
21
|
|
|
$table = $this->config['accounts']['identities']; |
|
22
|
|
|
|
|
23
|
|
|
$sql = "UPDATE $table |
|
24
|
|
|
SET used_on = FROM_UNIXTIME(:used) |
|
25
|
|
|
WHERE identity_id = :id"; |
|
26
|
|
|
|
|
27
|
|
|
$statement = $this->connection->prepare($sql); |
|
28
|
|
|
|
|
29
|
|
|
$statement->bindValue(':id', $entity->getId()); |
|
30
|
|
|
$statement->bindValue(':used', $entity->getLastUsed()); |
|
31
|
|
|
$statement->execute(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param Entity\Identity $entity |
|
37
|
|
|
*/ |
|
38
|
|
View Code Duplication |
public function fetch(Entity\Identity $entity) |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
$table = $this->config['accounts']['identities']; |
|
41
|
|
|
|
|
42
|
|
|
$sql = "SELECT identity_id AS id, |
|
43
|
|
|
user_id AS userId, |
|
44
|
|
|
status AS status, |
|
45
|
|
|
hash AS hash, |
|
46
|
|
|
UNIX_TIMESTAMP(token_expires_on) AS tokenEndOfLife |
|
47
|
|
|
FROM $table |
|
48
|
|
|
WHERE token = :token |
|
49
|
|
|
AND token_action = :action |
|
50
|
|
|
AND token_expires_on > FROM_UNIXTIME(:expires)"; |
|
51
|
|
|
|
|
52
|
|
|
$statement = $this->connection->prepare($sql); |
|
53
|
|
|
|
|
54
|
|
|
$statement->bindValue(':token', $entity->getToken()); |
|
55
|
|
|
$statement->bindValue(':action', $entity->getTokenAction()); |
|
56
|
|
|
$statement->bindValue(':expires', $entity->getTokenEndOfLife()); |
|
57
|
|
|
|
|
58
|
|
|
$statement->execute(); |
|
59
|
|
|
|
|
60
|
|
|
$data = $statement->fetch(); |
|
61
|
|
|
|
|
62
|
|
|
if ($data) { |
|
63
|
|
|
$this->applyValues($entity, $data); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param Entity\Identity $entity |
|
70
|
|
|
*/ |
|
71
|
|
|
public function fetch(Entity\Identity $entity) {} |
|
72
|
|
|
} |
|
73
|
|
|
|