Change work with ban by username
This commit is contained in:
parent
8b6cbdde1c
commit
68b12a6241
9 changed files with 41 additions and 17 deletions
|
@ -27,7 +27,10 @@ class Primary
|
|||
*/
|
||||
public function check(): ?Page
|
||||
{
|
||||
if ($this->c->config->o_maintenance && ! $this->c->MAINTENANCE_OFF) {
|
||||
if (
|
||||
$this->c->config->o_maintenance
|
||||
&& ! $this->c->MAINTENANCE_OFF
|
||||
) {
|
||||
if (
|
||||
! isset($this->c->admins->list[$this->c->Cookie->uId])
|
||||
|| ! isset($this->c->admins->list[$this->c->user->id])
|
||||
|
|
|
@ -34,11 +34,6 @@ class Check extends Method
|
|||
}
|
||||
}
|
||||
|
||||
// админ
|
||||
if ($user->isAdmin) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// проверка гостя
|
||||
if ($user->isGuest) {
|
||||
if (! empty($this->model->ipList)) {
|
||||
|
@ -66,8 +61,8 @@ class Check extends Method
|
|||
}
|
||||
}
|
||||
// проверка пользователя
|
||||
} else {
|
||||
$id = $this->model->isBanned($user);
|
||||
} elseif (! $user->isAdmin) {
|
||||
$id = $this->model->banFromName($user->username);
|
||||
|
||||
if ($id > 0) {
|
||||
if (isset($this->model->banList[$id])) {
|
||||
|
|
|
@ -14,13 +14,13 @@ class IsBanned extends Method
|
|||
*/
|
||||
public function isBanned(User $user): int
|
||||
{
|
||||
$name = $this->model->trimToNull($user->username, true);
|
||||
$name = $this->model->trimToNull($user->username, true);
|
||||
if (
|
||||
null !== $name
|
||||
&& isset($this->model->userList[$name])
|
||||
) {
|
||||
return $this->model->userList[$name];
|
||||
}
|
||||
} // ???? дублирование функционала
|
||||
|
||||
if (
|
||||
$user->isGuest
|
||||
|
|
|
@ -89,4 +89,21 @@ class Model extends ParentModel
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Выдает номер бана по имени или 0
|
||||
*/
|
||||
public function banFromName(?string $name): int
|
||||
{
|
||||
$name = $this->trimToNull($name, true);
|
||||
|
||||
if (
|
||||
null !== $name
|
||||
&& isset($this->userList[$name])
|
||||
) {
|
||||
return $this->userList[$name];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -570,7 +570,7 @@ class Bans extends Admin
|
|||
}
|
||||
|
||||
foreach ($userList as $user) {
|
||||
if ($this->c->bans->isBanned($user)) {
|
||||
if ($this->c->bans->banFromName($user->username) > 0) {
|
||||
return $this->c->Message->message(__('User is ban', $user->username));
|
||||
}
|
||||
|
||||
|
@ -749,7 +749,7 @@ class Bans extends Admin
|
|||
|
||||
if (! $user instanceof User) { // ???? может ли вернутся несколько юзеров?
|
||||
$v->addError('No user message');
|
||||
} elseif ($this->c->bans->isBanned($user)) {
|
||||
} elseif ($this->c->bans->banFromName($user->username) > 0) {
|
||||
$v->addError(__('User is ban', $user->username));
|
||||
} elseif (! $this->c->userRules->canBanUser($user)) {
|
||||
if ($user->isGuest) { // ???? O_o
|
||||
|
|
|
@ -95,7 +95,7 @@ abstract class Users extends Admin
|
|||
|
||||
switch ($action) {
|
||||
case self::ACTION_BAN:
|
||||
if ($this->c->bans->isBanned($user)) {
|
||||
if ($this->c->bans->banFromName($user->username) > 0) {
|
||||
$this->fIswev = ['i', __('User is ban', $user->username)];
|
||||
|
||||
return false;
|
||||
|
|
|
@ -64,7 +64,7 @@ class Send extends Method
|
|||
|
||||
if (
|
||||
1 !== $user->email_confirmed
|
||||
|| $this->c->bans->isBanned($user) > 0
|
||||
|| $this->c->bans->banFromName($user->username) > 0
|
||||
|| $this->c->Online->isOnline($user)
|
||||
) {
|
||||
continue;
|
||||
|
|
|
@ -19,7 +19,7 @@ class Model extends DataModel
|
|||
parent::__construct($container);
|
||||
|
||||
$this->zDepend = [
|
||||
'group_id' => ['isUnverified', 'isGuest', 'isAdmin', 'isAdmMod', 'link', 'viewUsers', 'showPostCount', 'searchUsers'],
|
||||
'group_id' => ['isUnverified', 'isGuest', 'isAdmin', 'isAdmMod', 'isBanByName', 'link', 'viewUsers', 'showPostCount', 'searchUsers'],
|
||||
'id' => ['isGuest', 'link', 'online'],
|
||||
'last_visit' => ['currentVisit'],
|
||||
'show_sig' => ['showSignature'],
|
||||
|
@ -64,6 +64,15 @@ class Model extends DataModel
|
|||
|| 1 == $this->g_moderator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Статус бана по имени пользователя
|
||||
*/
|
||||
protected function getisBanByName(): bool
|
||||
{
|
||||
return ! $this->isAdmin
|
||||
&& $this->c->bans->banFromName($this->username) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Статус модератора для указанной модели
|
||||
*/
|
||||
|
@ -195,7 +204,7 @@ class Model extends DataModel
|
|||
*/
|
||||
public function title(): string
|
||||
{
|
||||
if (isset($this->c->bans->userList[\mb_strtolower($this->username)])) { //????
|
||||
if ($this->isBanByName) {
|
||||
return __('Banned');
|
||||
} elseif ('' != $this->title) {
|
||||
return $this->censorTitle;
|
||||
|
|
|
@ -45,7 +45,7 @@ class Username extends RulesValidator
|
|||
} elseif ($this->c->censorship->censor($username) !== $username) {
|
||||
$v->addError('Username censor');
|
||||
// username забанен
|
||||
} elseif ($this->c->bans->isBanned($user) > 0) {
|
||||
} elseif ($this->c->bans->banFromName($username) > 0) {
|
||||
$v->addError('Banned username');
|
||||
// есть пользователь с похожим именем
|
||||
} elseif (
|
||||
|
|
Loading…
Add table
Reference in a new issue