POST /users/verify/phone/auth.json

Source

  • Legacy controller:/Users/mattsu/Documents/Site/get-lancer-php56/app/Controller/UsersController.php:5804-6044auth 分支 6006-6036
  • Legacy model:/Users/mattsu/Documents/Site/get-lancer-php56/app/Model/PhoneVerification.php:84-130
  • Legacy user write:/Users/mattsu/Documents/Site/get-lancer-php56/app/Model/User.php:1118-1151
  • Legacy ownership notification query / queue:/Users/mattsu/Documents/Site/get-lancer-php56/app/Plugin/Quotes/Model/QuoteServiceCategory.php:1583-16461817-1867
  • New endpoint:Endpoint/V1/Users.php:1125-1407,auth 主段 1348-1398
  • New model:Lib/Model/PhoneVerification.php:90-134
  • New verified phone write / notification:Lib/Model/User.php:718-848
  • New route:Lib/Common/RouterRule/Mapping.php:108-111

Input / guard

  • 全域 API key;session optional。
  • FormData:hashotp;另讀 is_login 決定 success log status。
  • IP key phone_auth:同一 IP 60 秒 5 次,鎖 600 秒。
  • 驗證條件:先由 hash 取得 phone,再找相同 phone、最近 10 分鐘、OTP 相同且 verify_code IS NULL 的 row;legacy 第二段查詢不再限制同一 hash。

DB write / side effect

user_id 的驗證紀錄

  • 對其他同 phone users 執行 legacy reset:phone 改 DEL{timestamp}_{phone}is_phone_confirmed=0
  • 若被 reset user 有 auto-quote service category,寫 Reset_Phone_Confirm event queue,email template 601 Auto Quote Verified Phone Unconfirmed Notification
  • 更新目前 user:phoneiphone_last_request=NOW()is_phone_confirmed=1;legacy Cake save 也更新 modified
  • 刪除成功使用的 phone_verifications row。
  • phone_verification_logs:一般成功 status=1is_login=1status=2
  • 呼叫 referral status 1,可能更新 user_referrals、wallet、transaction、wallet balance log。
  • 呼叫 AbnormalConfig::checkNewUser(..., 'user_verify_auth')

user_id 的驗證紀錄

  • 不更新 users、不跑 referral / abnormal。
  • 將 8 位亂數寫入 phone_verifications.verify_code,response 回同一字串,供後續 signup / quote service flow consume。

Response

  • success:phoneverify_codeerror=0message=Success
  • user-bound success 的 verify_code 是 boolean true;anonymous success 是 8 位字串。
  • failed:error=3message=Failed

Log / config

  • Legacy phone_verify channel 會記 hashotp、raw POST;先保持 legacy endpoint log。敏感資料與 RouterV3 重複風險待 reviewer 決定。
  • area 遵守共用規則:台灣環境不設定 area=tw
  • referral bonus、event template、site/email URL config 必須在 staging / production 部署前確認。

Payment / queue / activity

  • auth 本身不收款,也不呼叫 payment gateway。
  • user-bound success 會呼叫既有 ReferralHelper::checkReferral(user_id, 1);符合推薦條件時可能更新 wallet、transaction、wallet balance log。這不是新加的 bonus,而是 legacy controller UsersController.php:6018 的既有 side effect。
  • phone ownership 被轉移時,舊 user 若有 auto-quote category,寫 Reset_Phone_Confirm event;不新增 quote activity。
  • legacy QuoteServiceCategory::getHasServiceCategoryUserIdByUserIds()user_id 去重,因此同一舊 user 最多寫一筆 Reset_Phone_Confirm event;new 保留相同去重。
  • AbnormalConfig::checkNewUser(..., 'user_verify_auth') 可能更新 abnormal 相關資料,沿用既有 shared method,不修改 shared behavior。

Shared method caller 對照

  • User::setVerifiedPhoneForUser() 是本次新增的 legacy method port,目前 new caller 為 PhoneVerification::auth();既有 signup 仍使用 Users::setLegacySignUpVerifiedPhoneForUser() 的同等專用實作,沒有直接改 signup behavior。
  • ReferralHelper::checkReferral() 既有 caller 包含 hired / quote 等流程,本次只以 legacy status 1 呼叫,未修改 helper。

PHP 5.6 -> 8.2

  • hash / otp 缺值或非 scalar 時正規化,避免 regex / query TypeError。
  • 保留 legacy 的特殊查詢語意:第二段 OTP query 依 phone 找最近 10 分鐘未使用 row,不自行補 hash condition。
  • response verify_code 型別分開測:user-bound 是 boolean true,anonymous 是 8 位 string。

Tests / 未確認

  • 2026-07-16 PHP 8.2 容器:與 preauth / voice 共 9 tests / 85 assertions
  • 已驗證 anonymous / logged-in response 型別、users phone update、inactive 舊 owner reset、OTP delete、wrong / reused OTP、blocked session user。
  • 2026-07-16 new staging logged-in auth:preauth 後約 10 秒驗證成功,phone_verification_logs.id=30847/status=1;verification row 已刪除。users.id=8616 更新為測試 phone、is_phone_confirmed=1,舊 owner users.id=16508 改為 DEL{timestamp}_{phone}is_phone_confirmed=0
  • expired OTP、referral bonus / wallet、abnormal match、Reset_Phone_Confirm worker downstream 與完整 legacy/new staging raw response diff 仍待補。
  • production referral bonus config 與 Reset_Phone_Confirm worker downstream 尚未實測。
  • 本地 Lib/Common/Configuration.php.gitignore 忽略;email.signaturesite.url 與實際部署 config 不會由本 commit 自動同步。