Improvements for RIDYGO
This commit is contained in:
@@ -3,6 +3,7 @@ package handlers
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
@@ -16,7 +17,7 @@ func (h MobilityAccountsHandler) Login(username string, password string, namespa
|
||||
if password == "" {
|
||||
return nil, errors.New("empty password not allowed")
|
||||
}
|
||||
account, err := h.storage.DB.LocalAuthentication(namespace, username, "", "")
|
||||
account, err := h.storage.DB.LocalAuthentication(namespace, strings.ToLower(username), "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -32,6 +33,15 @@ func (h MobilityAccountsHandler) Register(account storage.Account) (*storage.Acc
|
||||
return nil, errors.New("id should be empty")
|
||||
}
|
||||
|
||||
account.Authentication.Local.Username = strings.ToLower(account.Authentication.Local.Username)
|
||||
account.Authentication.Local.Email = strings.ToLower(account.Authentication.Local.Email)
|
||||
|
||||
_, err := 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")
|
||||
}
|
||||
|
||||
// Generate new UUID
|
||||
account.ID = uuid.NewString()
|
||||
|
||||
@@ -115,6 +125,30 @@ func (h MobilityAccountsHandler) UpdateData(accountid string, datas map[string]a
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func (h MobilityAccountsHandler) UpdatePhoneNumber(accountid, phone_number string, verified bool, verification_code string) error {
|
||||
account, err := h.storage.DB.GetAccount(accountid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
account2, err := h.storage.DB.LocalAuthentication(account.Namespace, "", "", phone_number)
|
||||
|
||||
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
|
||||
|
||||
if err = h.storage.DB.UpdateAccount(*account); err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h MobilityAccountsHandler) GetAccount(id string) (account *storage.Account, err error) {
|
||||
account, err = h.storage.DB.GetAccount(id)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user