davical/inc/PublicSession.php
Andrew McMillan 20ee255898 Refactor fetching of Principal records from database.
This is a significant refactoring, replacing the old getUserBy*()
functions with a new Principal class, and replacing the old
CalDAVPrincipal class with a new DAVPrincipal class which extends
the Principal class.

At this point all regression tests pass (again) but there could
well be issues for people who use alternative authenticators
such as LDAP, although I have endeavoured to resolve those
potential issues.

Signed-off-by: Andrew McMillan <andrew@morphoss.com>
2011-01-03 10:16:43 +13:00

99 lines
2.1 KiB
PHP

<?php
/**
* A Class for faking sessions which are anonymous access to a resource
*
* @package davical
* @subpackage PublicSession
* @author Andrew McMillan <andrew@morphoss.com>
* @copyright Morphoss Ltd
* @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
*/
/**
* A Class for handling a public (anonymous) session
*
* @package davical
*/
class PublicSession {
/**#@+
* @access private
*/
/**
* User ID number
* @var user_no int
*/
var $user_no;
/**
* Principal ID
* @var principal_id int
*/
var $principal_id;
/**
* User e-mail
* @var email string
*/
var $email;
/**
* User full name
* @var fullname string
*/
var $fullname;
/**
* Group rights
* @var groups array
*/
var $groups;
/**#@-*/
/**
* The constructor, which just calls the actual type configured
*/
function PublicSession() {
global $c;
$principal = new Principal('username','unauthenticated');
// Assign each field in the selected record to the object
foreach( $principal AS $k => $v ) {
$this->{$k} = $v;
}
$this->username = $principal->username();
$this->user_no = $principal->user_no();
$this->principal_id = $principal->principal_id();
$this->email = $principal->email();
$this->dav_name = $principal->dav_name();
$this->principal = $principal;
if ( function_exists("awl_set_locale") && isset($this->locale) && $this->locale != "" ) {
awl_set_locale($this->locale);
}
$this->groups = ( isset($c->public_groups) ? $c->public_groups : array() );
$this->roles = array( 'Public' => true );
$this->logged_in = false;
}
/**
* Checks whether a user is allowed to do something.
*
* The check is performed to see if the user has that role.
*
* @param string $whatever The role we want to know if the user has.
* @return boolean Whether or not the user has the specified role.
*/
function AllowedTo ( $whatever ) {
dbg_error_log('session', 'Checking whether "Public" is allowed to "%s"', $whatever);
return ( isset($this->roles[$whatever]) && $this->roles[$whatever] );
}
}