-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSession.php
More file actions
62 lines (53 loc) · 1.83 KB
/
Session.php
File metadata and controls
62 lines (53 loc) · 1.83 KB
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
62
<?php
/**
* Created by PhpStorm.
* User: davidamackenzie
* Date: 11/11/18
* Time: 6:16 PM
*/
class Session extends DBObject
{
static $tableName = 'sessions';
static $columns = [
'id' => ['name' => 'id', 'primary_key' => true],
'account' => ['name' => 'account', 'foreign_key' => true, 'foreign_table' => Account::class],
'profile' => ['name' => 'profile', 'foreign_key' => true, 'foreign_table' => Profile::class],
'signon_time' => ['name' => 'signon_time'],
'last_action_time' => ['name' => 'last_action_time'],
'ip_address' => ['name' => 'ip_address'],
'session_hash' => ['name' => 'session_hash'],
'active' => ['name' => 'active']
];
static function getColumns() {
return self::$columns;
}
static function getTableName()
{
return self::$tableName;
}
static function getSessionObj($session_id) {
$db = DBConnectionFactory::Instance();
$values = [self::$columns['id']['name'] => $session_id];
$records = $db->select(Session::$tableName,$values);
$sessionObj = false;
if (count($records)>=1) {
$sessionObj = new Session($records[0],true);
}
return $sessionObj;
}
static function getByHash($hash) {
$db = DBConnectionFactory::Instance();
$values = [self::$columns['session_hash']['name'] => $hash];
$records = $db->select(Session::$tableName,$values);
$sessionObj = false;
if (count($records)>=1) {
$sessionObj = new Session($records[0],true);
}
return $sessionObj;
}
public function isValid($hash,$ip_address) {
return ($this->getValue('session_hash') === $hash
&& $this->getValue('ip_address') === $ip_address
&& $this->getValue('active') === '1');
}
}