fix for phone generation on email signup

This commit is contained in:
onysd 2026-07-14 00:30:52 +03:00
parent cee960fea0
commit 3409f190b9
20 changed files with 457 additions and 54 deletions

View file

@ -42,7 +42,11 @@ func (s *PhoneChangeStore) ChangePhone(ctx context.Context, req domain.PhoneChan
}
}
currentPhone := u.Phone
currentSignupEmail := u.SignupEmail
u.Phone = req.Phone
if req.SignupEmail != "" {
u.SignupEmail = req.SignupEmail
}
s.users.byID[req.UserID] = u
date := req.Date
@ -62,6 +66,7 @@ func (s *PhoneChangeStore) ChangePhone(ctx context.Context, req domain.PhoneChan
if err != nil {
// 保持内存替身与 PG 的 user+event 原子可见语义。
u.Phone = currentPhone
u.SignupEmail = currentSignupEmail
s.users.byID[req.UserID] = u
s.users.mu.Unlock()
return domain.PhoneChangeResult{}, err

View file

@ -2,6 +2,7 @@ package memory
import (
"context"
"fmt"
"sort"
"strings"
"sync"
@ -72,6 +73,23 @@ func (s *UserStore) ByPhone(_ context.Context, phone string) (domain.User, bool,
return domain.User{}, false, nil
}
// ByEmail looks up an email-signup account by its signup_email (see
// domain.NewEmailSignupDisplayPhone). Mirrors postgres.UserStore.ByEmail.
func (s *UserStore) ByEmail(_ context.Context, email string) (domain.User, bool, error) {
email = strings.ToLower(strings.TrimSpace(email))
if email == "" {
return domain.User{}, false, nil
}
s.mu.RLock()
defer s.mu.RUnlock()
for _, u := range s.byID {
if u.SignupEmail != "" && strings.ToLower(u.SignupEmail) == email {
return u, true, nil
}
}
return domain.User{}, false, nil
}
func (s *UserStore) ByPhones(_ context.Context, phones []string) ([]domain.User, error) {
if len(phones) == 0 {
return nil, nil
@ -377,6 +395,14 @@ func (s *UserStore) Create(_ context.Context, u domain.User) (domain.User, error
}
}
}
signupEmail := strings.ToLower(strings.TrimSpace(u.SignupEmail))
if signupEmail != "" {
for _, existing := range s.byID {
if existing.SignupEmail != "" && strings.ToLower(existing.SignupEmail) == signupEmail {
return domain.User{}, fmt.Errorf("create user: signup email occupied")
}
}
}
u.ID = s.nextID
s.nextID++
s.byID[u.ID] = u