fixing some issues
This commit is contained in:
@@ -13,23 +13,26 @@ import (
|
||||
)
|
||||
|
||||
func (h MobilityAccountsHandler) Login(username string, password string, namespace string) (*storage.Account, error) {
|
||||
|
||||
if password == "" {
|
||||
return nil, errors.New("empty password not allowed")
|
||||
}
|
||||
u := strings.ToLower(username)
|
||||
account, err := h.storage.DB.LocalAuthentication(namespace, &u, nil, nil)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = bcrypt.CompareHashAndPassword([]byte(account.Authentication.Local.Password), []byte(password)); err != nil {
|
||||
fmt.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func (h MobilityAccountsHandler) Register(account storage.Account) (*storage.Account, error) {
|
||||
|
||||
if account.ID != "" {
|
||||
return nil, errors.New("id should be empty")
|
||||
}
|
||||
@@ -57,11 +60,8 @@ func (h MobilityAccountsHandler) Register(account storage.Account) (*storage.Acc
|
||||
account.Authentication.Local.Password = string(hashedPassword)
|
||||
}
|
||||
|
||||
_, err := h.storage.DB.LocalAuthentication(account.Namespace, account.Authentication.Local.Username, account.Authentication.Local.Email, account.Authentication.Local.PhoneNumber)
|
||||
_, _ = h.storage.DB.LocalAuthentication(account.Namespace, account.Authentication.Local.Username, account.Authentication.Local.Email, account.Authentication.Local.PhoneNumber)
|
||||
|
||||
if err == nil {
|
||||
return nil, errors.New("user already exists")
|
||||
}
|
||||
}
|
||||
|
||||
// Validate data schemas
|
||||
@@ -146,7 +146,6 @@ func (h MobilityAccountsHandler) UpdatePhoneNumber(accountid, phone_number strin
|
||||
if err == nil && account.ID != account2.ID {
|
||||
return errors.New("user with this phone number already exists")
|
||||
}
|
||||
|
||||
account.Authentication.Local.PhoneNumber = &phone_number
|
||||
account.Authentication.Local.PhoneNumberValidation.Validated = verified
|
||||
account.Authentication.Local.PhoneNumberValidation.ValidationCode = verification_code
|
||||
@@ -195,7 +194,6 @@ func (h MobilityAccountsHandler) ChangePassword(accountid string, newpassword st
|
||||
account.Authentication.Local.Password = string(hashedPassword)
|
||||
|
||||
if err = h.storage.DB.UpdateAccount(*account); err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user