Source for file user_object_auth.php

Documentation is available at user_object_auth.php

  1. <?php
  2.     // This script is part of the Sloodle project
  3.  
  4.     /**
  5.     * User object authorisation interface.
  6.     * After an object in-world has initiated user-centric object authorisation,
  7.     *  the user should visit this page using a link they were provided in-world.
  8.     * It will finish registering the avatar (if necessary), and finish authorising the object.
  9.     *
  10.     * @package sloodle
  11.     * @copyright Copyright (c) 2008 Sloodle (various contributors)
  12.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  13.     *
  14.     * @contributor Peter R. Bloomfield
  15.     *
  16.     */
  17.     
  18.     /*
  19.     * The following parameter is always required:
  20.     *
  21.     *  sloodleauthid = the ID of the entry being authorised
  22.     *
  23.     * If an avatar is being registered at the same time, then both of the following parameters are also required:
  24.     *
  25.     *  sloodleuuid = UUID of the avatar
  26.     *  sloodlelst = the system-generated login security token
  27.     *
  28.     */
  29.     
  30.     /** Include Sloodle/Moodle configuration. */
  31.     require_once('../sl_config.php');
  32.     require_once(SLOODLE_LIBROOT.'/general.php');
  33.     
  34.     // Make sure the Moodle user is logged-in
  35.     
  36.     /** Include the Sloodle API. */
  37.     require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  38.     
  39.     // Display the page header
  40.     $strsloodle get_string('modulename''sloodle');
  41.     print_header_simple(get_string('userobjectauth''sloodle')""get_string('userobjectauth''sloodle')""""true);
  42.     
  43.     // Make sure it's not a guest who is logged in
  44.     if (isguest()) {
  45.         ?>
  46.         <div style="text-align:center;">
  47.          <h3><?php print_string('error''sloodle')?></h3>
  48.          <p><?php print_string('noguestaccess''sloodle')?></p>
  49.         </div>
  50.         <?php
  51.         print_footer();
  52.         exit();
  53.     }
  54.     
  55.     // Process the request data
  56.     $sloodle new SloodleSession();
  57.     // Load the Moodle user and linked avatar
  58.     $sloodle->user->load_user($USER->id);
  59.     $sloodle->user->load_linked_avatar();
  60.     
  61.     // Get the authorisation ID
  62.     $sloodleauthid required_param('sloodleauthid'PARAM_INT);
  63.     
  64.     // Does the avatar need to be registered?
  65.     if (!$sloodle->user->is_avatar_loaded()) {
  66.         // Make sure the user has permission to register their avatar
  67.         require_capability('mod/sloodle:registeravatar'get_context_instance(CONTEXT_SYSTEM));
  68.     
  69.         // Get the parameters
  70.         $sloodleuuid required_param('sloodleuuid'PARAM_TEXT);
  71.         $sloodlelst required_param('sloodlelst'PARAM_TEXT);
  72.         
  73.         // Attempt to find a pending avatar entry which matches the given details
  74.         $pa get_record('sloodle_pending_avatars''uuid'$sloodleuuid'lst'$sloodlelst);
  75.         if (!$pa{
  76.             ?>
  77.             <div style="text-align:center;">
  78.              <h3><?php print_string('error''sloodle')?></h3>
  79.              <p><?php print_string('pendingavatarnotfound''sloodle')?></p>
  80.             </div>
  81.             <?php
  82.             print_footer();
  83.             exit();
  84.         }
  85.         
  86.         // Add the new avatar
  87.         if (!$sloodle->user->add_linked_avatar($USER->id$sloodleuuid$pa->avname)) {
  88.             // Failed
  89.             ?>
  90.             <div style="text-align:center;">
  91.              <h3><?php print_string('error''sloodle')?></h3>
  92.              <p><?php print_string('failedcreatesloodleuser''sloodle')?></p>
  93.             </div>
  94.             <?php
  95.             print_footer();
  96.             exit();
  97.         }
  98.     }
  99.     
  100.     // Make sure the user has permission to authorise user objects
  101.     require_capability('mod/sloodle:userobjectauth'get_context_instance(CONTEXT_SYSTEM));
  102.  
  103.     // Attempt to authorise the object
  104.     if ($sloodle->user->authorise_user_object($sloodleauthid)) {
  105.         ?>
  106.         <div style="text-align:center;">
  107.          <p><?php print_string('objectauthsuccessful''sloodle')?></p>
  108.         </div>
  109.         <?php
  110.     else {
  111.         ?>
  112.         <div style="text-align:center;">
  113.          <h3><?php print_string('error''sloodle')?></h3>
  114.          <p><?php print_string('objectauthfailed''sloodle')?></p>
  115.         </div>
  116.         <?php
  117.     }
  118.     
  119.     
  120.     print_footer();
  121.     exit();
  122.     
  123.     
  124. ?>

Documentation generated on Fri, 17 Jul 2009 11:02:43 +0100 by phpDocumentor 1.4.0