Added user banning
This commit is contained in:
parent
3268618f26
commit
31e0158606
12 changed files with 43 additions and 1 deletions
1
TODO
1
TODO
|
@ -62,7 +62,6 @@ everything related to posts:
|
|||
(move post snapshot factory methods to PostService)
|
||||
|
||||
everything related to users:
|
||||
- banning
|
||||
- show link to user's uploads
|
||||
- show link to user's favs
|
||||
- show link to user's liked posts
|
||||
|
|
|
@ -38,6 +38,7 @@ changeAllNames = moderator, administrator
|
|||
changeAllPasswords = moderator, administrator
|
||||
changeAccessRank = administrator
|
||||
viewAllEmailAddresses = moderator, administrator
|
||||
ban = moderator, administrator
|
||||
|
||||
listSafePosts = anonymous, regularUser, powerUser, moderator, administrator
|
||||
listSketchyPosts = anonymous, regularUser, powerUser, moderator, administrator
|
||||
|
|
|
@ -17,6 +17,7 @@ App.Auth = function(_, jQuery, util, api, appState, promise) {
|
|||
changeAllPasswords: 'changeAllPasswords',
|
||||
deleteOwnAccount: 'deleteOwnAccount',
|
||||
deleteAllAccounts: 'deleteAllAccounts',
|
||||
ban: 'ban',
|
||||
|
||||
listSafePosts: 'listSafePosts',
|
||||
listSketchyPosts: 'listSketchyPosts',
|
||||
|
|
|
@ -22,6 +22,8 @@ App.Presenters.UserAccountSettingsPresenter = function(
|
|||
target = args.target;
|
||||
|
||||
privileges = {
|
||||
canBan:
|
||||
auth.hasPrivilege(auth.privileges.ban),
|
||||
canChangeAccessRank:
|
||||
auth.hasPrivilege(auth.privileges.changeAccessRank),
|
||||
canChangeAvatarStyle:
|
||||
|
@ -105,6 +107,9 @@ App.Presenters.UserAccountSettingsPresenter = function(
|
|||
if (privileges.canChangeAccessRank) {
|
||||
formData.accessRank = $el.find('[name=access-rank]:checked').val();
|
||||
}
|
||||
if (privileges.canBan) {
|
||||
formData.banned = $el.find('[name=ban]').is(':checked') ? 1 : 0;
|
||||
}
|
||||
|
||||
if (!validateAccountSettingsFormData(formData)) {
|
||||
return;
|
||||
|
|
|
@ -67,6 +67,19 @@
|
|||
</div>
|
||||
<% } %>
|
||||
|
||||
<% if (canBan) { %>
|
||||
<div class="form-row">
|
||||
<label class="form-label" for="account-settings-ban">Ban:</label>
|
||||
<div class="form-input">
|
||||
<input name="ban" type="checkbox" id="ban" <% print(user.banned ? 'checked="checked"' : '') %>>
|
||||
<label for="ban">
|
||||
Enabled
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
|
||||
<% if (canChangeAccessRank) { %>
|
||||
<div class="form-row">
|
||||
<label class="form-label" for="account-settings-access-rank">Access rank:</label>
|
||||
|
|
|
@ -21,6 +21,7 @@ class UserViewProxy extends AbstractViewProxy
|
|||
$result->registrationTime = $user->getRegistrationTime();
|
||||
$result->lastLoginTime = $user->getLastLoginTime();
|
||||
$result->avatarStyle = \Szurubooru\Helpers\EnumHelper::avatarStyleToString($user->getAvatarStyle());
|
||||
$result->banned = $user->isBanned();
|
||||
|
||||
if ($this->privilegeService->isLoggedIn($user))
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@ class UserEntityConverter extends AbstractEntityConverter implements IEntityConv
|
|||
'avatarStyle' => $entity->getAvatarStyle(),
|
||||
'browsingSettings' => $entity->getBrowsingSettings(),
|
||||
'accountConfirmed' => $entity->isAccountConfirmed(),
|
||||
'banned' => $entity->isBanned(),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -34,6 +35,7 @@ class UserEntityConverter extends AbstractEntityConverter implements IEntityConv
|
|||
$entity->setAvatarStyle(intval($array['avatarStyle']));
|
||||
$entity->setBrowsingSettings($array['browsingSettings']);
|
||||
$entity->setAccountConfirmed($array['accountConfirmed']);
|
||||
$entity->setBanned($array['banned']);
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ final class User extends Entity
|
|||
protected $avatarStyle;
|
||||
protected $browsingSettings;
|
||||
protected $accountConfirmed = false;
|
||||
protected $banned = false;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
|
@ -57,6 +58,16 @@ final class User extends Entity
|
|||
$this->emailUnconfirmed = $emailUnconfirmed;
|
||||
}
|
||||
|
||||
public function isBanned()
|
||||
{
|
||||
return $this->banned;
|
||||
}
|
||||
|
||||
public function setBanned($banned)
|
||||
{
|
||||
$this->banned = boolval($banned);
|
||||
}
|
||||
|
||||
public function isAccountConfirmed()
|
||||
{
|
||||
return $this->accountConfirmed;
|
||||
|
|
|
@ -10,6 +10,7 @@ class UserEditFormData implements \Szurubooru\IValidatable
|
|||
public $avatarStyle;
|
||||
public $avatarContent;
|
||||
public $browsingSettings;
|
||||
public $banned;
|
||||
|
||||
public function __construct($inputReader = null)
|
||||
{
|
||||
|
@ -24,6 +25,7 @@ class UserEditFormData implements \Szurubooru\IValidatable
|
|||
$this->avatarStyle = \Szurubooru\Helpers\EnumHelper::avatarStyleFromString($inputReader->avatarStyle);
|
||||
$this->avatarContent = $inputReader->decodeBase64($inputReader->avatarContent);
|
||||
$this->browsingSettings = $inputReader->browsingSettings;
|
||||
$this->banned = boolval($inputReader->banned);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ class Privilege
|
|||
const CHANGE_ALL_PASSWORDS = 'changeAllPasswords';
|
||||
const DELETE_OWN_ACCOUNT = 'deleteOwnAccount';
|
||||
const DELETE_ALL_ACCOUNTS = 'deleteAllAccounts';
|
||||
const BAN = 'ban';
|
||||
|
||||
const LIST_SAFE_POSTS = 'listSafePosts';
|
||||
const LIST_SKETCHY_POSTS = 'listSketchyPosts';
|
||||
|
|
|
@ -101,5 +101,8 @@ class AuthService
|
|||
{
|
||||
if (!$user->isAccountConfirmed() and $this->config->security->needEmailActivationToRegister)
|
||||
throw new \DomainException('User didn\'t confirm account yet.');
|
||||
|
||||
if ($user->isBanned())
|
||||
throw new \DomainException('Banned!');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,6 +137,9 @@ class UserService
|
|||
if ($formData->browsingSettings !== null)
|
||||
$this->updateUserBrowsingSettings($user, $formData->browsingSettings);
|
||||
|
||||
if ($formData->banned !== $user->isBanned())
|
||||
$user->setBanned(boolval($formData->banned));
|
||||
|
||||
return $this->userDao->save($user);
|
||||
};
|
||||
return $this->transactionManager->commit($transactionFunc);
|
||||
|
|
Loading…
Reference in a new issue