diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index 44db0cd9..115bf8c2 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -768,7 +768,7 @@ class User extends RowModel ]); } - function ban(string $reason, bool $deleteSubscriptions = true): void + function ban(string $reason, bool $deleteSubscriptions = true, ?int $unban_time = NULL): void { if($deleteSubscriptions) { $subs = DatabaseConnection::i()->getContext()->table("subscriptions"); @@ -782,6 +782,7 @@ class User extends RowModel } $this->setBlock_Reason($reason); + $this->setUnblock_time($unban_time); $this->save(); } @@ -1017,6 +1018,22 @@ class User extends RowModel { return (bool) $this->getRecord()->activated; } + + function getUnbanTime(): ?string + { + return !is_null($this->getRecord()->unblock_time) ? date('d.m.Y', $this->getRecord()->unblock_time) : NULL; + } + + function canUnbanThemself(): bool + { + if (!$this->isBanned()) + return false; + + if ($this->getRecord()->unblock_time > time() || $this->getRecord()->unblock_time == 0) + return false; + + return true; + } use Traits\TSubscribable; } diff --git a/Web/Presenters/AdminPresenter.php b/Web/Presenters/AdminPresenter.php index 4a484a4d..27b0bf09 100644 --- a/Web/Presenters/AdminPresenter.php +++ b/Web/Presenters/AdminPresenter.php @@ -339,12 +339,14 @@ final class AdminPresenter extends OpenVKPresenter function renderQuickBan(int $id): void { $this->assertNoCSRF(); - + + $unban_time = strtotime($this->queryParam("date")) ?: NULL; + $user = $this->users->get($id); if(!$user) exit(json_encode([ "error" => "User does not exist" ])); - $user->ban($this->queryParam("reason")); + $user->ban($this->queryParam("reason"), true, $unban_time); exit(json_encode([ "success" => true, "reason" => $this->queryParam("reason") ])); } @@ -356,7 +358,8 @@ final class AdminPresenter extends OpenVKPresenter if(!$user) exit(json_encode([ "error" => "User does not exist" ])); - $user->setBlock_Reason(null); + $user->setBlock_Reason(NULL); + $user->setUnblock_time(NULL); $user->save(); exit(json_encode([ "success" => true ])); } diff --git a/Web/Presenters/AuthPresenter.php b/Web/Presenters/AuthPresenter.php index 3fe6e66c..f934f7fe 100644 --- a/Web/Presenters/AuthPresenter.php +++ b/Web/Presenters/AuthPresenter.php @@ -323,6 +323,23 @@ final class AuthPresenter extends OpenVKPresenter $this->redirect("/"); } + function renderUnbanThemself(): void + { + $this->assertUserLoggedIn(); + $this->willExecuteWriteAction(); + + if(!$this->user->identity->canUnbanThemself()) + $this->flashFail("err", tr("error"), tr("forbidden")); + + $user = $this->users->get($this->user->id); + + $user->setBlock_Reason(NULL); + $user->setUnblock_Time(NULL); + $user->save(); + + $this->flashFail("succ", tr("banned_unban_title"), tr("banned_unban_description")); + } + /* * This function will revoke all tokens, including API and Web tokens and except active one * diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index 3832607f..bfda79e8 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -17,7 +17,6 @@ final class UserPresenter extends OpenVKPresenter private $users; public $deactivationTolerant = false; - function __construct(Users $users) { $this->users = $users; diff --git a/Web/Presenters/templates/@banned.xml b/Web/Presenters/templates/@banned.xml index c3c894d3..48c29ddb 100644 --- a/Web/Presenters/templates/@banned.xml +++ b/Web/Presenters/templates/@banned.xml @@ -12,6 +12,16 @@
{tr("banned_1", htmlentities($thisUser->getCanonicalName()))|noescape}
{tr("banned_2", htmlentities($thisUser->getBanReason()))|noescape}
+
+ {if !$thisUser->getUnbanTime()}
+ {_banned_perm}
+ {else}
+ {tr("banned_until_time", $thisUser->getUnbanTime())|noescape}
+ {/if}
+
+
diff --git a/Web/Presenters/templates/User/View.xml b/Web/Presenters/templates/User/View.xml
index a2b8cb0d..fb38133d 100644
--- a/Web/Presenters/templates/User/View.xml
+++ b/Web/Presenters/templates/User/View.xml
@@ -543,12 +543,14 @@
uBanMsgTxt = "Вы собираетесь забанить пользователя " + {$user->getCanonicalName()} + ".";
uBanMsgTxt += "
Предупреждение: Это действие удалит все подписки пользователя и отпишет всех от него.";
uBanMsgTxt += "
Причина бана: "
-
+ uBanMsgTxt += "
Заблокировать до: ";
+
MessageBox("Забанить " + {$user->getFirstName()}, uBanMsgTxt, ["Подтвердить", "Отмена"], [
(function() {
res = document.querySelector("#uBanMsgInput").value;
+ date = document.querySelector("#uBanMsgDate").value;
xhr = new XMLHttpRequest();
- xhr.open("GET", "/admin/ban/" + {$user->getId()} + "?reason=" + res + "&hash=" + {rawurlencode($csrfToken)}, true);
+ xhr.open("GET", "/admin/ban/" + {$user->getId()} + "?reason=" + res + "&date=" + date + "&hash=" + {rawurlencode($csrfToken)}, true);
xhr.onload = (function() {
if(xhr.responseText.indexOf("success") === -1)
MessageBox("Ошибка", "Не удалось забанить пользователя...", ["OK"], [Function.noop]);
diff --git a/Web/Presenters/templates/User/banned.xml b/Web/Presenters/templates/User/banned.xml
index d1d5eef7..a495a59d 100644
--- a/Web/Presenters/templates/User/banned.xml
+++ b/Web/Presenters/templates/User/banned.xml
@@ -2,7 +2,8 @@
{tr("user_banned", htmlentities($user->getFirstName()))|noescape}
- {_user_banned_comment} {$user->getBanReason()}.
+ {_user_banned_comment} {$user->getBanReason()}.
+ Пользователь заблокирован до: {$user->getUnbanTime()}
diff --git a/Web/routes.yml b/Web/routes.yml index 99c918c2..0e5398f8 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -65,6 +65,8 @@ routes: handler: "Auth->verifyEmail" - url: "/setSID/{slug}" handler: "Auth->su" + - url: "/unban.php" + handler: "Auth->unbanThemself" - url: "/revokeAllTokens" handler: "Auth->revokeAllTokens" - url: "/settings" diff --git a/locales/en.strings b/locales/en.strings index 88fa02a7..ba11c73e 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -842,8 +842,13 @@ "banned_header" = "You are banned"; "banned_alt" = "The user is blocked."; "banned_1" = "Sorry $1, but you have been banned."; -"banned_2" = "And the reason for this is simple: $1. Unfortunately, this time we had to block you forever."; +"banned_2" = "And the reason for this is simple: $1."; +"banned_perm" = "Unfortunately, this time we had to block you forever."; +"banned_until_time" = "This time we had to block you until $1"; "banned_3" = "You can still write to the support if you think there was an error or logout."; +"banned_unban_myself" = "Unban myself"; +"banned_unban_title" = "Your account has been unbanned"; +"banned_unban_description" = "Try not to break the rules anymore."; /* Registration confirm */ diff --git a/locales/ru.strings b/locales/ru.strings index a5500a0f..4e55715e 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -887,8 +887,13 @@ "banned_header" = "Вы были верискокнуты"; "banned_alt" = "Пользователь заблокирован."; "banned_1" = "Извините, $1, но вы были верискокнуты."; -"banned_2" = "А причина этому проста: $1. К сожалению, на этот раз нам пришлось заблокировать вас навсегда."; +"banned_2" = "А причина этому проста: $1."; +"banned_perm" = "К сожалению, на этот раз нам пришлось заблокировать вас навсегда"; +"banned_until_time" = "На этот раз нам пришлось заблокировать вас до $1"; "banned_3" = "Вы всё ещё можете написать в службу поддержки, если считаете что произошла ошибка или выйти."; +"banned_unban_myself" = "Разморозить страницу"; +"banned_unban_title" = "Ваш аккаунт разблокирован"; +"banned_unban_description" = "Постарайтесь больше не нарушать правила."; /* Registration confirm */