user_object_linker.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. // This script is part of the Sloodle project
  3. /**
  4. * User object authorisation linker.
  5. * Allows objects to initiate authorisation for user-centric tasks.
  6. * Also allows manual registration of avatars.
  7. *
  8. * @package sloodle
  9. * @copyright Copyright (c) 2008 Sloodle (various contributors)
  10. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  11. *
  12. * @contributor Peter R. Bloomfield
  13. *
  14. */
  15. /*
  16. * The following parameters are required:
  17. *
  18. * sloodleobjuuid = UUID of the object
  19. * sloodleobjname = name of the object
  20. * sloodleobjpwd = password for the object
  21. * sloodleuuid = UUID of the avatar
  22. * sloodleavname = name of the avatar
  23. *
  24. * If successful, the status code returned will be 1 and the data line will contain a URL to forward the user to.
  25. */
  26. /** Lets Sloodle know we are in a linker script. */
  27. define('SLOODLE_LINKER_SCRIPT', true);
  28. /** Grab the Sloodle/Moodle configuration. */
  29. require_once('../init.php');
  30. /** Include the Sloodle PHP API. */
  31. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  32. // Process the request (but we can't authenticate it)
  33. $sloodle = new SloodleSession();
  34. // Make sure we have the required parameters
  35. $objuuid = $sloodle->request->required_param('sloodleobjuuid');
  36. $objname = $sloodle->request->required_param('sloodleobjname');
  37. $objpwd = $sloodle->request->required_param('sloodleobjpwd');
  38. $avuuid = $sloodle->request->get_avatar_uuid();
  39. $avname = $sloodle->request->get_avatar_name();
  40. // Attempt to validate the user (but suppress autoreg/enrol)
  41. $avatar_validated = $sloodle->validate_avatar(false);
  42. // If user validation failed, then setup a pending avatar entry
  43. $lst = null;
  44. if (!$avatar_validated) {
  45. $pa = $sloodle->user->add_pending_avatar($avuuid, $avname);
  46. if (!$pa) {
  47. $sloodle->response->quick_output(-322, 'MISC_REGISTER', 'Failed to add pending avatar details.', false);
  48. exit();
  49. }
  50. // Store the login security token
  51. $lst = $pa->lst;
  52. }
  53. // Attempt to add a new object to the database
  54. $sloodleauthid = $sloodle->user->add_user_object($avuuid, $objuuid, $objname, $objpwd);
  55. if (!$sloodleauthid) {
  56. $sloodle->response->quick_output(-201, 'OBJECT_AUTH', 'Failed to add user object to database.', false);
  57. exit();
  58. }
  59. // Construct the URL
  60. $url = SLOODLE_WWWROOT ."/login/user_object_auth.php?sloodleauthid=$sloodleauthid";
  61. if (!empty($lst)) $url .= "&sloodleuuid=$avuuid&sloodlelst=$lst";
  62. // Render the response
  63. $sloodle->response->set_status_code(1);
  64. $sloodle->response->set_status_descriptor('OK');
  65. $sloodle->response->add_data_line($url);
  66. $sloodle->response->render_to_output();
  67. exit();
  68. ?>