-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAuth.php
127 lines (89 loc) · 2.74 KB
/
Auth.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
class Wave_Auth {
const SUCCESS = 'success';
const FAILURE_NO_IDENTITY = 'no-identity';
const FAILURE_BAD_CREDENTIAL = 'bad-credential';
/**
* Reference to a static instance of the Auth Handler class
**/
private static $_handler;
private static $_auth_problems;
private static $_valid_auth;
public static $_is_loaded = false;
public static function registerHandler($class){
if(!class_implements($class))
throw new Wave_Exception('Auth Handler class ('.$class.') must implement Wave_IAuthable');
$class::loadPersistentAuth();
self::$_handler = $class;
self::$_is_loaded = true;
}
public static function checkIdentity($primary, $secondary){
$class = self::$_handler;
$auth_object = $class::loadByIdentifier($primary);
if($auth_object instanceof Wave_IAuthable){
$_is_valid = true;
// check the secondary credentials
foreach($secondary as $key => $value){
if(!isset($auth_object->$key) || $auth_object->$key != $value){
self::$_auth_problems['secondary'][$key] = array(
'value' => $auth_object->$key,
'reason' => self::FAILURE_BAD_CREDENTIAL,
'match' => $value);
$_is_valid = false;
}
}
if($_is_valid){
self::$_valid_auth = $auth_object;
self::registerIdentity($auth_object);
return self::SUCCESS;
}
else return self::FAILURE_BAD_CREDENTIAL;
}
else {
self::$_auth_problems['primary'] = $primary;
return self::FAILURE_NO_IDENTITY;
}
}
public static function registerIdentity($identity){
return Wave_Registry::store('__wave_identity', $identity);
}
public static function deregisterIdentity($identity){
return Wave_Registry::destroy('__wave_identity');
}
public static function persistIdentity($identity, $type = null, $expires = null){
$config = Wave_Config::get('deploy')->auth;
if($type === null)
$type = $config->persist_type;
if($expires === null)
$expires = $config->$type->expires;
if($type == 'cookie'){
Wave_Storage_Cookie::store(
$config->cookie->name,
$identity,
strtotime($expires),
$config->cookie->path,
$config->cookie->domain
);
}
}
public static function ceaseIdentity($type = null){
$config = Wave_Config::get('deploy')->auth;
if($type === null)
$type = $config->persist_type;
if($type == 'cookie'){
Wave_Storage_Cookie::store(
$config->cookie->name,
'',
time()-86400,
$config->cookie->path,
$config->cookie->domain
);
}
}
public static function getAuthProblems() { return self::$_auth_problems; }
public static function getIdentity() {
return Wave_Registry::fetch('__wave_identity');
}
public static function getHandlerClass() { return self::$_handler; }
}
?>