auth_check_linker.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Sloodle object authorization check linker.
  4. * Allows authorised objects in SL to check whether or not a specified user can authorize objects.
  5. *
  6. * @package sloodleclassroom
  7. * @copyright Copyright (c) 2008 Sloodle (various contributors)
  8. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  9. *
  10. * @contributor Peter R. Bloomfield
  11. *
  12. */
  13. // The following parameters are required:
  14. //
  15. // sloodlecontrollerid = the ID of the controller through which the current object may access Sloodle
  16. // sloodlepwd = the prim password or object-specific session key to authenticate access
  17. // sloodleuuid = the UUID of the agent requesting object authorisation
  18. // sloodleavname = the name of the avatar requesting object authorisation
  19. //
  20. //
  21. // If the check is successful, the status code will be 1.
  22. // The data line will contain a 1 to indicate if the user can authorise objects on this course, or 0 otherwise.
  23. //
  24. /** Lets Sloodle know we are in a linker script. */
  25. define('SLOODLE_LINKER_SCRIPT', true);
  26. /** Grab the Sloodle/Moodle configuration. */
  27. require_once('../init.php');
  28. /** Include the Sloodle PHP API. */
  29. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  30. // Authenticate the request and the user, but do not allow autoreg/autoenrol
  31. $sloodle = new SloodleSession();
  32. $sloodle->authenticate_request();
  33. $sloodle->validate_user(true, true, true);
  34. $sloodle->user->login();
  35. $can_authorize = false;
  36. // MOODLE-SPECIFIC //
  37. // Check that the user has the Sloodle capability on this course
  38. $course_context = get_context_instance(CONTEXT_COURSE, $sloodle->course->get_course_id());
  39. $can_authorize = has_capability('mod/sloodle:objectauth' $course_context);
  40. // END MOODLE-SPECIFIC //
  41. // Render the output
  42. $sloodle->response->set_status_code(1);
  43. $sloodle->response->set_status_descriptor('OK');
  44. if ($can_authorize) $sloodle->response->add_data_line('1');
  45. else $sloodle->response->add_data_line('0');
  46. $sloodle->response->render_to_output();
  47. ?>