fix duplicate accounts
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 2m22s

This commit is contained in:
Arnaud Delcasse
2026-01-13 12:38:46 +01:00
parent b0b3de1f63
commit 0c982c8f47
3 changed files with 10 additions and 7 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
config.yaml
.vscode
__debug_bin
__debug_bin
mobility-accounts

View File

@@ -78,7 +78,7 @@ func (s MobilityAccountsServerImpl) GetAccount(ctx context.Context, req *GetAcco
account, err := s.handler.GetAccount(req.Id)
if err != nil {
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.AlreadyExists, "issue while retrieving account : %v", err)
return nil, status.Errorf(codes.NotFound, "issue while retrieving account : %v", err)
}
response, err := AccountFromStorageType(account)
if err != nil {
@@ -91,7 +91,7 @@ func (s MobilityAccountsServerImpl) GetAccountUsername(ctx context.Context, req
account, err := s.handler.GetAccountUsername(req.Username, req.Namespace)
if err != nil {
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.AlreadyExists, "issue while retrieving account : %v", err)
return nil, status.Errorf(codes.NotFound, "issue while retrieving account : %v", err)
}
response, err := AccountFromStorageType(account)
if err != nil {

View File

@@ -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