fix for phone generation on email signup
This commit is contained in:
parent
cee960fea0
commit
3409f190b9
20 changed files with 457 additions and 54 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue