Fix tests

This commit is contained in:
Lakhan Samani
2023-07-18 22:50:23 +05:30
committed by catusax
parent 2f849b8f0c
commit cf54fcef03
6 changed files with 81 additions and 46 deletions

View File

@@ -17,6 +17,7 @@ import (
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/memorystore"
"github.com/authorizerdev/authorizer/server/refs"
"github.com/authorizerdev/authorizer/server/smsproviders"
"github.com/authorizerdev/authorizer/server/token"
"github.com/authorizerdev/authorizer/server/utils"
"github.com/authorizerdev/authorizer/server/validators"
@@ -94,6 +95,45 @@ func MobileLoginResolver(ctx context.Context, params model.MobileLoginInput) (*m
roles = params.Roles
}
disablePhoneVerification, _ := memorystore.Provider.GetBoolStoreEnvVariable(constants.EnvKeyDisablePhoneVerification)
if disablePhoneVerification {
now := time.Now().Unix()
user.PhoneNumberVerifiedAt = &now
}
fmt.Println("=> disablePhoneVerification", disablePhoneVerification)
if !disablePhoneVerification {
duration, _ := time.ParseDuration("10m")
smsCode := utils.GenerateOTP()
smsBody := strings.Builder{}
smsBody.WriteString("Your verification code is: ")
smsBody.WriteString(smsCode)
// TODO: For those who enabled the webhook to call their sms vendor separately - sending the otp to their api
if err != nil {
log.Debug("error while upserting user: ", err.Error())
return nil, err
}
_, err := db.Provider.UpsertOTP(ctx, &models.OTP{
PhoneNumber: params.PhoneNumber,
Otp: smsCode,
ExpiresAt: time.Now().Add(duration).Unix(),
})
if err != nil {
log.Debug("error while upserting OTP: ", err.Error())
return nil, err
}
go func() {
smsproviders.SendSMS(params.PhoneNumber, smsBody.String())
}()
return &model.AuthResponse{
Message: "Please check the OTP",
ShouldShowOtpScreen: refs.NewBoolRef(true),
}, nil
}
scope := []string{"openid", "email", "profile"}
if params.Scope != nil && len(scope) > 0 {
scope = params.Scope

View File

@@ -105,7 +105,6 @@ func MobileSignupResolver(ctx context.Context, params *model.MobileSignUpInput)
}
inputRoles := []string{}
if len(params.Roles) > 0 {
// check if roles exists
rolesString, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyRoles)
@@ -197,7 +196,7 @@ func MobileSignupResolver(ctx context.Context, params *model.MobileSignUpInput)
log.Debug("Failed to add user: ", err)
return res, err
}
fmt.Println("=> disablePhoneVerification signup", disablePhoneVerification)
if !disablePhoneVerification {
duration, _ := time.ParseDuration("10m")
smsCode := utils.GenerateOTP()
@@ -211,15 +210,22 @@ func MobileSignupResolver(ctx context.Context, params *model.MobileSignUpInput)
log.Debug("error while upserting user: ", err.Error())
return nil, err
}
_, err = db.Provider.UpsertOTP(ctx, &models.OTP{
PhoneNumber: mobile,
Otp: smsCode,
ExpiresAt: time.Now().Add(duration).Unix(),
})
if err != nil {
log.Debug("error while upserting OTP: ", err.Error())
return nil, err
}
go func() {
db.Provider.UpsertOTP(ctx, &models.OTP{
PhoneNumber: mobile,
Otp: smsCode,
ExpiresAt: time.Now().Add(duration).Unix(),
})
smsproviders.SendSMS(mobile, smsBody.String())
}()
return &model.AuthResponse{
Message: "Please check the OTP in your inbox",
ShouldShowOtpScreen: refs.NewBoolRef(true),
}, nil
}
roles := strings.Split(user.Roles, ",")