فهرست منبع

修改注册手机号的验证

llp 4 روز پیش
والد
کامیت
b803bc7ff0

+ 4 - 3
packages/Webkul/BagistoApi/src/State/CustomerProfileProcessor.php

@@ -319,7 +319,8 @@ class CustomerProfileProcessor implements ProcessorInterface
      * spaces, hyphens, dots or parentheses):
      *   +1 2123165641, +86 138 0013 8000, (212) 316-5641, 2123165641
      *
-     * Returns the normalized number (e.g. "+12123165641") for storage.
+     * Returns the phone as-is (trimmed). Separators are preserved, so the
+     * stored value keeps the user's original formatting, e.g. "+1 530 996 4115".
      *
      * @throws InvalidInputException
      */
@@ -345,7 +346,7 @@ class CustomerProfileProcessor implements ProcessorInterface
             throw new InvalidInputException(__('bagistoapi::app.graphql.customer.phone-invalid-format'));
         }
 
-        // Normalize for storage: optional leading "+" followed by plain digits.
-        return (str_starts_with($phone, '+') ? '+' : '').$digits;
+        // No separator stripping: keep the user's input (trimmed) exactly as-is.
+        return $phone;
     }
 }

+ 9 - 3
packages/Webkul/BagistoApi/src/Validators/CustomerValidator.php

@@ -28,6 +28,11 @@ class CustomerValidator
             'password'   => 'min:6|required',
         ];
 
+        // Trim phone first so the unique check and the stored value always match.
+        if ($customer->phone !== null) {
+            $customer->phone = trim($customer->phone);
+        }
+
         $data = [
             'first_name'            => $customer->first_name,
             'last_name'             => $customer->last_name,
@@ -115,7 +120,8 @@ class CustomerValidator
      * spaces, hyphens, dots or parentheses):
      *   +1 2123165641, +86 138 0013 8000, (212) 316-5641, 2123165641
      *
-     * Returns the normalized number (e.g. "+12123165641") for storage.
+     * Returns the phone as-is (trimmed). Separators are preserved, so the
+     * stored value keeps the user's original formatting, e.g. "+1 530 996 4115".
      *
      * @throws InvalidInputException
      */
@@ -141,8 +147,8 @@ class CustomerValidator
             throw new InvalidInputException(__('bagistoapi::app.graphql.customer.phone-invalid-format'));
         }
 
-        // Normalize for storage: optional leading "+" followed by plain digits.
-        return (str_starts_with($phone, '+') ? '+' : '').$digits;
+        // No separator stripping: keep the user's input (trimmed) exactly as-is.
+        return $phone;
     }
 
     /**