user_object_auth.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. // This script is part of the Sloodle project
  3. /**
  4. * User object authorisation interface.
  5. * After an object in-world has initiated user-centric object authorisation,
  6. * the user should visit this page using a link they were provided in-world.
  7. * It will finish registering the avatar (if necessary), and finish authorising the object.
  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. * The following parameter is always required:
  18. *
  19. * sloodleauthid = the ID of the entry being authorised
  20. *
  21. * If an avatar is being registered at the same time, then both of the following parameters are also required:
  22. *
  23. * sloodleuuid = UUID of the avatar
  24. * sloodlelst = the system-generated login security token
  25. *
  26. */
  27. /** Include Sloodle/Moodle configuration. */
  28. require_once('../init.php');
  29. require_once(SLOODLE_LIBROOT.'/general.php');
  30. // Make sure the Moodle user is logged-in
  31. sloodle_require_login_no_guest();
  32. /** Include the Sloodle API. */
  33. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  34. // Display the page header
  35. $strsloodle = get_string('modulename', 'sloodle');
  36. sloodle_print_header_simple(get_string('userobjectauth', 'sloodle'), "&nbsp;", get_string('userobjectauth', 'sloodle'), "", "", true);
  37. // Make sure it's not a guest who is logged in
  38. if (isguestuser()) {
  39. ?>
  40. <div style="text-align:center;">
  41. <h3><?php print_string('error', 'sloodle'); ?></h3>
  42. <p><?php print_string('noguestaccess', 'sloodle'); ?></p>
  43. </div>
  44. <?php
  45. sloodle_print_footer();
  46. exit();
  47. }
  48. // Process the request data
  49. $sloodle = new SloodleSession();
  50. // Load the Moodle user and linked avatar
  51. $sloodle->user->load_user($USER->id);
  52. $sloodle->user->load_linked_avatar();
  53. // Get the authorisation ID
  54. $sloodleauthid = required_param('sloodleauthid', PARAM_INT);
  55. // Does the avatar need to be registered?
  56. if (!$sloodle->user->is_avatar_loaded()) {
  57. // Make sure the user has permission to register their avatar
  58. require_capability('mod/sloodle:registeravatar', get_context_instance(CONTEXT_SYSTEM));
  59. // Get the parameters
  60. $sloodleuuid = required_param('sloodleuuid', PARAM_TEXT);
  61. $sloodlelst = required_param('sloodlelst', PARAM_TEXT);
  62. // Attempt to find a pending avatar entry which matches the given details
  63. $pa = sloodle_get_record('sloodle_pending_avatars', 'uuid', $sloodleuuid, 'lst', $sloodlelst);
  64. if (!$pa) {
  65. ?>
  66. <div style="text-align:center;">
  67. <h3><?php print_string('error', 'sloodle'); ?></h3>
  68. <p><?php print_string('pendingavatarnotfound', 'sloodle'); ?></p>
  69. </div>
  70. <?php
  71. sloodle_print_footer();
  72. exit();
  73. }
  74. // Add the new avatar
  75. if (!$sloodle->user->add_linked_avatar($USER->id, $sloodleuuid, $pa->avname)) {
  76. // Failed
  77. ?>
  78. <div style="text-align:center;">
  79. <h3><?php print_string('error', 'sloodle'); ?></h3>
  80. <p><?php print_string('failedcreatesloodleuser', 'sloodle'); ?></p>
  81. </div>
  82. <?php
  83. sloodle_print_footer();
  84. exit();
  85. }
  86. }
  87. // Make sure the user has permission to authorise user objects
  88. require_capability('mod/sloodle:userobjectauth', get_context_instance(CONTEXT_SYSTEM));
  89. // Attempt to authorise the object
  90. if ($sloodle->user->authorise_user_object($sloodleauthid)) {
  91. ?>
  92. <div style="text-align:center;">
  93. <p><?php print_string('objectauthsuccessful', 'sloodle'); ?></p>
  94. </div>
  95. <?php
  96. } else {
  97. ?>
  98. <div style="text-align:center;">
  99. <h3><?php print_string('error', 'sloodle'); ?></h3>
  100. <p><?php print_string('objectauthfailed', 'sloodle'); ?></p>
  101. </div>
  102. <?php
  103. }
  104. sloodle_print_footer();
  105. exit();
  106. ?>