Source for file sl_reg_linker.php

Documentation is available at sl_reg_linker.php

  1. <?php
  2.  
  3.     /**
  4.     * Sloodle registration booth linker script
  5.     *
  6.     * Allows a registration booth in Second Life to setup an SL-Moodle user registration process
  7.     *
  8.     * @package sloodlelogin
  9.     * @copyright Copyright (c) 2007 Sloodle (various contributors)
  10.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  11.     *
  12.     * @contributor Edmund Edgar
  13.     * @contributor Peter R. Bloomfield
  14.     *
  15.     */
  16.  
  17.  
  18. //
  19. // This script requires to be able to authenticate the object making the request, so the "sloodlepwd" parameter should be set.
  20. // In order to register the avatar, the name and UUID are required, in parameters "sloodleavname" and "sloodleuuid".
  21. //
  22. // The database will be searched to see if the specified avatar has already been entered, and it will enter it if not.
  23. // If the user is already associated with a Moodle account, then this will be reported by the HTTP response, and nothing further needs done.
  24. // Otherwise, a login security code will be generated for the user if necessary, and will be returned to the requesting LSL script.
  25. // The registration booth can use the security code and the avatar's UUID to construct a URL to a login page on the Moodle site.
  26. // By following that link and entering their Moodle account details, the user can authenticate their avatar.
  27. //
  28. // Two success status codes: 1 (meaning user has been newly registered), 301 (user was already fully registered)
  29.  
  30. require_once('../config.php')// Sloodle/Moodle configuration
  31. require_once('../sl_debug.php')// Sloodle debug mode/functionality
  32. require_once('../lib/sl_lsllib.php')// Sloodle LSL library
  33.  
  34.  
  35. // Construct our LSL handler
  36. sloodle_debug_output("Constructing LSL handler...<br>");
  37. $lsl new SloodleLSLHandler();
  38. // Process the request data
  39. sloodle_debug_output("Processing request data...<br>");
  40. $lsl->request->process_request_data();
  41. // Authenticate the request
  42. // (Unless we pass in FALSE, the script will be terminated if authentication fails)
  43. sloodle_debug_output("Authenticating request...<br>");
  44. $lsl->request->authenticate_request();
  45.  
  46. // Ensure that the avatar UUID and name were both provided
  47. // (Note: due to cunning request processing trickery, if the is already fully registered with Sloodle,
  48. //  and only UUID OR name was provided, then the missing value will have been filled in)
  49. if (is_null($lsl->request->get_avatar_uuid())) {
  50.     $lsl->response->set_status_code(-311);
  51.     $lsl->response->set_status_descriptor('USER_REG');
  52.     $lsl->response->add_data_line('Avatar UUID not provided.');
  53.     $lsl->response->render_to_output();
  54.     exit();
  55. }
  56. if (is_null($lsl->request->get_avatar_name())) {
  57.     $lsl->response->set_status_code(-311);
  58.     $lsl->response->set_status_descriptor('USER_REG');
  59.     $lsl->response->add_data_line('Avatar name not provided.');
  60.     $lsl->response->render_to_output();
  61.     exit();
  62. }
  63.  
  64. // Do we have a Sloodle account already?
  65. sloodle_debug_output("Checking for a Sloodle user...<br>");
  66. $has_sloodle_account ($lsl->user->get_sloodle_user_id(0);
  67. // Note that, if the user already has a Moodle account, we will still output the security token
  68. // The reason for this is to allow a change of account link
  69. sloodle_debug_output("Checking for a Moodle user...<br>");
  70. $has_moodle_account $has_sloodle_account && ($lsl->user->get_moodle_user_id(0);
  71.  
  72.  
  73. // Is the user completely un-registered?
  74. if (!$has_sloodle_account{
  75.     sloodle_debug_output("User not registered with Sloodle. Registering...<br>");
  76.     // Yes - a new Sloodle entry is required
  77.     $result $lsl->user->create_sloodle_user($lsl->request->get_avatar_uuid()$lsl->request->get_avatar_name());
  78.     if ($result !== TRUE{
  79.         // Something went wrong
  80.         sloodle_debug_output("Failed to register user with Sloodle...<br>");
  81.         $lsl->response->set_status_code(-301);
  82.         $lsl->response->set_status_descriptor('USER_REG');
  83.         $lsl->response->add_data_line('Failed to add Sloodle user entry to database.');
  84.         if (is_string($result)) $lsl->response->add_data_line($result);
  85.         $lsl->response->render_to_output();
  86.         exit();
  87.     }
  88. }
  89.  
  90. // Make sure there is a login security token specified for the Sloodle user
  91. if (!$lsl->user->has_login_security_token()) {
  92.     sloodle_debug_output("Generating a login security token...<br>");
  93.     if (!$lsl->user->regenerate_login_security_token()) {
  94.         $lsl->response->set_status_code(-301);
  95.         $lsl->response->set_status_descriptor('USER_REG');
  96.         $lsl->response->add_data_line('Failed to generate a new login security token for the user.');       
  97.         $lsl->response->render_to_output();
  98.         exit();
  99.     }
  100. }
  101.  
  102. // We will return a URL which the registration booth will forward the user to
  103. sloodle_debug_output("Constructing user authentication URL...<br>");
  104. $auth_url SLOODLE_WWWROOT."/login/sl_welcome_reg.php?";
  105. $auth_url .= "sloodleuuid={$lsl->user->sloodle_user_cache->uuid}";
  106. $auth_url .= "&sloodleavname={$lsl->user->sloodle_user_cache->avname}";
  107. $auth_url .= "&sloodlelst={$lsl->user->sloodle_user_cache->loginsecuritytoken}";
  108. sloodle_debug_output("Authentication URL: $auth_url");
  109.  
  110. sloodle_debug_output("Outputting response...<br>");
  111.  
  112. // Get the Sloodle user cache
  113. $sloodle_user $lsl->user->sloodle_user_cache;
  114. // Output the token (note that the request object will already have set the user's UUID in the response object... cunning, eh? :-) )
  115. // The status code depends on whether or not the user is already fully registered
  116. if ($has_moodle_account$lsl->response->set_status_code(301);
  117. else $lsl->response->set_status_code(1);
  118. $lsl->response->set_status_descriptor('USER_REG');
  119. //$lsl->response->add_data_line($sloodle_user->loginsecuritytoken);
  120. $lsl->response->add_data_line($auth_url)// We'll just output the whole entire URL
  121. $lsl->response->render_to_output();
  122.  
  123. exit();
  124. ?>

Documentation generated on Tue, 04 Mar 2008 15:08:53 +0000 by phpDocumentor 1.4.0