linker.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Sloodle password reset linker.
  4. * Allows users in-world to request a password reset.
  5. * This is only intended for auto-registered users.
  6. *
  7. * @package sloodlepwreset
  8. * @copyright Copyright (c) 2008 Sloodle (various contributors)
  9. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  10. *
  11. * @contributor Peter R. Bloomfield
  12. *
  13. */
  14. // This script should be called with the following parameters:
  15. // sloodlecontrollerid = ID of a Sloodle Controller through which to access Moodle
  16. // sloodlepwd = the prim password or object-specific session key to authenticate the request
  17. // sloodleuuid = the UUID of a user agent
  18. // sloodleavname = the name of an avatar
  19. //
  20. // The following parameter is optional:
  21. // sloodleserveraccesslevel = indicates what access level to enforce: 0 = public, 1 = course, 2 = site, 3 = staff
  22. //
  23. //
  24. // If successful, the script will reset the user's password, returning status code 1.
  25. // The data line will contain: username|password
  26. //
  27. // If the user has an active email account associated with their Moodle account, then
  28. // status code -341 is returned, and the password is unchanged.
  29. /** Lets Sloodle know we are in a linker script. */
  30. define('SLOODLE_LINKER_SCRIPT', true);
  31. /** Grab the Sloodle/Moodle configuration. */
  32. require_once('../../init.php');
  33. /** Include the Sloodle PHP API. */
  34. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  35. // Authenticate the request, and validate the user, but do not allow auto-registration/enrolment
  36. $sloodle = new SloodleSession();
  37. $sloodle->authenticate_request();
  38. $sloodle->validate_user(true, true, true);
  39. // Request a password reset.
  40. $password = $sloodle->user->reset_password();
  41. // Prepare the response
  42. $sloodle->response->set_status_code(1);
  43. $sloodle->response->set_status_descriptor('OK');
  44. $sloodle->response->add_data_line(array($sloodle->user->get_username(), $password));
  45. // If there are any pending password notifications for this user, then delete them
  46. $sloodle->user->purge_password_notifications();
  47. // Output the response data
  48. sloodle_debug('<pre>');
  49. $sloodle->response->render_to_output();
  50. sloodle_debug('</pre>');
  51. ?>