浏览代码

Update User model for username_normal

And fix User\Save.
Visman 3 年之前
父节点
当前提交
e39a350e8f
共有 3 个文件被更改,包括 19 次插入14 次删除
  1. 1 1
      app/Models/User/IsUniqueName.php
  2. 4 10
      app/Models/User/Save.php
  3. 14 3
      app/Models/User/User.php

+ 1 - 1
app/Models/User/IsUniqueName.php

@@ -23,7 +23,7 @@ class IsUniqueName extends Action
         $vars = [
         $vars = [
             ':id'    => (int) $user->id,
             ':id'    => (int) $user->id,
             ':name'  => $user->username,
             ':name'  => $user->username,
-            ':norm'  => $this->manager->normUsername($user->username),
+            ':norm'  => $user->username_normal,
             ':normL' => $this->manager->normUsername(\mb_strtolower($user->username, 'UTF-8')), // ????
             ':normL' => $this->manager->normUsername(\mb_strtolower($user->username, 'UTF-8')), // ????
             ':normU' => $this->manager->normUsername(\mb_strtoupper($user->username, 'UTF-8')), // ????
             ':normU' => $this->manager->normUsername(\mb_strtoupper($user->username, 'UTF-8')), // ????
         ];
         ];

+ 4 - 10
app/Models/User/Save.php

@@ -60,15 +60,6 @@ class Save extends Action
 
 
             if ('username' === $name) {
             if ('username' === $name) {
                 $nameChange = true;
                 $nameChange = true;
-
-                // пересчет username_normal при изменении username
-                $name = 'username_normal';
-
-                if (isset($fileds[$name])) {
-                    $vars[] = $this->manager->normUsername($user->username);
-                    $set[]  = $name . '=?' . $fileds[$name];
-                }
-                // пересчет username_normal при изменении username
             } elseif ('group_id' === $name) {
             } elseif ('group_id' === $name) {
                 $grChange = true;
                 $grChange = true;
             }
             }
@@ -114,7 +105,10 @@ class Save extends Action
     {
     {
         if (null !== $user->id) {
         if (null !== $user->id) {
             throw new RuntimeException('The model has ID');
             throw new RuntimeException('The model has ID');
-        } elseif ($user->isGuest) {
+        } elseif (
+            null === $user->group_id
+            || FORK_GROUP_GUEST === $user->group_id
+        ) {
             throw new RuntimeException('Unexpected guest');
             throw new RuntimeException('Unexpected guest');
         }
         }
 
 

+ 14 - 3
app/Models/User/User.php

@@ -38,6 +38,7 @@ class User extends DataModel
             'show_avatars' => ['showAvatar'],
             'show_avatars' => ['showAvatar'],
             'signature'    => ['isSignature'],
             'signature'    => ['isSignature'],
             'email'        => ['email_normal'],
             'email'        => ['email_normal'],
+            'username'     => ['username_normal'],
             'g_pm'         => ['usePM'],
             'g_pm'         => ['usePM'],
         ];
         ];
     }
     }
@@ -366,20 +367,30 @@ class User extends DataModel
     }
     }
 
 
     /**
     /**
-     * Вычисление нормализованного email
+     * Вычисляет нормализованный email
      */
      */
     protected function getemail_normal(): string
     protected function getemail_normal(): string
     {
     {
         return $this->c->NormEmail->normalize($this->email);
         return $this->c->NormEmail->normalize($this->email);
     }
     }
 
 
+    /**
+     * Вычисляет нормализованный username
+     */
+    protected function getusername_normal(): string
+    {
+        return $this->c->users->normUsername($this->username);
+    }
+
     /**
     /**
      * Возвращает значения свойств в массиве
      * Возвращает значения свойств в массиве
      */
      */
     public function getAttrs(): array
     public function getAttrs(): array
     {
     {
-        if (isset($this->zModFlags['email_normal'])) {
-            $this->setAttr('email_normal', $this->email_normal);
+        foreach (['email_normal', 'username_normal'] as $key) {
+            if (isset($this->zModFlags[$key])) {
+                $this->setAttr($key, $this->$key);
+            }
         }
         }
 
 
         return parent::getAttrs();
         return parent::getAttrs();