Add quickban button for admins

This commit is contained in:
Alma Armas 2020-07-17 16:26:59 +00:00
parent fafc3b4fb9
commit af6eeb882c
4 changed files with 60 additions and 1 deletions

View file

@ -517,6 +517,21 @@ class User extends RowModel
return !is_null($this->getPendingPhoneVerification()); return !is_null($this->getPendingPhoneVerification());
} }
function ban(string $reason): void
{
$subs = DatabaseConnection::i()->getContext()->table("subscriptions");
$subs = $subs->where(
"follower = ? OR (target = ? AND model = ?)",
$this->getId(),
$this->getId(),
get_class($this),
);
$subs->delete();
$this->setBlock_Reason($reason);
$this->save();
}
function verifyNumber(string $code): bool function verifyNumber(string $code): bool
{ {
$ver = $this->getPendingPhoneVerification(); $ver = $this->getPendingPhoneVerification();

View file

@ -27,7 +27,9 @@ final class AdminPresenter extends OpenVKPresenter
function onStartup(): void function onStartup(): void
{ {
exit("Не реализовано..."); parent::onStartup();
$this->assertPermission("admin", "access", -1);
} }
function renderIndex(): void function renderIndex(): void
@ -82,4 +84,14 @@ final class AdminPresenter extends OpenVKPresenter
{ {
} }
function renderQuickBan(int $id): void
{
$user = $this->users->get($id);
if(!$user)
exit(json_encode([ "error" => "User does not exist" ]));
$user->ban($this->queryParam("reason"));
exit(json_encode([ "reason" => $this->queryParam("reason") ]));
}
} }

View file

@ -72,6 +72,12 @@
</a> </a>
{/if} {/if}
{if $thisUser->getChandlerUser()->can("access")->model("admin")->whichBelongsTo(NULL)}
<a href="javascript:banUser()" class="profile_link">
Забанить пользователя
</a>
{/if}
{var subStatus = $user->getSubscriptionStatus($thisUser)} {var subStatus = $user->getSubscriptionStatus($thisUser)}
{if $subStatus === 0} {if $subStatus === 0}
<form action="/setSub/user" method="post"> <form action="/setSub/user" method="post">
@ -445,6 +451,30 @@
</div> </div>
{presenter "openvk!Wall->wall", $user->getId()} {presenter "openvk!Wall->wall", $user->getId()}
<script n:if="isset($thisUser) && $thisUser->getChandlerUser()->can('access')->model('admin')->whichBelongsTo(NULL)">
function banUser() {
uBanMsgTxt = "Вы собираетесь забанить пользователя " + {$user->getCanonicalName()} + ".";
uBanMsgTxt += "<br/><b>Предупреждение</b>: Это действие удалит все подписки пользователя и отпишет всех от него.";
uBanMsgTxt += "<br/><br/><b>Причина бана</b>: <input type='text' id='uBanMsgInput' placeholder='насрал в штаны' />"
MessageBox("Забанить " + {$user->getFirstName()}, uBanMsgTxt, ["Подтвердить", "Отмена"], [
(function() {
res = document.querySelector("#uBanMsgInput").value;
xhr = new XMLHttpRequest();
xhr.open("GET", "/admin/ban.pl/" + {$user->getId()} + "?reason=" + res, true);
xhr.onload = (function() {
if(xhr.responseText.indexOf("reason") === -1)
MessageBox("Ошибка", "Не удалось забанить пользователя...", ["OK"], [Function.noop]);
else
MessageBox("Операция успешна", "Пользователь заблокирован", ["OK"], [Function.noop]);
});
xhr.send(null);
}),
Function.noop
])
}
</script>
</div> </div>
{/if} {/if}

View file

@ -191,6 +191,8 @@ routes:
handler: "Admin->clubs" handler: "Admin->clubs"
- url: "/admin/clubs/id{num}" - url: "/admin/clubs/id{num}"
handler: "Admin->club" handler: "Admin->club"
- url: "/admin/ban.pl/{num}"
handler: "Admin->quickBan"
- url: "/sandbox_cocksex" - url: "/sandbox_cocksex"
handler: "About->sandbox" handler: "About->sandbox"
- url: "/{?shortCode}" - url: "/{?shortCode}"