fixes
This commit is contained in:
@@ -10,15 +10,12 @@ func (h *SilvermobiHandler) Login(ctx context.Context, username string, password
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
key := h.Config.GetString("identification.local.jwt_secret")
|
||||
ttl := h.Config.GetString("identification.local.ttl")
|
||||
|
||||
parsedttl, err := time.ParseDuration(ttl)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return account.CreateToken(parsedttl, key)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,15 +10,11 @@ import (
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
func (h *SilvermobiHandler) UpdatePhoneNumber(ctx context.Context, email string, phone_number string) error {
|
||||
func (h *SilvermobiHandler) UpdatePhoneNumber(ctx context.Context, id string, phone_number string) error {
|
||||
code := rand.Intn(9999)
|
||||
account, err := h.Services.MobilityAccounts.GetAccountUsername(ctx, email, "silvermobi")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = h.Services.MobilityAccounts.UpdatePhoneNumber(
|
||||
err := h.Services.MobilityAccounts.UpdatePhoneNumber(
|
||||
ctx,
|
||||
account.ID,
|
||||
id,
|
||||
phone_number,
|
||||
false,
|
||||
fmt.Sprintf("%04d", code),
|
||||
@@ -44,10 +40,9 @@ func (h *SilvermobiHandler) UpdatePhoneNumber(ctx context.Context, email string,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *SilvermobiHandler) VerifyPhoneNumber(ctx context.Context, email string, phone_number string, verification_code string) error {
|
||||
account, err := h.Services.MobilityAccounts.GetAccountUsername(ctx, email, "silvermobi")
|
||||
func (h *SilvermobiHandler) VerifyPhoneNumber(ctx context.Context, id string, phone_number string, verification_code string) error {
|
||||
request := &grpcapi.GetAccountRequest{
|
||||
Id: account.ID,
|
||||
Id: id,
|
||||
}
|
||||
resp, err := h.Services.MobilityAccounts.Client.GetAccount(ctx, request)
|
||||
if err != nil {
|
||||
@@ -69,7 +64,7 @@ func (h *SilvermobiHandler) VerifyPhoneNumber(ctx context.Context, email string,
|
||||
|
||||
err = h.Services.MobilityAccounts.UpdatePhoneNumber(
|
||||
ctx,
|
||||
account.ID,
|
||||
id,
|
||||
phone_number,
|
||||
true,
|
||||
"",
|
||||
@@ -81,29 +76,62 @@ func (h *SilvermobiHandler) VerifyPhoneNumber(ctx context.Context, email string,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *SilvermobiHandler) UpdateBirthDate(ctx context.Context, username string, birthdate string) error {
|
||||
err := h.Services.MobilityAccounts.UpdateAccountBirthDate(ctx, username, "silvermobi", birthdate)
|
||||
func (h *SilvermobiHandler) UpdateBirthDate(ctx context.Context, id string, birthdate string) error {
|
||||
err := h.Services.MobilityAccounts.UpdateAccountBirthDate(ctx, id, "silvermobi", birthdate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *SilvermobiHandler) CheckValidation(ctx context.Context, email string) (phone_validation, birth_validation bool, err error) {
|
||||
account, err := h.Services.MobilityAccounts.GetAccountUsername(ctx, email, "silvermobi")
|
||||
func (h *SilvermobiHandler) SetAccountType(ctx context.Context, id string, accountType string) error {
|
||||
err := h.Services.MobilityAccounts.SetAccountType(ctx, id, accountType)
|
||||
if err != nil {
|
||||
return false, false, err
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (h *SilvermobiHandler) GetAccountType(ctx context.Context, id string) (account_type string, err error) {
|
||||
request := &grpcapi.GetAccountRequest{
|
||||
Id: id,
|
||||
}
|
||||
resp, err := h.Services.MobilityAccounts.Client.GetAccount(ctx, request)
|
||||
if err != nil {
|
||||
return "", err
|
||||
log.Error().Err(err).Msg("Failed get account type")
|
||||
}
|
||||
account := h.Services.MobilityAccounts.ToAccountModel(resp.Account.ToStorageType())
|
||||
if account.Type != "" {
|
||||
|
||||
return account.Type, nil
|
||||
}
|
||||
return "", errors.New("account type not set")
|
||||
}
|
||||
|
||||
func (h *SilvermobiHandler) CheckValidation(ctx context.Context, id string) (phone_validation, birth_validation, type_validation bool, err error) {
|
||||
request := &grpcapi.GetAccountRequest{
|
||||
Id: id,
|
||||
}
|
||||
resp, err := h.Services.MobilityAccounts.Client.GetAccount(ctx, request)
|
||||
if err != nil {
|
||||
return false, false, false, err
|
||||
log.Error().Err(err).Msg("Failed get validation response")
|
||||
}
|
||||
account := h.Services.MobilityAccounts.ToAccountModel(resp.Account.ToStorageType())
|
||||
phone_validation = false
|
||||
birth_validation = false
|
||||
type_validation = false
|
||||
if account.LocalCredentials.PhoneNumberVerified {
|
||||
phone_validation = true
|
||||
|
||||
}
|
||||
if account.BirthDate != "" {
|
||||
birth_validation = true
|
||||
}
|
||||
log.Info().Msg("Getting phone and birth validation for " + email)
|
||||
return phone_validation, birth_validation, nil
|
||||
fmt.Println(account.Type)
|
||||
if account.Type != "" {
|
||||
type_validation = true
|
||||
}
|
||||
|
||||
log.Info().Msg("Getting phone and birth validation for " + account.Email)
|
||||
return phone_validation, birth_validation, type_validation, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user