1 |
bareface |
1.1 |
<?php |
2 |
|
|
/* |
3 |
|
|
|
4 |
|
|
YakkaUser |
5 |
|
|
|
6 |
|
|
Represents a common user of yakka. |
7 |
|
|
|
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
require_once("YakkaSerialize.php"); |
11 |
|
|
require_once("YakkaSerializableObject.php"); |
12 |
|
|
require_once("YakkaRole.php"); |
13 |
|
|
|
14 |
|
|
class YakkaUser extends YakkaSerializableObject { |
15 |
|
|
var $userStorage; |
16 |
|
|
|
17 |
|
|
var $exists; |
18 |
|
|
|
19 |
|
|
var $name; |
20 |
|
|
var $authenticated; |
21 |
|
|
var $roles; |
22 |
|
|
|
23 |
|
|
function YakkaUser($id = null, $username = null, $password = null) { |
24 |
|
|
$$singleton = YAKKA_GLOBAL_SINGLETON; |
25 |
|
|
global $singleton; |
26 |
|
|
$this->userStorage = &$singleton->userStorage; |
27 |
|
|
|
28 |
|
|
$this->YakkaSerializableObject($id); |
29 |
|
|
|
30 |
|
|
$this->exists = $this->load($id); |
31 |
|
|
|
32 |
|
|
if ($username && $password) |
33 |
|
|
$this->authenticated = $this->authenticate($username, $password); |
34 |
|
|
else |
35 |
|
|
$this->authenticated = false; |
36 |
|
|
|
37 |
|
|
$this->roles = null; |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
function load($id) { |
41 |
|
|
if ($data = $this->userStorage->loadUser($id)) { |
42 |
|
|
$this->id = $data["id"]; |
43 |
|
|
$this->name = $data["name"]; |
44 |
|
|
$this->exists = true; |
45 |
|
|
} else { |
46 |
|
|
$this->id = $id; |
47 |
|
|
$this->exists = false; |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
return $this->exists; |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
function authenticate($username, $password) { |
54 |
|
|
if ($data = $this->userStorage->authenticateUser($username, $password)) { |
55 |
|
|
$this->id = $data["id"]; |
56 |
|
|
$this->name = $data["name"]; |
57 |
|
|
$this->exists = $this->authenticated = true; |
58 |
|
|
} else |
59 |
|
|
$this->exists = $this->authenticated = false; |
60 |
|
|
|
61 |
|
|
return $this->authenticated; |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
function getRoles() { |
65 |
|
|
if ($data = $this->userStorage->loadUserRoles($this->id)) |
66 |
|
|
while (list(,$role) = each($data)) |
67 |
|
|
while (list(,$roleId) = each($role)) |
68 |
|
|
$this->roles[$roleId] = new YakkaRole($roleId); |
69 |
|
|
|
70 |
|
|
return $this->roles; |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
function fromString($string) { |
74 |
|
|
$userStorage = &$this->userStorage; |
75 |
|
|
$this = unserialize($string); |
76 |
|
|
$this->userStorage = &$userStorage; |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
function toXml() { |
80 |
|
|
$xml = "<user id='".$this->id."' name='".$this->name."' isauthenticated='".YakkaSerialize::boolToString($this->authenticated)."'/>"; |
81 |
|
|
return $xml; |
82 |
|
|
} |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
?> |