improve hit and run disable user + signup link

This commit is contained in:
xiaomlove
2022-10-24 22:37:37 +08:00
parent d9e5cbdcbc
commit b738fca498
6 changed files with 45 additions and 28 deletions
+31 -24
View File
@@ -98,6 +98,7 @@ class HitAndRunRepository extends BaseRepository
$setting['diff_in_section'] = $diffInSection; $setting['diff_in_section'] = $diffInSection;
$setting['search_box_id'] = $browseMode; $setting['search_box_id'] = $browseMode;
$this->doCronjobUpdateStatus($setting, $uid, $torrentId, $ignoreTime); $this->doCronjobUpdateStatus($setting, $uid, $torrentId, $ignoreTime);
$this->checkAndDisableUser($setting);
$specialMode = Setting::get('main.specialcat'); $specialMode = Setting::get('main.specialcat');
if ($diffInSection && $browseMode != $specialMode) { if ($diffInSection && $browseMode != $specialMode) {
@@ -105,6 +106,7 @@ class HitAndRunRepository extends BaseRepository
$setting['diff_in_section'] = $diffInSection; $setting['diff_in_section'] = $diffInSection;
$setting['search_box_id'] = $specialMode; $setting['search_box_id'] = $specialMode;
$this->doCronjobUpdateStatus($setting, $uid, $torrentId, $ignoreTime); $this->doCronjobUpdateStatus($setting, $uid, $torrentId, $ignoreTime);
$this->checkAndDisableUser($setting);
} }
} }
@@ -333,37 +335,43 @@ class HitAndRunRepository extends BaseRepository
]; ];
Message::query()->insert($message); Message::query()->insert($message);
if (!$disableUser) { return true;
do_log("[DO_NOT_DISABLE_USER], return"); }
return true;
} private function checkAndDisableUser(array $setting): void
if ($hitAndRun->user->enabled == 'no') { {
do_log("[USER_ALREADY_DISABLED], return"); $disableCounts = HitAndRun::getConfig('ban_user_when_counts_reach', $setting['search_box_id']);
return true; $query = HitAndRun::query()
} ->selectRaw("count(*) as counts, uid")
//disable user ->where('status', HitAndRun::STATUS_UNREACHED)
/** @var User $user */ ->groupBy('uid')
$user = $hitAndRun->user; ->having("counts", '>=', $disableCounts)
$countsQuery = $user->hitAndRuns()->where('status', HitAndRun::STATUS_UNREACHED); ;
if ($setting['diff_in_section']) { if ($setting['diff_in_section']) {
$countsQuery->whereHas('torrent.basic_category', function (Builder $query) use ($setting) { $query->whereHas('torrent.basic_category', function (Builder $query) use ($setting) {
return $query->where('mode', $setting['search_box_id']); return $query->where('mode', $setting['search_box_id']);
}); });
} }
$counts = $countsQuery->count(); $result = $query->get();
$disableCounts = HitAndRun::getConfig('ban_user_when_counts_reach', $setting['search_box_id']); if ($result->isEmpty()) {
do_log("user: {$user->id}, H&R counts: $counts, disableCounts: $disableCounts", 'notice'); do_log("No user to disable");
if ($counts >= $disableCounts) { return;
do_log("[DISABLE_USER_DUE_TO_H&R_UNREACHED]", 'notice'); }
$comment = nexus_trans('hr.unreached_disable_comment', [], $user->locale); $users = User::query()
$user->updateWithModComment(['enabled' => User::ENABLED_NO], $comment); ->with('language')
->where('enabled', User::ENABLED_YES)
->find($result->pluck('id')->toArray(), ['id', 'username', 'lang']);
foreach ($users as $user) {
$locale = $user->locale;
$comment = nexus_trans('hr.unreached_disable_comment', [], $locale);
$user->updateWithModComment(['enabled' => User::ENABLED_NO], sprintf('%s - %s', date('Y-m-d'), $comment));
$message = [ $message = [
'receiver' => $hitAndRun->uid, 'receiver' => $user->id,
'added' => Carbon::now()->toDateTimeString(), 'added' => Carbon::now()->toDateTimeString(),
'subject' => $comment, 'subject' => $comment,
'msg' => nexus_trans('hr.unreached_disable_message_content', [ 'msg' => nexus_trans('hr.unreached_disable_message_content', [
'ban_user_when_counts_reach' => Setting::get('hr.ban_user_when_counts_reach'), 'ban_user_when_counts_reach' => Setting::get('hr.ban_user_when_counts_reach'),
], $hitAndRun->user->locale), ], $locale),
]; ];
Message::query()->insert($message); Message::query()->insert($message);
$userBanLog = [ $userBanLog = [
@@ -372,9 +380,8 @@ class HitAndRunRepository extends BaseRepository
'reason' => $comment 'reason' => $comment
]; ];
UserBanLog::query()->insert($userBanLog); UserBanLog::query()->insert($userBanLog);
do_log("Disable user: " . nexus_json_encode($userBanLog));
} }
return true;
} }
public function getStatusStats($uid, $formatted = true) public function getStatusStats($uid, $formatted = true)
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.7.30'); defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.7.30');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-10-23'); defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-10-24');
defined('IN_TRACKER') || define('IN_TRACKER', false); defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP"); defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org"); defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
+2 -1
View File
@@ -48,8 +48,9 @@ $lang_invite = array
'std_only' => "只有", 'std_only' => "只有",
'std_or_above_can_invite' => "及以上的用户才能发送邀请。", 'std_or_above_can_invite' => "及以上的用户才能发送邀请。",
'text_email_restriction_note' => "你只能发送邀请给以下邮箱:", 'text_email_restriction_note' => "你只能发送邀请给以下邮箱:",
'harem_addition' => '后宫加成', 'harem_addition' => '后宫加成',
'signup_link_help' => '右键复制',
'signup_link' => '注册链接',
); );
?> ?>
+2
View File
@@ -49,6 +49,8 @@ $lang_invite = array
'std_or_above_can_invite' => "及以上的用戶才能發送邀請。", 'std_or_above_can_invite' => "及以上的用戶才能發送邀請。",
'text_email_restriction_note' => "你只能發送邀請給以下郵箱:", 'text_email_restriction_note' => "你只能發送邀請給以下郵箱:",
'harem_addition' => '後宮加成', 'harem_addition' => '後宮加成',
'signup_link_help' => '右鍵復製',
'signup_link' => '註冊鏈接',
); );
?> ?>
+2
View File
@@ -52,6 +52,8 @@ Best Regards,
'std_or_above_can_invite' => " or above can send invitation.", 'std_or_above_can_invite' => " or above can send invitation.",
'text_email_restriction_note' => "You could only send invitation to email from those domains: ", 'text_email_restriction_note' => "You could only send invitation to email from those domains: ",
'harem_addition' => 'Harem addition', 'harem_addition' => 'Harem addition',
'signup_link_help' => 'Right click to copy',
'signup_link' => 'Signup link',
); );
?> ?>
+7 -2
View File
@@ -166,12 +166,17 @@ if ($type == 'new'){
for ($i = 0; $i < $num1; ++$i) for ($i = 0; $i < $num1; ++$i)
{ {
$arr1 = mysql_fetch_assoc($rer); $arr1 = mysql_fetch_assoc($rer);
$isHashValid = $arr1['valid'] == \App\Models\Invite::VALID_YES;
$registerLink = '';
if ($isHashValid) {
$registerLink = sprintf('&nbsp;<a href="signup.php?type=invite&invitenumber=%s" title="%s" target="_blank"><small>[%s]</small></a>', $arr1['hash'], $lang_invite['signup_link_help'], $lang_invite['signup_link']);
}
$tr = "<tr>"; $tr = "<tr>";
$tr .= "<td class=rowfollow>{$arr1['invitee']}</td>"; $tr .= "<td class=rowfollow>{$arr1['invitee']}</td>";
$tr .= "<td class=rowfollow>{$arr1['hash']}</td>"; $tr .= sprintf('<td class="rowfollow">%s%s</td>', $arr1['hash'], $registerLink);
$tr .= "<td class=rowfollow>{$arr1['time_invited']}</td>"; $tr .= "<td class=rowfollow>{$arr1['time_invited']}</td>";
$tr .= "<td class=rowfollow>".\App\Models\Invite::$validInfo[$arr1['valid']]['text']."</td>"; $tr .= "<td class=rowfollow>".\App\Models\Invite::$validInfo[$arr1['valid']]['text']."</td>";
if ($arr1['valid'] == \App\Models\Invite::VALID_NO) { if (!$isHashValid) {
$tr .= "<td class=rowfollow><a href=userdetails.php?id={$arr1['invitee_register_uid']}><font color=#1f7309>".$arr1['invitee_register_username']."</font></a></td>"; $tr .= "<td class=rowfollow><a href=userdetails.php?id={$arr1['invitee_register_uid']}><font color=#1f7309>".$arr1['invitee_register_username']."</font></a></td>";
} else { } else {
$tr .= "<td class='rowfollow'></td>"; $tr .= "<td class='rowfollow'></td>";