Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.4KB

  1. <?php
  2. /**
  3. * @file mod/regmod.php
  4. */
  5. use Friendica\App;
  6. use Friendica\Core\Config;
  7. use Friendica\Core\L10n;
  8. use Friendica\Core\System;
  9. use Friendica\Core\Worker;
  10. use Friendica\Database\DBA;
  11. use Friendica\Model\Register;
  12. use Friendica\Model\User;
  13. use Friendica\Module\Login;
  14. function user_allow($hash)
  15. {
  16. $a = get_app();
  17. $register = Register::getByHash($hash);
  18. if (!DBA::isResult($register)) {
  19. return false;
  20. }
  21. $user = User::getById($register['uid']);
  22. if (!DBA::isResult($user)) {
  23. exit();
  24. }
  25. Register::deleteByHash($hash);
  26. DBA::update('user', ['blocked' => false, 'verified' => true], ['uid' => $register['uid']]);
  27. $profile = DBA::selectFirst('profile', ['net-publish'], ['uid' => $register['uid'], 'is-default' => true]);
  28. if (DBA::isResult($profile) && $profile['net-publish'] && Config::get('system', 'directory')) {
  29. $url = System::baseUrl() . '/profile/' . $user['nickname'];
  30. Worker::add(PRIORITY_LOW, "Directory", $url);
  31. }
  32. L10n::pushLang($register['language']);
  33. $res = User::sendRegisterOpenEmail(
  34. $user,
  35. Config::get('config', 'sitename'),
  36. $a->getBaseUrl(),
  37. defaults($register, 'password', 'Sent in a previous email')
  38. );
  39. L10n::popLang();
  40. if ($res) {
  41. info(L10n::t('Account approved.') . EOL);
  42. return true;
  43. }
  44. }
  45. // This does not have to go through user_remove() and save the nickname
  46. // permanently against re-registration, as the person was not yet
  47. // allowed to have friends on this system
  48. function user_deny($hash)
  49. {
  50. $register = Register::getByHash($hash);
  51. if (!DBA::isResult($register)) {
  52. return false;
  53. }
  54. $user = User::getById($register['uid']);
  55. if (!DBA::isResult($user)) {
  56. exit();
  57. }
  58. DBA::delete('user', ['uid' => $register['uid']]);
  59. Register::deleteByHash($register['hash']);
  60. notice(L10n::t('Registration revoked for %s', $user['username']) . EOL);
  61. return true;
  62. }
  63. function regmod_content(App $a)
  64. {
  65. if (!local_user()) {
  66. info(L10n::t('Please login.') . EOL);
  67. return Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 0 : 1);
  68. }
  69. if (!is_site_admin() || !empty($_SESSION['submanage'])) {
  70. notice(L10n::t('Permission denied.') . EOL);
  71. return '';
  72. }
  73. if ($a->argc != 3) {
  74. exit();
  75. }
  76. $cmd = $a->argv[1];
  77. $hash = $a->argv[2];
  78. if ($cmd === 'deny') {
  79. user_deny($hash);
  80. $a->internalRedirect('admin/users/');
  81. }
  82. if ($cmd === 'allow') {
  83. user_allow($hash);
  84. $a->internalRedirect('admin/users/');
  85. }
  86. }