feat: sync login email verification support
This commit is contained in:
parent
e0cabb4930
commit
9a501f900a
39 changed files with 2198 additions and 117 deletions
|
|
@ -34,6 +34,38 @@ func (s *AuthKeyStore) Get(_ context.Context, id [8]byte) (store.AuthKeyData, bo
|
|||
return k, ok, nil
|
||||
}
|
||||
|
||||
func (s *AuthKeyStore) UpdateClientInfo(_ context.Context, id [8]byte, info store.AuthKeyClientInfo) error {
|
||||
s.mu.Lock()
|
||||
k, ok := s.keys[id]
|
||||
if ok {
|
||||
mergeAuthKeyClientInfo(&k, info)
|
||||
s.keys[id] = k
|
||||
}
|
||||
s.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func mergeAuthKeyClientInfo(k *store.AuthKeyData, info store.AuthKeyClientInfo) {
|
||||
if info.Layer > 0 {
|
||||
k.Layer = info.Layer
|
||||
}
|
||||
if info.DeviceModel != "" {
|
||||
k.DeviceModel = info.DeviceModel
|
||||
}
|
||||
if info.Platform != "" {
|
||||
k.Platform = info.Platform
|
||||
}
|
||||
if info.SystemVersion != "" {
|
||||
k.SystemVersion = info.SystemVersion
|
||||
}
|
||||
if info.APIID != 0 {
|
||||
k.APIID = info.APIID
|
||||
}
|
||||
if info.AppVersion != "" {
|
||||
k.AppVersion = info.AppVersion
|
||||
}
|
||||
}
|
||||
|
||||
func (s *AuthKeyStore) Delete(_ context.Context, id [8]byte) error {
|
||||
s.mu.Lock()
|
||||
delete(s.keys, id)
|
||||
|
|
@ -256,6 +288,18 @@ func (s *CodeStore) Get(_ context.Context, hash string) (store.PhoneCode, bool,
|
|||
return e.code, true, nil
|
||||
}
|
||||
|
||||
func (s *CodeStore) Update(_ context.Context, hash string, code store.PhoneCode) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
e, ok := s.m[hash]
|
||||
if !ok || time.Now().After(e.expires) {
|
||||
return nil
|
||||
}
|
||||
e.code = code
|
||||
s.m[hash] = e
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *CodeStore) Del(_ context.Context, hash string) error {
|
||||
s.mu.Lock()
|
||||
delete(s.m, hash)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package memory
|
|||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"telesrv/internal/domain"
|
||||
)
|
||||
|
|
@ -75,11 +76,40 @@ func (s *PasswordStore) GetByUser(_ context.Context, userID int64) (domain.Passw
|
|||
|
||||
func (s *PasswordStore) Save(_ context.Context, userID int64, settings domain.PasswordSettings) error {
|
||||
s.mu.Lock()
|
||||
settings.LoginEmail = normalizeLoginEmail(settings.LoginEmail)
|
||||
settings.LoginEmailPattern = domain.MaskEmail(settings.LoginEmail)
|
||||
if settings.LoginEmail != "" {
|
||||
for ownerUserID, existing := range s.m {
|
||||
if ownerUserID != userID && strings.EqualFold(existing.LoginEmail, settings.LoginEmail) {
|
||||
s.mu.Unlock()
|
||||
return domain.ErrEmailOccupied
|
||||
}
|
||||
}
|
||||
}
|
||||
s.m[userID] = clonePasswordSettings(settings)
|
||||
s.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *PasswordStore) LoginEmailOwner(_ context.Context, email string) (int64, bool, error) {
|
||||
email = normalizeLoginEmail(email)
|
||||
if email == "" {
|
||||
return 0, false, nil
|
||||
}
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
for userID, settings := range s.m {
|
||||
if strings.EqualFold(settings.LoginEmail, email) {
|
||||
return userID, true, nil
|
||||
}
|
||||
}
|
||||
return 0, false, nil
|
||||
}
|
||||
|
||||
func normalizeLoginEmail(email string) string {
|
||||
return strings.ToLower(strings.TrimSpace(email))
|
||||
}
|
||||
|
||||
func clonePasswordSettings(in domain.PasswordSettings) domain.PasswordSettings {
|
||||
out := in
|
||||
if in.CurrentAlgo != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue