fix duplicate accounts
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 2m22s
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 2m22s
This commit is contained in:
@@ -49,8 +49,13 @@ func (h MobilityAccountsHandler) Register(account storage.Account) (*storage.Acc
|
||||
account.Authentication.Local.Username = &email
|
||||
}
|
||||
|
||||
//TODO remove this as we want to handle unicity in storage
|
||||
if account.Authentication.Local != nil {
|
||||
// Check if account with same username/email/phone already exists
|
||||
existing, _ := h.storage.DB.LocalAuthentication(account.Namespace, account.Authentication.Local.Username, account.Authentication.Local.Email, account.Authentication.Local.PhoneNumber)
|
||||
if existing != nil {
|
||||
return nil, errors.New("account with same credentials already exists")
|
||||
}
|
||||
|
||||
// If a password was sent, hash the password
|
||||
if account.Authentication.Local.Password != "" {
|
||||
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(account.Authentication.Local.Password), bcrypt.DefaultCost)
|
||||
@@ -59,9 +64,6 @@ func (h MobilityAccountsHandler) Register(account storage.Account) (*storage.Acc
|
||||
}
|
||||
account.Authentication.Local.Password = string(hashedPassword)
|
||||
}
|
||||
|
||||
_, _ = h.storage.DB.LocalAuthentication(account.Namespace, account.Authentication.Local.Username, account.Authentication.Local.Email, account.Authentication.Local.PhoneNumber)
|
||||
|
||||
}
|
||||
|
||||
// Validate data schemas
|
||||
|
||||
Reference in New Issue
Block a user