ソースを参照

Fix User\Save

Visman 3 年 前
コミット
b137e6de94
1 ファイル変更9 行追加6 行削除
  1. 9 6
      app/Models/User/Save.php

+ 9 - 6
app/Models/User/Save.php

@@ -21,21 +21,22 @@ class Save extends Action
      */
      */
     public function update(User $user): User
     public function update(User $user): User
     {
     {
-        if ($user->id < 1) {
-            throw new RuntimeException('The model does not have ID');
+        if (
+            (! $user->isGuest && $user->id < 1)
+            || ($user->isGuest && 0 !== $user->id)
+        ) {
+            throw new RuntimeException('Bad ID');
         }
         }
 
 
         $modified = $user->getModified();
         $modified = $user->getModified();
+
         if (empty($modified)) {
         if (empty($modified)) {
             return $user;
             return $user;
         }
         }
 
 
         $values = $user->getAttrs();
         $values = $user->getAttrs();
 
 
-        if (
-            $user->isGuest
-            && ! $user->isUnverified
-        ) {
+        if ($user->isGuest) {
             $fileds = $this->c->dbMap->online;
             $fileds = $this->c->dbMap->online;
             $table  = 'online';
             $table  = 'online';
             $where  = 'user_id=0 AND ident=?s';
             $where  = 'user_id=0 AND ident=?s';
@@ -113,6 +114,8 @@ 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) {
+            throw new RuntimeException('Unexpected guest');
         }
         }
 
 
         // вычисление username_normal для нового пользователя
         // вычисление username_normal для нового пользователя