mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
parent
324297db7e
commit
a935b2ca31
10 changed files with 71 additions and 10 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 ]));
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -17,7 +17,6 @@ final class UserPresenter extends OpenVKPresenter
|
|||
private $users;
|
||||
|
||||
public $deactivationTolerant = false;
|
||||
|
||||
function __construct(Users $users)
|
||||
{
|
||||
$this->users = $users;
|
||||
|
|
|
@ -12,6 +12,16 @@
|
|||
<p>
|
||||
{tr("banned_1", htmlentities($thisUser->getCanonicalName()))|noescape}<br/>
|
||||
{tr("banned_2", htmlentities($thisUser->getBanReason()))|noescape}
|
||||
|
||||
{if !$thisUser->getUnbanTime()}
|
||||
{_banned_perm}
|
||||
{else}
|
||||
{tr("banned_until_time", $thisUser->getUnbanTime())|noescape}
|
||||
{/if}
|
||||
</p>
|
||||
<p n:if="$thisUser->canUnbanThemself()">
|
||||
<hr/>
|
||||
<center><a class="button" href="/unban.php">{_banned_unban_myself}</a></center>
|
||||
</p>
|
||||
<hr/>
|
||||
<p>
|
||||
|
|
|
@ -543,12 +543,14 @@
|
|||
uBanMsgTxt = "Вы собираетесь забанить пользователя " + {$user->getCanonicalName()} + ".";
|
||||
uBanMsgTxt += "<br/><b>Предупреждение</b>: Это действие удалит все подписки пользователя и отпишет всех от него.";
|
||||
uBanMsgTxt += "<br/><br/><b>Причина бана</b>: <input type='text' id='uBanMsgInput' placeholder='придумайте что-нибудь крутое' />"
|
||||
|
||||
uBanMsgTxt += "<br/><br/><b>Заблокировать до</b>: <input type='date' id='uBanMsgDate' />";
|
||||
|
||||
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]);
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
<img src="/assets/packages/static/openvk/img/oof.apng" alt="Пользователь заблокирован." style="width: 20%;" />
|
||||
<p>
|
||||
{tr("user_banned", htmlentities($user->getFirstName()))|noescape}<br/>
|
||||
{_user_banned_comment} <b>{$user->getBanReason()}</b>.
|
||||
{_user_banned_comment} <b>{$user->getBanReason()}</b>.<br/>
|
||||
Пользователь заблокирован до: <b>{$user->getUnbanTime()}</b>
|
||||
</p>
|
||||
{if isset($thisUser)}
|
||||
<p n:if="$thisUser->getChandlerUser()->can('access')->model('admin')->whichBelongsTo(NULL) || $thisUser->getChandlerUser()->can('write')->model('openvk\Web\Models\Entities\TicketReply')->whichBelongsTo(0)">
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -842,8 +842,13 @@
|
|||
"banned_header" = "You are banned";
|
||||
"banned_alt" = "The user is blocked.";
|
||||
"banned_1" = "Sorry <b>$1</b>, but you have been banned.";
|
||||
"banned_2" = "And the reason for this is simple: <b>$1</b>. Unfortunately, this time we had to block you forever.";
|
||||
"banned_2" = "And the reason for this is simple: <b>$1</b>.";
|
||||
"banned_perm" = "Unfortunately, this time we had to block you forever.";
|
||||
"banned_until_time" = "This time we had to block you until <b>$1</b>";
|
||||
"banned_3" = "You can still <a href=\"/support?act=new\">write to the support</a> if you think there was an error or <a href=\"/logout?hash=$1\">logout</a>.";
|
||||
"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 */
|
||||
|
||||
|
|
|
@ -887,8 +887,13 @@
|
|||
"banned_header" = "Вы были верискокнуты";
|
||||
"banned_alt" = "Пользователь заблокирован.";
|
||||
"banned_1" = "Извините, <b>$1</b>, но вы были верискокнуты.";
|
||||
"banned_2" = "А причина этому проста: <b>$1</b>. К сожалению, на этот раз нам пришлось заблокировать вас навсегда.";
|
||||
"banned_2" = "А причина этому проста: <b>$1</b>.";
|
||||
"banned_perm" = "К сожалению, на этот раз нам пришлось заблокировать вас навсегда";
|
||||
"banned_until_time" = "На этот раз нам пришлось заблокировать вас до <b>$1</b>";
|
||||
"banned_3" = "Вы всё ещё можете <a href=\"/support?act=new\">написать в службу поддержки</a>, если считаете что произошла ошибка или <a href=\"/logout?hash=$1\">выйти</a>.";
|
||||
"banned_unban_myself" = "Разморозить страницу";
|
||||
"banned_unban_title" = "Ваш аккаунт разблокирован";
|
||||
"banned_unban_description" = "Постарайтесь больше не нарушать правила.";
|
||||
|
||||
/* Registration confirm */
|
||||
|
||||
|
|
Loading…
Reference in a new issue