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

View File

@@ -98,6 +98,7 @@ class HitAndRunRepository extends BaseRepository
$setting['diff_in_section'] = $diffInSection;
$setting['search_box_id'] = $browseMode;
$this->doCronjobUpdateStatus($setting, $uid, $torrentId, $ignoreTime);
$this->checkAndDisableUser($setting);
$specialMode = Setting::get('main.specialcat');
if ($diffInSection && $browseMode != $specialMode) {
@@ -105,6 +106,7 @@ class HitAndRunRepository extends BaseRepository
$setting['diff_in_section'] = $diffInSection;
$setting['search_box_id'] = $specialMode;
$this->doCronjobUpdateStatus($setting, $uid, $torrentId, $ignoreTime);
$this->checkAndDisableUser($setting);
}
}
@@ -333,37 +335,43 @@ class HitAndRunRepository extends BaseRepository
];
Message::query()->insert($message);
if (!$disableUser) {
do_log("[DO_NOT_DISABLE_USER], return");
return true;
}
if ($hitAndRun->user->enabled == 'no') {
do_log("[USER_ALREADY_DISABLED], return");
return true;
}
//disable user
/** @var User $user */
$user = $hitAndRun->user;
$countsQuery = $user->hitAndRuns()->where('status', HitAndRun::STATUS_UNREACHED);
return true;
}
private function checkAndDisableUser(array $setting): void
{
$disableCounts = HitAndRun::getConfig('ban_user_when_counts_reach', $setting['search_box_id']);
$query = HitAndRun::query()
->selectRaw("count(*) as counts, uid")
->where('status', HitAndRun::STATUS_UNREACHED)
->groupBy('uid')
->having("counts", '>=', $disableCounts)
;
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']);
});
}
$counts = $countsQuery->count();
$disableCounts = HitAndRun::getConfig('ban_user_when_counts_reach', $setting['search_box_id']);
do_log("user: {$user->id}, H&R counts: $counts, disableCounts: $disableCounts", 'notice');
if ($counts >= $disableCounts) {
do_log("[DISABLE_USER_DUE_TO_H&R_UNREACHED]", 'notice');
$comment = nexus_trans('hr.unreached_disable_comment', [], $user->locale);
$user->updateWithModComment(['enabled' => User::ENABLED_NO], $comment);
$result = $query->get();
if ($result->isEmpty()) {
do_log("No user to disable");
return;
}
$users = User::query()
->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 = [
'receiver' => $hitAndRun->uid,
'receiver' => $user->id,
'added' => Carbon::now()->toDateTimeString(),
'subject' => $comment,
'msg' => nexus_trans('hr.unreached_disable_message_content', [
'ban_user_when_counts_reach' => Setting::get('hr.ban_user_when_counts_reach'),
], $hitAndRun->user->locale),
], $locale),
];
Message::query()->insert($message);
$userBanLog = [
@@ -372,9 +380,8 @@ class HitAndRunRepository extends BaseRepository
'reason' => $comment
];
UserBanLog::query()->insert($userBanLog);
do_log("Disable user: " . nexus_json_encode($userBanLog));
}
return true;
}
public function getStatusStats($uid, $formatted = true)

View File

@@ -1,6 +1,6 @@
<?php
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('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");

View File

@@ -48,8 +48,9 @@ $lang_invite = array
'std_only' => "只有",
'std_or_above_can_invite' => "及以上的用户才能发送邀请。",
'text_email_restriction_note' => "你只能发送邀请给以下邮箱:",
'harem_addition' => '后宫加成',
'signup_link_help' => '右键复制',
'signup_link' => '注册链接',
);
?>

View File

@@ -49,6 +49,8 @@ $lang_invite = array
'std_or_above_can_invite' => "及以上的用戶才能發送邀請。",
'text_email_restriction_note' => "你只能發送邀請給以下郵箱:",
'harem_addition' => '後宮加成',
'signup_link_help' => '右鍵復製',
'signup_link' => '註冊鏈接',
);
?>

View File

@@ -52,6 +52,8 @@ Best Regards,
'std_or_above_can_invite' => " or above can send invitation.",
'text_email_restriction_note' => "You could only send invitation to email from those domains: ",
'harem_addition' => 'Harem addition',
'signup_link_help' => 'Right click to copy',
'signup_link' => 'Signup link',
);
?>

View File

@@ -166,12 +166,17 @@ if ($type == 'new'){
for ($i = 0; $i < $num1; ++$i)
{
$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 .= "<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>".\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>";
} else {
$tr .= "<td class='rowfollow'></td>";