Source for file user_object_linker.php

Documentation is available at user_object_linker.php

  1. <?php
  2.     // This script is part of the Sloodle project
  3.  
  4.     /**
  5.     * User object authorisation linker.
  6.     * Allows objects to initiate authorisation for user-centric tasks.
  7.     * Also allows manual registration of avatars.
  8.     *
  9.     * @package sloodle
  10.     * @copyright Copyright (c) 2008 Sloodle (various contributors)
  11.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  12.     *
  13.     * @contributor Peter R. Bloomfield
  14.     *
  15.     */
  16.     
  17.     /*
  18.     * The following parameters are required:
  19.     *
  20.     *  sloodleobjuuid = UUID of the object
  21.     *  sloodleobjname = name of the object
  22.     *  sloodleobjpwd = password for the object
  23.     *  sloodleuuid = UUID of the avatar
  24.     *  sloodleavname = name of the avatar
  25.     *
  26.     * If successful, the status code returned will be 1 and the data line will contain a URL to forward the user to.
  27.     */
  28.     
  29.     
  30.     /** Lets Sloodle know we are in a linker script. */
  31.     define('SLOODLE_LINKER_SCRIPT'true);
  32.     
  33.     /** Grab the Sloodle/Moodle configuration. */
  34.     require_once('../sl_config.php');
  35.     /** Include the Sloodle PHP API. */
  36.     require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  37.     
  38.     
  39.     // Process the request (but we can't authenticate it)
  40.     $sloodle new SloodleSession();
  41.     
  42.     // Make sure we have the required parameters
  43.     $objuuid $sloodle->request->required_param('sloodleobjuuid');
  44.     $objname $sloodle->request->required_param('sloodleobjname');
  45.     $objpwd $sloodle->request->required_param('sloodleobjpwd');
  46.     $avuuid $sloodle->request->get_avatar_uuid();
  47.     $avname $sloodle->request->get_avatar_name();
  48.     
  49.     // Attempt to validate the user (but suppress autoreg/enrol)
  50.     $avatar_validated $sloodle->validate_avatar(false);
  51.     // If user validation failed, then setup a pending avatar entry
  52.     $lst null;
  53.     if (!$avatar_validated{
  54.         $pa $sloodle->user->add_pending_avatar($avuuid$avname);
  55.         if (!$pa{
  56.             $sloodle->response->quick_output(-322'MISC_REGISTER''Failed to add pending avatar details.'false);
  57.             exit();
  58.         }
  59.         
  60.         // Store the login security token
  61.         $lst $pa->lst;
  62.     }
  63.     
  64.     // Attempt to add a new object to the database
  65.     $sloodleauthid $sloodle->user->add_user_object($avuuid$objuuid$objname$objpwd);
  66.     if (!$sloodleauthid{
  67.         $sloodle->response->quick_output(-201'OBJECT_AUTH''Failed to add user object to database.'false);
  68.         exit();
  69.     }
  70.     
  71.     // Construct the URL
  72.     $url SLOODLE_WWWROOT ."/login/user_object_auth.php?sloodleauthid=$sloodleauthid";
  73.     if (!empty($lst)) $url .= "&sloodleuuid=$avuuid&sloodlelst=$lst";
  74.     
  75.     // Render the response
  76.     $sloodle->response->set_status_code(1);
  77.     $sloodle->response->set_status_descriptor('OK');
  78.     $sloodle->response->add_data_line($url);
  79.     $sloodle->response->render_to_output();
  80.     exit();
  81. ?>

Documentation generated on Mon, 07 Jul 2008 12:33:23 +0100 by phpDocumentor 1.4.0