Преглед на файлове

Change work with ban by username

Visman преди 4 години
родител
ревизия
68b12a6241

+ 4 - 1
app/Controllers/Primary.php

@@ -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])

+ 2 - 7
app/Models/BanList/Check.php

@@ -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])) {

+ 2 - 2
app/Models/BanList/IsBanned.php

@@ -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

+ 17 - 0
app/Models/BanList/Model.php

@@ -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;
+        }
+    }
 }

+ 2 - 2
app/Models/Pages/Admin/Bans.php

@@ -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

+ 1 - 1
app/Models/Pages/Admin/Users.php

@@ -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;

+ 1 - 1
app/Models/Subscription/Send.php

@@ -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;

+ 11 - 2
app/Models/User/Model.php

@@ -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;

+ 1 - 1
app/Models/Validators/Username.php

@@ -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 (