Ejemplo n.º 1
0
 function testWithDB()
 {
     $u = new folksoUser($this->dbc);
     $u->loadUser(array('nick' => 'marcelp', 'firstname' => 'Marcel', 'lastname' => 'Proust', 'email' => '*****@*****.**', 'userid' => 'marcelp-2010-001'));
     $this->assertIsA($u, folksoUser, 'problem with object creation');
     $this->assertEqual($u->nick, 'marcelp', 'missing data in user object');
     $this->assertEqual($u->email, '*****@*****.**', 'Email incorrect after loadUser');
     $this->assertEqual($u->userid, 'marcelp-2010-001', 'userid not present: ' . $u->userid);
     $this->assertTrue($u->checkUserRight('folkso', 'tag'), 'user right fails incorrectly');
     $this->assertFalse($u->checkUserRight('ploop', 'dooop'), 'inexistant right should not validate');
 }
Ejemplo n.º 2
0
 /**
  * Load user data from session id (cookie). Retuns folksoUser
  * obj. Caches the fkUser object. We might consider a "force reload"
  * option if there were a reason for it. This also means that if the
  * arguments (sid) change, the data returned will not. This should
  * not be a problem though.
  *
  * @param $sid Session ID.
  * @return folksoUser obj or false if user not found
  */
 public function userSession($sid = null, $service = null, $right = null)
 {
     if ($this->user instanceof folksoUser) {
         return $this->user;
     }
     $sid = $sid ? $sid : $this->sessionId;
     if ($this->validateSid($sid) === false) {
         return false;
         // exception?
     }
     $i = new folksoDBinteract($this->dbc);
     $sql = '';
     if (is_null($service) || is_null($right)) {
         $sql = 'select u.nick as nick, u.firstname as firstname, ' . '  u.lastname as lastname, u.email as email, u.userid  as userid' . ' from sessions s ' . ' join users u on u.userid = s.userid ' . " where s.token = '" . $sid . "'" . " and s.started > now() - 1209600 ";
     } else {
         $sql = 'select u.nick as nick, u.firstname as firstname, ' . '  u.lastname as lastname, u.email as email, u.userid  as userid, ' . ' dr.rightid, dr.service ' . ' from sessions s ' . ' join users u on u.userid = s.userid ' . ' left join users_rights ur on ur.userid = s.userid ' . ' left join rights dr on dr.rightid = ur.rightid ' . " where s.token = '" . $i->dbescape($sid) . "' " . " and dr.rightid = '" . $i->dbescape($right) . "' " . " and s.started > now() - 1209600 ";
     }
     $this->debug = $sql;
     $i->query($sql);
     if ($i->result_status == 'OK') {
         $u = new folksoUser($this->dbc);
         $res = $i->result->fetch_object();
         $u->loadUser(array('nick' => $res->nick, 'firstname' => $res->firstname, 'lastname' => $res->lastname, 'email' => $res->email, 'userid' => $res->userid));
         if ($right && $service && $res->rightid == $right && $res->service == $service) {
             $this->debug2 = 'we r here';
             $u->rights->addRight(new folksoRight($res->service, $res->rightid));
         }
         return $u;
     } else {
         return false;
     }
 }