enable user handle leechwarn

This commit is contained in:
xiaomlove
2021-05-15 12:59:59 +08:00
parent 682cf806d7
commit 73f9920e1f
5 changed files with 22 additions and 9 deletions
+15 -3
View File
@@ -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;
}