Oppaitime's version of Gazelle
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.

take_invite.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?
  2. if (!$UserCount = $Cache->get_value('stats_user_count')) {
  3. $DB->query("
  4. SELECT COUNT(ID)
  5. FROM users_main
  6. WHERE Enabled = '1'");
  7. list($UserCount) = $DB->next_record();
  8. $Cache->cache_value('stats_user_count', $UserCount, 0);
  9. }
  10. $UserID = $LoggedUser['ID'];
  11. if (!apcu_exists('DBKEY')) {
  12. error('Invites disabled until database decrypted');
  13. header('Location: user.php?action=invite');
  14. die();
  15. }
  16. //This is where we handle things passed to us
  17. authorize();
  18. $DB->query("
  19. SELECT can_leech
  20. FROM users_main
  21. WHERE ID = $UserID");
  22. list($CanLeech) = $DB->next_record();
  23. if ($LoggedUser['RatioWatch']
  24. || !$CanLeech
  25. || $LoggedUser['DisableInvites'] == '1'
  26. || $LoggedUser['Invites'] == 0
  27. && !check_perms('site_send_unlimited_invites')
  28. || (
  29. $UserCount >= USER_LIMIT
  30. && USER_LIMIT != 0
  31. && !check_perms('site_can_invite_always')
  32. )
  33. ) {
  34. error(403);
  35. }
  36. $Email = trim($_POST['email']);
  37. $Username = $LoggedUser['Username'];
  38. $SiteName = SITE_NAME;
  39. $SiteURL = site_url();
  40. $InviteExpires = time_plus(60 * 60 * 24 * 3); // 3 days
  41. $InviteReason = check_perms('users_invite_notes') ? db_string($_POST['reason']) : '';
  42. //MultiInvite
  43. if (strpos($Email, '|') !== false && check_perms('site_send_unlimited_invites')) {
  44. $Emails = explode('|', $Email);
  45. } else {
  46. $Emails = array($Email);
  47. }
  48. foreach ($Emails as $CurEmail) {
  49. if (!preg_match("/^".EMAIL_REGEX."$/i", $CurEmail)) {
  50. if (count($Emails) > 1) {
  51. continue;
  52. } else {
  53. error('Invalid email.');
  54. header('Location: user.php?action=invite');
  55. die();
  56. }
  57. }
  58. $DB->query("
  59. SELECT Email
  60. FROM invites
  61. WHERE InviterID = ".$LoggedUser['ID']);
  62. if ($DB->has_results()) {
  63. while (list($MaybeEmail) = $DB->next_record()) {
  64. if (Crypto::decrypt($MaybeEmail) == $CurEmail) {
  65. error('You already have a pending invite to that address!');
  66. header('Location: user.php?action=invite');
  67. die();
  68. }
  69. }
  70. }
  71. $InviteKey = db_string(Users::make_secret());
  72. $DisabledChan = BOT_DISABLED_CHAN;
  73. $IRCServer = BOT_SERVER;
  74. $Message = <<<EOT
  75. The user $Username has invited you to join $SiteName and has specified this address ($CurEmail) as your email address. If you do not know this person, please ignore this email, and do not reply.
  76. Please note that selling invites, trading invites, and giving invites away publicly (e.g. on a forum) is strictly forbidden. If you have received your invite as a result of any of these things, do not bother signing up - you will be banned and lose your chances of ever signing up legitimately.
  77. If you have previously had an account at $SiteName, do not use this invite. Instead, please join $DisabledChan on $IRCServer and ask for your account to be reactivated.
  78. To confirm your invite, click on the following link:
  79. {$SiteURL}register.php?invite=$InviteKey
  80. After you register, you will be able to use your account. Please take note that if you do not use this invite in the next 3 days, it will expire. We urge you to read the RULES and the wiki immediately after you join.
  81. Thank you,
  82. $SiteName Staff
  83. EOT;
  84. $DB->query("
  85. INSERT INTO invites
  86. (InviterID, InviteKey, Email, Expires, Reason)
  87. VALUES
  88. ('$LoggedUser[ID]', '$InviteKey', '".Crypto::encrypt($CurEmail)."', '$InviteExpires', '$InviteReason')");
  89. if (!check_perms('site_send_unlimited_invites')) {
  90. $DB->query("
  91. UPDATE users_main
  92. SET Invites = GREATEST(Invites, 1) - 1
  93. WHERE ID = '$LoggedUser[ID]'");
  94. $Cache->begin_transaction('user_info_heavy_'.$LoggedUser['ID']);
  95. $Cache->update_row(false, array('Invites' => '-1'));
  96. $Cache->commit_transaction(0);
  97. }
  98. Misc::send_email($CurEmail, 'You have been invited to '.SITE_NAME, $Message, 'noreply');
  99. }
  100. header('Location: user.php?action=invite');
  101. ?>