* dumb commit
[vsc.git] / _res / _libs / tsusers.class.php
blob7bbdc2499a091c03becc37036d9c022927f0b7df
1 <?php
2 /**
3 * @desc This object loads at login time all user's credentials.
4 * further along the session they can be verified at any time.
6 */
7 class tsUsers extends tdoUsers {
8 public $uid;
10 public function __construct (&$db){
11 parent::__construct ($db);
13 if (isset ($_SESSION['user'])) {
14 $user = unserialize ($_SESSION['user']);
16 if ( is_array($user) ) {
17 $this->uid = $user['user_id'];
18 $this->loadFromArray ($user, false);
23 public function isLogged () {
24 if (isset ($_SESSION['user'])) {
25 $user = unserialize ($_SESSION['user']);
27 if ( $user['user_id'] > 0) {
28 return true;
31 return false;
34 public function isAllowed ($to = 'nothing') {
35 return in_array ($to, explode ('|', $_SESSION['user']['user_role']));
38 public function logIn ($uName, $pass) {
39 $this->user_name = $uName;
40 $this->user_credentials = md5 ($pass.$this->salt);
42 if ($this->getCount() > 0) {
43 $group = new tdoGroups ($this->$db);
44 $roles = new tdoRoles ($this->$db);
45 $linkGR = new tdoGroupsRoles ($this->db);
46 $linkUG = new tdoUsersGroups ($this->db);
48 $roles->set_FieldModifier('GROUP_CONCAT(DISTINCT(%s) SEPARATOR \'|\')', $roles->role_name);
50 $linkGR->joinWith ('INNER', $linkGR->role_id, $roles, $roles->id);
51 $group->joinWith ('INNER', $group->id, $linkGR, $linkGR->group_id);
53 $linkUG->joinWith ('INNER', $linkUG->group_id, $group, $group->id);
54 $this->joinWith ('INNER', $this->id, $linkUG, $linkUG->user_id);
56 $user = $this->getArray(1);
58 $_SESSION['user'] = serialize ($user[0]);
59 // var_dump($_SESSION);die;
61 } else {
62 $_SESSION['user'] = null;
66 public function logOut () {
67 $_SESSION['user'] = null;
68 session_destroy();