Esempio n. 1
0
 /**
  * Check that user is authenticated.
  * @throws AuthUserNotAuthenticatedException
  */
 public function __construct()
 {
     // construct the db table
     $this->table = new Table('users');
     // call the authenticator
     parent::__construct($this->table);
     // no entry, we are not logged in, fail the constructor
     if (!$this->isAuthenticated()) {
         throw new AuthUserNotAuthenticatedException();
     }
 }
Esempio n. 2
0
 /**
  * Create object for authenticated user
  */
 function __construct($roles = NULL)
 {
     $this->db = Fari_Db::getConnection();
     parent::__construct();
     // no entry, we are not logged in, fail the constructor
     if (!$this->isAuthenticated()) {
         throw new UserNotAuthenticatedException();
     }
     // fetch the database entry for us
     $dbUser = $this->db->selectRow('users', 'id, role, name, surname, short, long, invitation', array('username' => $this->getCredentials()));
     // user has been inactivated, throw them away
     if ($dbUser['role'] == 'inactive') {
         throw new UserNotAuthenticatedException();
     }
     // ORM much? effectively map db entry into an identity Fari_Bag object
     $this->identity = new Fari_Bag();
     foreach ($dbUser as $key => $value) {
         $this->identity->{$key} = $value;
     }
     // get an array of room permissions for us
     $q = $this->db->select('user_permissions', 'room', array('user' => $dbUser['id']), 'room ASC');
     foreach ($q as $room) {
         array_push($this->permissions, $room['room']);
     }
     // which rooms are we in?
     $q = $this->db->select('room_users JOIN rooms ON room_users.room=rooms.id', 'rooms.id, name', array('user' => $dbUser['id']), 'room ASC');
     foreach ($q as $room) {
         $this->inRoom[$room['name']] = $room['id'];
     }
     // optionally check the roles
     if (isset($roles)) {
         if (!$this->isAuthorized(&$roles, $dbUser['role'])) {
             throw new UserNotAuthorizedException();
         }
     }
 }