diff --git a/TODO b/TODO
index 785a3fb9..5dc4e26b 100644
--- a/TODO
+++ b/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
diff --git a/data/config.ini b/data/config.ini
index ddaa77c1..d634d50a 100644
--- a/data/config.ini
+++ b/data/config.ini
@@ -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
diff --git a/public_html/js/Auth.js b/public_html/js/Auth.js
index 0b8a8100..65eeb07a 100644
--- a/public_html/js/Auth.js
+++ b/public_html/js/Auth.js
@@ -17,6 +17,7 @@ App.Auth = function(_, jQuery, util, api, appState, promise) {
changeAllPasswords: 'changeAllPasswords',
deleteOwnAccount: 'deleteOwnAccount',
deleteAllAccounts: 'deleteAllAccounts',
+ ban: 'ban',
listSafePosts: 'listSafePosts',
listSketchyPosts: 'listSketchyPosts',
diff --git a/public_html/js/Presenters/UserAccountSettingsPresenter.js b/public_html/js/Presenters/UserAccountSettingsPresenter.js
index 44b362bc..8baedc22 100644
--- a/public_html/js/Presenters/UserAccountSettingsPresenter.js
+++ b/public_html/js/Presenters/UserAccountSettingsPresenter.js
@@ -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;
diff --git a/public_html/templates/account-settings.tpl b/public_html/templates/account-settings.tpl
index 8d259d5b..83157b15 100644
--- a/public_html/templates/account-settings.tpl
+++ b/public_html/templates/account-settings.tpl
@@ -67,6 +67,19 @@
<% } %>
+ <% if (canBan) { %>
+
+ <% } %>
+
+
<% if (canChangeAccessRank) { %>
diff --git a/src/Controllers/ViewProxies/UserViewProxy.php b/src/Controllers/ViewProxies/UserViewProxy.php
index 8fd0d2b4..27e8b07b 100644
--- a/src/Controllers/ViewProxies/UserViewProxy.php
+++ b/src/Controllers/ViewProxies/UserViewProxy.php
@@ -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))
{
diff --git a/src/Dao/EntityConverters/UserEntityConverter.php b/src/Dao/EntityConverters/UserEntityConverter.php
index d2057a9e..0e7d2695 100644
--- a/src/Dao/EntityConverters/UserEntityConverter.php
+++ b/src/Dao/EntityConverters/UserEntityConverter.php
@@ -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;
}
}
diff --git a/src/Entities/User.php b/src/Entities/User.php
index 40889c0d..c8f70c85 100644
--- a/src/Entities/User.php
+++ b/src/Entities/User.php
@@ -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;
diff --git a/src/FormData/UserEditFormData.php b/src/FormData/UserEditFormData.php
index 573d283a..9a25832f 100644
--- a/src/FormData/UserEditFormData.php
+++ b/src/FormData/UserEditFormData.php
@@ -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);
}
}
diff --git a/src/Privilege.php b/src/Privilege.php
index 88599efb..070f2da1 100644
--- a/src/Privilege.php
+++ b/src/Privilege.php
@@ -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';
diff --git a/src/Services/AuthService.php b/src/Services/AuthService.php
index 1bdc753e..e745c402 100644
--- a/src/Services/AuthService.php
+++ b/src/Services/AuthService.php
@@ -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!');
}
}
diff --git a/src/Services/UserService.php b/src/Services/UserService.php
index 34ad0fe5..d98b2fcb 100644
--- a/src/Services/UserService.php
+++ b/src/Services/UserService.php
@@ -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);