sl_welcome_reg.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 sloodleregenrol
  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. // This script is expected to be visited by a user with a web browser.
  17. // The following request parameters (GET or POST) are required for an initial page view:
  18. //
  19. // sloodleuuid - the UUID of the avatar which is being registered
  20. // sloodlelst - the login security token generated for the registration attempt
  21. //
  22. // Optionally, objects which need to know when registration has been accomplished can provide the following:
  23. //
  24. // sloodlechannel - UUID of an XMLRPC channel
  25. //
  26. // In most cases, after login, the above parameters will be sufficient.
  27. // However, where the same avatar is already registered to another Moodle user,
  28. // the user will be asked for confirmation. At this point, an additional
  29. // parameter will be added:
  30. //
  31. // sloodleconfirm - 'true' if the change/overwrite of existing details is confirmed
  32. //
  33. // A new optional parameter is the following:
  34. //
  35. // sloodlecourseid - the integer ID of the course which the user should be enrolled in after registration
  36. /** Include Sloodle/Moodle configuration. */
  37. require_once('../init.php');
  38. require_once(SLOODLE_LIBROOT.'/general.php');
  39. sloodle_require_login_no_guest();
  40. // Make sure the user has permission to register their avatar
  41. require_capability('mod/sloodle:registeravatar', get_context_instance(CONTEXT_SYSTEM));
  42. /** Include the Sloodle API. */
  43. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  44. // Display the page header
  45. sloodle_print_header_simple(get_string('welcometosloodle', 'sloodle'), "&nbsp;", get_string('welcometosloodle', 'sloodle'), "", "", true);
  46. // Process the request data
  47. $sloodle = new SloodleSession();
  48. // Check parameters
  49. $sloodleuuid = required_param('sloodleuuid', PARAM_TEXT);
  50. $sloodlelst = required_param('sloodlelst', PARAM_TEXT);
  51. $sloodlechannel = optional_param('sloodlechannel', NULL, PARAM_RAW);
  52. $sloodlecourseid = optional_param('sloodlecourseid', NULL, PARAM_INT);
  53. // Attempt to find a pending avatar entry which matches the given details
  54. $pa = sloodle_get_record('sloodle_pending_avatars', 'uuid', $sloodleuuid, 'lst', $sloodlelst);
  55. if (!$pa) {
  56. ?>
  57. <div style="text-align:center;">
  58. <h3><?php print_string('error', 'sloodle'); ?></h3>
  59. <p><?php print_string('pendingavatarnotfound', 'sloodle'); ?></p>
  60. </div>
  61. <?php
  62. sloodle_print_footer();
  63. exit();
  64. }
  65. // Add the new avatar
  66. if (!$sloodle->user->add_linked_avatar($USER->id, $sloodleuuid, $pa->avname)) {
  67. // Failed
  68. ?>
  69. <div style="text-align:center;">
  70. <h3><?php print_string('error', 'sloodle'); ?></h3>
  71. <p><?php print_string('failedcreatesloodleuser', 'sloodle'); ?></p>
  72. </div>
  73. <?php
  74. sloodle_print_footer();
  75. exit();
  76. }
  77. /// /// MOODLE-SPECIFIC /// ///
  78. // This is a slightly dirty hack, but is needed just now to prevent multiple avatar registrations.
  79. // Delete any avatar belonging to this user, which doesn't match the one just registered.
  80. sloodle_delete_records_select_params('sloodle_users', "userid = ? AND uuid <> ?", array($USER->id, $sloodleuuid));
  81. /// /// END MOODLE-SPECIFIC /// ///
  82. echo "<div style=\"text-align:center; font-size:140%;\">\n";
  83. echo get_string('welcometosloodle','sloodle').', '.$pa->avname.'<br /><br />'.get_string('userlinksuccessful','sloodle');
  84. echo "</div>\n";
  85. // If the object passed us a channel parameter, we'll use it to tell the object that the authentication is done.
  86. // (Parameter name: sloodlechannel)
  87. if (is_string($sloodlechannel) && !empty($sloodlechannel)) {
  88. flush();
  89. // XMLRPC messages going into SL strip \n, so we use \\n instead
  90. $sloodle->response->set_line_separator("\\n");
  91. // Prepare a response as a string
  92. $str = '';
  93. $sloodle->response->set_status_code(1);
  94. $sloodle->response->set_status_descriptor('USER_AUTH');
  95. $sloodle->response->add_data_line('User has been successfully registered.');
  96. $sloodle->response->render_to_string($str);
  97. // Send the message
  98. $xmlrpcresult = sloodle_send_xmlrpc_message($channel, 0, $str);
  99. if (!$xmlrpcresult) {
  100. echo '<div style="text-align:center;">';
  101. echo 'ERROR: Unable to tell the object that sent you here that you have been authenticated.';
  102. echo '</div>';
  103. }
  104. }
  105. // We we asked to enrol the user as well?
  106. if ($sloodlecourseid != NULL) {
  107. echo "<br/><br/><br/>";
  108. redirect("{$CFG->wwwroot}/course/enrol.php?id=$sloodlecourseid", get_string('nowenrol','sloodle'), 3);
  109. }
  110. sloodle_print_footer();
  111. exit();
  112. ?>