Source for file sl_welcome_reg.php

Documentation is available at sl_welcome_reg.php

  1. <?php
  2.     /**
  3.     * Sloodle avatar registration page.
  4.     *
  5.     * Allows users who have clicked an in-world registration booth to complete their
  6.     *  avatar registration by logging-in to their Moodle account (or creating one).
  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.     // This script is expected to be visited by a user with a web browser.
  18.     // The following request parameters (GET or POST) are required for an initial page view:
  19.     //
  20.     //  sloodleuuid - the UUID of the avatar which is being registered
  21.     //  sloodlelst - the login security token generated for the registration attempt
  22.     //
  23.     // Optionally, objects which need to know when registration has been accomplished can provide the following:
  24.     //
  25.     //  sloodlechannel - UUID of an XMLRPC channel
  26.     //
  27.     // (Note that the avatar name can be given in parameter 'sloodleavname' instead of the UUID parameter, but this is not recommended)
  28.     //
  29.     // In most cases, after login, the above parameters will be sufficient.
  30.     // However, where the same avatar is already registered to another Moodle user,
  31.     //  the user will be asked for confirmation. At this point, an additional
  32.     //  parameter will be added:
  33.     //
  34.     //  sloodleconfirm - 'true' if the change/overwrite of existing details is confirmed
  35.     //
  36.     // A new optional is the following:
  37.     //
  38.     //  sloodlecourseid - the integer ID of the course which the user should be enrolled in after registration
  39.     
  40.     // At some stage, we may implement the use of an XMLRPC channel to send a
  41.     //  confirmation back to the in-world object which initiated the registration.
  42.     
  43.  
  44.     require_once('../config.php')// Sloodle/Moodle configuraton
  45.     
  46.     // Make sure the Moodle user is logged-in
  47.     require_login();
  48.     
  49.     require_once(SLOODLE_DIRROOT.'/sl_debug.php')// Enables debug mode if necessary... very useful! :-)
  50.     require_once(SLOODLE_DIRROOT.'/lib/sl_lsllib.php')// LSL handling code - we use this here for user processing   
  51.     
  52.     print_header('Welcome to sloodle'''''''false''''false'');
  53.     print_heading('Welcome to sloodle');
  54.     
  55.     // Make sure it's not a guest who is logged in
  56.     sloodle_debug_output('Ensuring logged-in user is not a guest...<br/>');
  57.     if (isguest()) {
  58.         sloodle_debug_output('User is a guest.<br/>');
  59.         ?>
  60.         <div style="text-align:center;">
  61.          <h3><?php print_string('error''sloodle')?></h3>
  62.          <p><?php print_string('noguestaccess''sloodle')?></p>
  63.         </div>
  64.         <?php
  65.         print_footer();
  66.         exit();
  67.     }
  68.     
  69.     // Process the request data
  70.     sloodle_debug_output('Constructing an LSL handler...<br/>');
  71.     $lsl new SloodleLSLHandler();
  72.     sloodle_debug_output('Processing request data...<br/>');
  73.     $lsl->request->process_request_data();
  74.     
  75.     // Get additional parameters
  76.     sloodle_debug_output('Fetching additional request parameters...<br/>');
  77.     $channel optional_param('sloodlechannel'NULLPARAM_RAW);
  78.     $sloodlecourseid optional_param('sloodlecourseid'NULLPARAM_INT);
  79.     
  80.     // Make sure a Sloodle user has been identified
  81.     sloodle_debug_output('Checking if a Sloodle user has been identified...<br/>');
  82.     if ($lsl->user->get_sloodle_user_id(<= 0{
  83.         sloodle_debug_output('Failed to identify a Sloodle user.<br/>');
  84.         ?>
  85.         <div style="text-align:center;">
  86.          <h3><?php print_string('error''sloodle')?></h3>
  87.          <p><?php print_string('avatarnotfound''sloodle')?></p>
  88.         </div>
  89.         <?php
  90.         print_footer();
  91.         exit();
  92.     }
  93.     
  94.     // Check that we could verify the Sloodle user by the security token
  95.     sloodle_debug_output('Attempting to confirm Sloodle user by login security token...<br/>');
  96.     if ($lsl->confirm_by_login_security_token(TRUE!== TRUE{
  97.         // Verification failed
  98.         sloodle_debug_output('Failed to confirm Sloodle user by login security token.<br/>');
  99.         ?>
  100.         <div style="text-align:center;">
  101.          <h3><?php print_string('error''sloodle')?></h3>
  102.          <p><?php print_string('loginsecuritytokenfailed''sloodle')?></p>
  103.         </div>
  104.         <?php
  105.         print_footer();
  106.         exit();
  107.     }
  108.     
  109.     // TODO: add confirmation for changing avatar to different account...
  110.     
  111.     
  112.     // Get the Moodle user ID
  113.     $lsl->user->set_moodle_user_id($USER->id);
  114.     // Link the accounts together
  115.     sloodle_debug_output('Attempting to link Sloodle user to Moodle account...<br/>');
  116.     $linkresult $lsl->user->link_users();
  117.     if ($linkresult !== TRUE{
  118.         sloodle_debug_output('Failed to link users.<br/>');
  119.         if (is_string($linkresult)) sloodle_debug_output("Error message: $linkresult<br/>");
  120.         else sloodle_debug_output(' No error message given.<br/>');
  121.         ?>
  122.         <div style="text-align:center;">
  123.          <h3><?php print_string('error''sloodle')?></h3>
  124.          <p><?php print_string('userlinkfailed''sloodle')?></p>
  125.         </div>
  126.         <?php
  127.         print_footer();
  128.         exit();
  129.     }
  130.     
  131.     // Success!
  132.     sloodle_debug_output('Successfully linked avatar to Moodle account.<br/>');
  133.     
  134.     echo "<div style=\"text-align:center\">\n";
  135.      echo get_string('welcometosloodle','sloodle').', '.$lsl->request->get_avatar_name().'<br /><br />'.get_string('userlinksuccessful','sloodle');
  136.     echo "</div>\n";
  137.  
  138.     // TODO: update all this bit to use the response object, localisation strings, and debug messages
  139.     
  140.     // If the object passed us a channel parameter, we'll use it to tell the object that the authentication is done.
  141.     // (Parameter name: sloodlechannel)
  142.     if (is_string($channel&& !empty($channel)) {
  143.         flush();
  144.         sloodle_debug_output('Preparing XMLRPC confirmation message...<br/>');
  145.         
  146.         // Prepare a response as a string
  147.         $str '';
  148.         $lsl->response->set_status_code(1);
  149.         $lsl->response->set_status_descriptor('USER_AUTH');
  150.         $lsl->response->add_data_line('User has been successfully registered.');
  151.         $lsl->response->render_to_string($str);
  152.         
  153.         // XMLRPC hack -- double escape the newlines
  154.         $str str_replace("\n""\\n"$str);
  155.         
  156.         sloodle_debug_output('Sending XMLRPC confirmation message...<br/>');
  157.         $xmlrpcresult sloodle_send_xmlrpc_message($channel0$str);
  158.         if (!$xmlrpcresult{
  159.             sloodle_debug_output('ERROR: failed to send XMLRPC confirmation message.<br/>');
  160.             echo '<div style="text-align:center;">';
  161.             echo 'ERROR: Unable to tell the object that sent you here that you have been authenticated.';
  162.             echo '</div>';
  163.         else {
  164.             sloodle_debug_output('Successfully sent XMLRPC confirmation message.<br/>');
  165.         }
  166.     else {
  167.         sloodle_debug_output('XMLRPC confirmation message not requested.<br/>');
  168.     }
  169.     
  170.     sloodle_debug_output('Finished.<br/>');
  171.     
  172.     
  173.     // We we asked to enrol the user as well?
  174.     if ($sloodlecourseid != NULL{
  175.         echo "<br/><br/><br/>";
  176.         redirect("{$CFG->wwwroot}/course/enrol.php?id=$sloodlecourseid"get_string('nowenrol','sloodle')3);
  177.     }
  178.     
  179.     
  180.     print_footer();
  181.     exit();
  182.  
  183. ?>

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