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:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
config.yaml
|
config.yaml
|
||||||
.vscode
|
.vscode
|
||||||
__debug_bin
|
__debug_bin
|
||||||
|
mobility-accounts
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ func (s MobilityAccountsServerImpl) GetAccount(ctx context.Context, req *GetAcco
|
|||||||
account, err := s.handler.GetAccount(req.Id)
|
account, err := s.handler.GetAccount(req.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("")
|
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)
|
response, err := AccountFromStorageType(account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -91,7 +91,7 @@ func (s MobilityAccountsServerImpl) GetAccountUsername(ctx context.Context, req
|
|||||||
account, err := s.handler.GetAccountUsername(req.Username, req.Namespace)
|
account, err := s.handler.GetAccountUsername(req.Username, req.Namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("")
|
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)
|
response, err := AccountFromStorageType(account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -49,8 +49,13 @@ func (h MobilityAccountsHandler) Register(account storage.Account) (*storage.Acc
|
|||||||
account.Authentication.Local.Username = &email
|
account.Authentication.Local.Username = &email
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO remove this as we want to handle unicity in storage
|
|
||||||
if account.Authentication.Local != nil {
|
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 a password was sent, hash the password
|
||||||
if account.Authentication.Local.Password != "" {
|
if account.Authentication.Local.Password != "" {
|
||||||
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(account.Authentication.Local.Password), bcrypt.DefaultCost)
|
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)
|
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
|
// Validate data schemas
|
||||||
|
|||||||
Reference in New Issue
Block a user