diff --git a/app/Models/BonusLogs.php b/app/Models/BonusLogs.php index 17d55355..472a0b20 100644 --- a/app/Models/BonusLogs.php +++ b/app/Models/BonusLogs.php @@ -21,6 +21,7 @@ class BonusLogs extends NexusModel const DEFAULT_BONUS_BUY_TEMPORARY_INVITE = 500; const DEFAULT_BONUS_BUY_RAINBOW_ID = 5000; const DEFAULT_BONUS_BUY_CHANGE_USERNAME_CARD = 100000; + const DEFAULT_BONUS_SELF_ENABLE = 100000; //扣除类,1开始 const BUSINESS_TYPE_CANCEL_HIT_AND_RUN = 1; @@ -46,6 +47,7 @@ class BonusLogs extends NexusModel const BUSINESS_TYPE_TASK_PASS_REWARD = 21; const BUSINESS_TYPE_REWARD_TORRENT = 22; const BUSINESS_TYPE_CLAIMED_UNREACHED = 23; + const BUSINESS_TYPE_SELF_ENABLE = 24; //获得类,普通获得,1000 起步 const BUSINESS_TYPE_ROLE_WORK_SALARY = 1000; @@ -87,6 +89,7 @@ class BonusLogs extends NexusModel self::BUSINESS_TYPE_TASK_PASS_REWARD => ['text' => 'Task success reward'], self::BUSINESS_TYPE_REWARD_TORRENT => ['text' => 'Reward torrent'], self::BUSINESS_TYPE_CLAIMED_UNREACHED => ['text' => 'Claimed torrent unreached'], + self::BUSINESS_TYPE_SELF_ENABLE => ['text' => 'Self enable'], self::BUSINESS_TYPE_ROLE_WORK_SALARY => ['text' => 'Role work salary'], self::BUSINESS_TYPE_TORRENT_BE_DOWNLOADED => ['text' => 'Torrent be downloaded'], diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 1490cfdb..b6c40d8e 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -334,4 +334,9 @@ class Setting extends NexusModel { return self::get('main.showimdbinfo') == 'yes'; } + + public static function getSelfEnableBonus(): int + { + return (int)self::get("bonus.self_enable", BonusLogs::DEFAULT_BONUS_SELF_ENABLE); + } } diff --git a/app/Models/UserBanLog.php b/app/Models/UserBanLog.php index 081ed06b..6fa74a5b 100644 --- a/app/Models/UserBanLog.php +++ b/app/Models/UserBanLog.php @@ -8,6 +8,8 @@ class UserBanLog extends NexusModel protected $fillable = ['uid', 'username', 'operator', 'reason']; + public $timestamps = true; + public static function clearUserBanLogDuplicate() { $lists = UserBanLog::query() diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index a3b2dfb4..a04846aa 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -2,7 +2,6 @@ namespace App\Repositories; use App\Enums\ModelEventEnum; -use App\Enums\RedisKeysEnum; use App\Exceptions\InsufficientPermissionException; use App\Exceptions\NexusException; use App\Http\Resources\ExamUserResource; @@ -29,7 +28,6 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Str; use Nexus\Database\NexusDB; @@ -228,9 +226,9 @@ class UserRepository extends BaseRepository 'operator' => $operator->id, ]; $modCommentText = sprintf("%s - Disable by %s, reason: %s.", now()->format('Y-m-d'), $operator->username, $reason); - DB::transaction(function () use ($targetUser, $banLog, $modCommentText) { + NexusDB::transaction(function () use ($targetUser, $banLog, $modCommentText) { $targetUser->updateWithModComment(['enabled' => User::ENABLED_NO], $modCommentText); - UserBanLog::query()->insert($banLog); + UserBanLog::query()->create($banLog); }); do_log("user: $uid, $modCommentText"); $this->clearCache($targetUser); diff --git a/include/functions.php b/include/functions.php index cd362786..db018608 100644 --- a/include/functions.php +++ b/include/functions.php @@ -2072,7 +2072,6 @@ function userlogin() { if (empty($row)) { return $loginResult = false; } - if (!$row["passkey"]){ $passkey = md5($row['username'].date("Y-m-d H:i:s").$row['passhash']); sql_query("UPDATE users SET passkey = ".sqlesc($passkey)." WHERE id=" . sqlesc($row["id"])); @@ -2093,6 +2092,9 @@ function userlogin() { // error_reporting(E_ALL & ~E_NOTICE); // error_reporting(-1); // } + if ($row['enabled'] !== 'yes') { + + } return $loginResult = true; } @@ -3168,8 +3170,9 @@ function base64 ($string, $encode=true) { function loggedinorreturn($mainpage = false) { global $CURUSER,$BASEURL; + $script = nexus()->getScript(); if (!$CURUSER) { - if (nexus()->getScript() == 'ajax') { + if ($script == 'ajax') { exit(fail('Not login!', $_POST)); } if ($mainpage) { @@ -3181,7 +3184,9 @@ function loggedinorreturn($mainpage = false) { } exit(); } -// do_log("[USER]: " . $CURUSER['id']); + if ($CURUSER['enabled'] != 'yes' && $script != 'self-enable') { + nexus_redirect('self-enable.php'); + } } function deletetorrent($id, $notify = false) { diff --git a/include/globalfunctions.php b/include/globalfunctions.php index 6add1f01..d417edaf 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -1505,8 +1505,15 @@ function get_user_from_cookie(array $cookie, $isArray = true): array|\App\Models $tokenJson = $result['token_json']; $signature = $result['signature']; $log .= ", uid = $id"; + $isAjax = nexus()->isAjax(); + //only in nexus web can self-enable + $shouldIgnoreEnabled = IN_NEXUS && !$isAjax; if ($isArray) { - $res = sql_query("SELECT * FROM users WHERE users.id = ".sqlesc($id)." AND users.enabled='yes' AND users.status = 'confirmed' LIMIT 1"); + $whereStr = sprintf("id = %d and status = 'confirmed'", $id); + if (!$shouldIgnoreEnabled) { + $whereStr .= " and enabled = 'yes'"; + } + $res = sql_query("SELECT * FROM users WHERE $whereStr LIMIT 1"); $row = mysql_fetch_array($res); if (!$row) { do_log("$log, user not exists"); @@ -1520,7 +1527,11 @@ function get_user_from_cookie(array $cookie, $isArray = true): array|\App\Models do_log("$log, user not exists"); return null; } - $row->checkIsNormal(); + $checkFields = ['status']; + if (!$shouldIgnoreEnabled) { + $checkFields[] = 'enabled'; + } + $row->checkIsNormal($checkFields); $authKey = $row->auth_key; } $expectedSignature = hash_hmac('sha256', $tokenJson, $authKey); diff --git a/lang/chs/lang_settings.php b/lang/chs/lang_settings.php index 1ce174f7..186bcf2e 100644 --- a/lang/chs/lang_settings.php +++ b/lang/chs/lang_settings.php @@ -826,6 +826,8 @@ $lang_settings = array 'text_reward_bonus_options_note' => '种子详情页的魔力值奖励选项,多个用英文逗号分割', 'row_reward_times_limit' => '魔力奖励次数限制', 'text_reward_times_limit_note' => '种子详情页的魔力奖励每人每天次数限制,设置为 0 不限制。默认:0', + 'row_self_enable' => '自助解封', + 'text_self_enable_note' => '个魔力值,如果他选择在被封禁 1 天内解封。封禁时长为 N 天,失去的魔力值将会是此值的 N 倍。', ); ?> diff --git a/lang/cht/lang_settings.php b/lang/cht/lang_settings.php index 1def0ca8..ddb111fb 100644 --- a/lang/cht/lang_settings.php +++ b/lang/cht/lang_settings.php @@ -826,6 +826,8 @@ $lang_settings = array 'text_reward_bonus_options_note' => '種子詳情頁的魔力值獎勵選項,多個用英文逗號分割', 'row_reward_times_limit' => '魔力獎勵次數限制', 'text_reward_times_limit_note' => '種子詳情頁的魔力獎勵每人每天次數限制,設置爲 0 不限制。默認:0', + 'row_self_enable' => '自助解封', + 'text_self_enable_note' => '個魔力值,如果他選擇在被封禁 1 天內解封。封禁時長為 N 天,失去的魔力值將會是此值的 N 倍。', ); ?> diff --git a/lang/en/lang_settings.php b/lang/en/lang_settings.php index c6688550..e1c2b10c 100644 --- a/lang/en/lang_settings.php +++ b/lang/en/lang_settings.php @@ -826,6 +826,8 @@ $lang_settings = array 'text_reward_bonus_options_note' => 'Reward bonus options on the torrent details page, multiple options separated by commas', 'row_reward_times_limit' => 'Reward Frequency Limit', 'text_reward_times_limit_note' => 'Daily limit per user for bonus rewards on seed detail pages. Set to 0 for no limit. Default: 0', + 'row_self_enable' => 'Self-service unblocking', + 'text_self_enable_note' => 'points. If he chooses to unblock within 1 day of being banned. If the ban duration is N days, the lost mana points will be N times this value.', ); ?> diff --git a/nexus/Nexus.php b/nexus/Nexus.php index 281b5892..af6b944a 100644 --- a/nexus/Nexus.php +++ b/nexus/Nexus.php @@ -176,6 +176,22 @@ final class Nexus return false; } + public function isAjax(): bool + { + if ($this->getScript() == 'ajax') { + return true; + } + $ajax = $this->retrieveFromServer(['HTTP_X_REQUESTED_WITH'], true); + if (!empty($ajax) && strtolower($ajax) == 'xmlhttprequest') { + return true; + } + $json = $this->retrieveFromServer(['HTTP_ACCEPT'], true); + if (!empty($json) && strtolower($json) == 'application/json') { + return true; + } + return false; + } + private function generateRequestId(): string { $prefix = ($_SERVER['SCRIPT_FILENAME'] ?? '') . implode('', $_SERVER['argv'] ?? []); @@ -426,4 +442,6 @@ final class Nexus } + + } diff --git a/public/self-enable.php b/public/self-enable.php new file mode 100644 index 00000000..e632318a --- /dev/null +++ b/public/self-enable.php @@ -0,0 +1,62 @@ +%s', nexus_trans('self-enable.enable_status_normal')); +} else { + $latestBanLog = \App\Models\UserBanLog::query() + ->where('uid', $CURUSER['id']) + ->orderBy('id', 'desc') + ->first(); + if (!$latestBanLog) { + printf('
| UID: | %s |
|---|---|
| Username: | %s |
| Reason: | %s |
| CreatedAt: | %s |
%s
', nexus_trans('self-enable.deduct_bonus_per_day', ['unit' => number_format($unit)])); + printf('%s
', nexus_trans('self-enable.deduct_bonus_total', ['days' => number_format($elapsedDay), 'total' => number_format($total)])); + if ($isUserBonusEnough) { + printf('%s
', nexus_trans('self-enable.enable_desc')); + printf('', nexus_trans('self-enable.enable_button')); + } else { + printf('%s
', $userBonusNotEnoughTip); + } + } + } +} +end_frame(); +end_main_frame(); +stdfoot(); +?> diff --git a/public/settings.php b/public/settings.php index f77c0346..82b4ef99 100644 --- a/public/settings.php +++ b/public/settings.php @@ -99,7 +99,7 @@ elseif ($action == 'savesettings_bonus') // save bonus 'tengbupload', 'ratiolimit','dlamountlimit','oneinvite','customtitle','vipstatus','bonusgift', 'basictax', 'taxpercentage', 'prolinkpoint', 'prolinktime', 'attendance_initial', 'attendance_step', 'attendance_max', 'cancel_hr', 'attendance_card', 'harem_addition', 'hundredgbupload', 'tengbdownload', 'hundredgbdownload', 'official_addition', 'official_tag', 'zero_bonus_tag', 'zero_bonus_factor', - 'one_tmp_invite', 'rainbow_id', 'change_username_card', 'min_size' + 'one_tmp_invite', 'rainbow_id', 'change_username_card', 'min_size', 'self_enable' ); GetVar($validConfig); $BONUS = []; @@ -630,6 +630,7 @@ elseif ($action == 'bonussettings'){ tr($lang_settings['row_attendance_card'],$lang_settings['text_it_costs_user']."".$lang_settings['text_attendance_card_note'], 1); tr($lang_settings['row_buy_rainbow_id'],$lang_settings['text_it_costs_user']."".$lang_settings['text_buy_rainbow_id_note'], 1); tr($lang_settings['row_buy_change_username_card'],$lang_settings['text_it_costs_user']."".$lang_settings['text_buy_change_username_card_note'], 1); + tr($lang_settings['row_self_enable'],$lang_settings['text_it_costs_user']."".$lang_settings['text_self_enable_note'], 1); echo '