Source for file sloodle_session.php
Documentation is available at sloodle_session.php
// This file is part of the Sloodle project (www.sloodle.org)
* This file defines the primary API class, SloodleSession.
* @copyright Copyright (c) 2008 Sloodle (various contributors)
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
* @contributor Peter R. Bloomfield
/** General functionality. */
require_once(SLOODLE_LIBROOT.
'/general.php');
/** Request and response functionality. */
require_once(SLOODLE_LIBROOT.
'/io.php');
/** User functionality. */
require_once(SLOODLE_LIBROOT.
'/user.php');
/** Course functionality. */
require_once(SLOODLE_LIBROOT.
'/course.php');
/** Sloodle Controller functionality. */
require_once(SLOODLE_LIBROOT.
'/controller.php');
/** Module functionality. */
require_once(SLOODLE_LIBROOT.
'/modules.php');
* The primary API class, which manages all other parts.
* Outgoing response - can be rendered to HTTP or as a string.
* Current user information.
* The Sloodle course structure for the course this session is accessing
* The Sloodle module this session relates to, if any.
* Note: this may be the base Sloodle module class, or a derivative.
* Constructor - initialises members
* @param bool $process If true (default) then basic request data will be processed immediately. Otherwise, it can be done manually by calling $request->process_request_data()
// Construct the different parts of the session, as far as possible
// Process the basic request data
* Constructs and loads the appropriate module part of the session.
* Note that this function will fail if the current VLE user (in the $user member) does not have permission to access it.
* @param string $type The expected type of module - function fails if type is not correctly matched
* @param bool $db If true then the system will also try to load appropriate data from the database, as specified in the module ID request parameter
* @param bool $require If true, then if something goes wrong, the script will be terminated with an error message
* @param bool $override_access If true, then the user access permissions will be overriden to force access (not implemented yet)
* @return bool True if successful, or false otherwise. (Note, if parameter $require was true, then the script will terminate before this function returns if something goes wrong)
function load_module($type, $db, $require =
true, $override_access =
false)
// If the database loading is requested, then make sure we have a parameter to load with
if ($db_id ==
null) return false;
* Verifies security for the incoming request (but does not check user access).
* Initially ensures that the request is coming in on a valid and enabled course/controller (rejects it if not).
* The password is then checked, and it can handle prim-passwords and object-specific passwords.
* @param bool $require If true, the function will NOT return on authentication failure. Rather, it will terminate the script with an error message.
* @return bool true if successful in authenticating the request, or false if not.
// Make sure that the request data has been processed
// Make sure the controller ID parameter was specified
// Make sure we've got a valid course and controller object
// Make sure the course is available
// Make sure the contrller is available
// Make sure the controller is enabled
// Get the password parameter
// Does the password contain an object UUID?
if (count($parts) >=
2) {
// Make sure the password was provided
$this->response->quick_output(-
212, 'OBJECT_AUTH', 'Object-specific password not specified.', false);
// Verify the object's authorisation
// Passed authorisation - make sure the object is registered as being still active
// Get the controller password
// Prim Password access is disabled if no password has been specified
if (strlen($controllerpwd) ==
0) {
$this->response->quick_output(-
213, 'OBJECT_AUTH', 'Access to this Controller by prim password has been disabled.', false);
// Check that the passwords match
* Validates the user account and enrolment (ensures there is an avatar linked to a VLE account, and that the VLE account is enrolled in the current course).
* Attempts auto-registration/enrolment if that is allowed and required, and logs-in the user.
* Server access level is checked if it is specified in the request parameters.
* Note: if the request indicates that it relates to an object, then the validation fails.
* @param bool $require If true, the script will be terminated with an error message if validation fails
* @param bool $suppress_autoreg If true, auto-registration will be completely suppressed for this function call
* @param bool $suppress_autoenrol If true, auto-enrolment will be completely suppressed for this function call
* @return bool Returns true if validation and/or autoregistration were successful. Returns false on failure (unless $require was true).
function validate_user($require =
true, $suppress_autoreg =
false, $suppress_autoenrol =
false)
// Is it an object request?
// Was a server access level specified in the request?
// Check what level was specified
// Is a course already loaded?
$reason =
'No course loaded.';
// Was a user account already fully loaded?
// Is the user enrolled on the current course?
else $reason =
'User not enrolled in course.';
$reason =
'User not registered on site.';
// Was a user account already fully loaded?
else $reason =
'User not registered on site.';
// Is a course already loaded?
$reason =
'No course loaded.';
// Was a user account already fully loaded?
// Is the user staff on the current course?
else $reason =
'User not staff in course.';
$reason =
'User not registered on site.';
$reason =
'Access level not recognised';
// Was the user blocked by access level?
// Make sure a the course is loaded
$this->response->quick_output(-
511, 'COURSE', 'Cannot validate user - no course data loaded.', false);
// Is the user already loaded?
// If an avatar is loaded, but the user isn't, then we probably have a deleted Moodle user
// Make sure avatar details were provided
// Is validation required?
} else if (empty($uuid) ||
empty($avname)) {
// If there was a problem, just stop
// Ensure autoreg is not suppressed, and that it is permitted on that course and on the site
$this->response->quick_output(-
321, 'USER_AUTH', 'User not registered, and auto-registration of users was not permitted', false);
// It is important that we also check auto-enrolment here.
// If that is not enabled, but the call here requires it, then there is no point registering the user.
$this->response->quick_output(-
421, 'USER_ENROL', 'User not enrolled, and auto-enrolment of users was not permitted', false);
// Is there an avatar loaded?
// Add the avatar details, linked to imaginary user 0
// If we reached here then we definitely have an avatar
// Create a matching Moodle user
if ($password ===
FALSE) {
// Add a side effect code to our response data
// The user needs to be notified of their new username/password
if (isset
($_SERVER['HTTP_X_SECONDLIFE_OBJECT_KEY'])) {
// Is the user already enrolled on the course?
// Ensure auto-enrolment is not suppressed, and that it is permitted on that course and on the site
$this->response->quick_output(-
421, 'USER_ENROL', 'Auto-enrolment of users was not permitted', false);
// Attempt to enrol the user
// Add a side effect code to our response data
// Make sure the user is logged-in
//... Add functions for verifying user access to resources?
Documentation generated on Mon, 16 Jun 2008 15:57:00 +0100 by phpDocumentor 1.4.0