hooks.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * All plugin hook callback functions are handled in this file
  4. */
  5. /**
  6. * Listen to the usersettings save hook for some notifications to the user
  7. *
  8. * @param string $hook usersettings:save
  9. * @param string $type user
  10. * @param bool $return_value not supplied for this hook
  11. * @param null $params not supplied for this hook
  12. *
  13. * @return void
  14. */
  15. function security_tools_usersettings_save_handler($hook, $type, $return_value, $params) {
  16. $user_guid = (int) get_input("guid");
  17. if (empty($user_guid)) {
  18. $user_guid = elgg_get_logged_in_user_guid();
  19. }
  20. if (empty($user_guid)) {
  21. return $return_value;
  22. }
  23. $user = get_user($user_guid);
  24. if (empty($user) || !$user->canEdit()) {
  25. return $return_value;
  26. }
  27. // passwords are different
  28. if (_elgg_set_user_password() === true) {
  29. // do we need to notify the user about a password change
  30. $setting = elgg_get_plugin_setting("mails_password_change", "security_tools");
  31. if ($setting != "no") {
  32. $site = elgg_get_site_entity();
  33. $subject = elgg_echo("security_tools:notify_user:password:subject");
  34. $message = elgg_echo("security_tools:notify_user:password:message", array(
  35. $user->name,
  36. $site->name,
  37. $site->url
  38. ));
  39. notify_user($user->getGUID(), $site->getGUID(), $subject, $message, null, "email");
  40. }
  41. }
  42. // email are also different
  43. $setting = elgg_get_plugin_setting("mails_verify_email_change", "security_tools");
  44. if (($setting != "no") && ($user->getGUID() == elgg_get_logged_in_user_guid())) {
  45. // verify new email address
  46. security_tools_prepare_email_change();
  47. } else {
  48. // old way, or admin changes your email
  49. _elgg_set_user_email();
  50. }
  51. }