From 73f9920e1fdb59cb24d489547e5a0363c9074590 Mon Sep 17 00:00:00 2001 From: xiaomlove <353856593@qq.com> Date: Sat, 15 May 2021 12:59:59 +0800 Subject: [PATCH] enable user handle leechwarn --- app/Models/User.php | 3 ++- app/Repositories/ToolRepository.php | 2 +- app/Repositories/UserRepository.php | 18 +++++++++++++++--- public/signup.php | 6 +++--- public/torrentrss.php | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 72848dbd..82da0210 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -82,7 +82,8 @@ class User extends Authenticatable * @var array */ protected $fillable = [ - 'username', 'email', 'passhash', 'secret', 'stylesheet', 'editsecret', 'added', 'modcomment', 'enabled', 'status' + 'username', 'email', 'passhash', 'secret', 'stylesheet', 'editsecret', 'added', 'modcomment', 'enabled', 'status', + 'leechwarn', 'leechwarnuntil' ]; /** diff --git a/app/Repositories/ToolRepository.php b/app/Repositories/ToolRepository.php index 0e5f9a5c..509921a6 100644 --- a/app/Repositories/ToolRepository.php +++ b/app/Repositories/ToolRepository.php @@ -153,7 +153,7 @@ class ToolRepository extends BaseRepository $filename = $backupResult['filename']; $upload_result = $filesystem->put(basename($filename), fopen($filename, 'r')); $backupResult['upload_result'] = $upload_result; - + do_log("Final result: " . json_encode($backupResult)); return $backupResult; } } diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 8105cd7d..5b34bcff 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -123,13 +123,25 @@ class UserRepository extends BaseRepository public function enableUser(User $operator, $uid) { - $targetUser = User::query()->findOrFail($uid, ['id', 'enabled', 'username']); + $targetUser = User::query()->findOrFail($uid, ['id', 'enabled', 'username', 'class']); if ($targetUser->enabled == User::ENABLED_YES) { throw new NexusException('Already enabled!'); } + $update = [ + 'enabled' => User::ENABLED_YES + ]; + if ($targetUser->class == User::CLASS_PEASANT) { + // warn users until 30 days + $until = now()->addDays(30)->toDateTimeString(); + $update['leechwarn'] = 'yes'; + $update['leechwarnuntil'] = $until; + } else { + $update['leechwarn'] = 'no'; + $update['leechwarnuntil'] = null; + } $modCommentText = sprintf("Enable by %s.", $operator->username); - $targetUser->updateWithModComment(['enabled' => User::ENABLED_YES], $modCommentText); - do_log("user: $uid, $modCommentText"); + $targetUser->updateWithModComment($update, $modCommentText); + do_log("user: $uid, $modCommentText, update: " . nexus_json_encode($update)); return true; } diff --git a/public/signup.php b/public/signup.php index a2e20092..eb7fa50a 100644 --- a/public/signup.php +++ b/public/signup.php @@ -14,7 +14,7 @@ if ($langid) } require_once(get_langfile_path("", false, $CURLANGDIR)); cur_user_check (); -$type = $_GET['type']; +$type = $_GET['type'] ?? ''; if ($type == 'invite') { registration_check(); @@ -32,7 +32,7 @@ if ($type == 'invite') $dom = $tldm[2]; } - $sq = sprintf("SELECT inviter FROM invites WHERE hash ='%s'",mysql_real_escape_string($code)); + $sq = sprintf("SELECT inviter FROM invites WHERE valid = %s and hash ='%s'", \App\Models\Invite::VALID_YES, mysql_real_escape_string($code)); $res = sql_query($sq) or sqlerr(__FILE__, __LINE__); $inv = mysql_fetch_assoc($res); $inviter = htmlspecialchars($inv["inviter"]); @@ -87,7 +87,7 @@ show_image_code (); $ct_r = sql_query("SELECT id,name FROM countries ORDER BY name") or die; while ($ct_a = mysql_fetch_array($ct_r)) $countries .= "n"; -tr($lang_signup['row_country'], "", 1); +tr($lang_signup['row_country'], "", 1); //School select if ($showschool == 'yes'){ $schools = "n"; diff --git a/public/torrentrss.php b/public/torrentrss.php index 55035dd3..918b4909 100644 --- a/public/torrentrss.php +++ b/public/torrentrss.php @@ -17,7 +17,7 @@ if ($passkey){ die("invalid passkey"); elseif ($user['enabled'] == 'no' || $user['parked'] == 'yes') die("account disabed or parked"); - elseif ($_GET['linktype'] == 'dl') + elseif (isset($_GET['linktype']) && $_GET['linktype'] == 'dl') $dllink = true; $inclbookmarked=intval($_GET['inclbookmarked'] ?? 0); if($inclbookmarked == 1)