Allow empty email
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/authorizerdev/authorizer/server/db"
|
||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||
"github.com/authorizerdev/authorizer/server/memorystore"
|
||||
"github.com/authorizerdev/authorizer/server/refs"
|
||||
"github.com/authorizerdev/authorizer/server/token"
|
||||
"github.com/authorizerdev/authorizer/server/utils"
|
||||
)
|
||||
@@ -51,28 +52,41 @@ func DeleteUserResolver(ctx context.Context, params model.DeleteUserInput) (*mod
|
||||
|
||||
go func() {
|
||||
// delete otp for given email
|
||||
otp, err := db.Provider.GetOTPByEmail(ctx, user.Email)
|
||||
otp, err := db.Provider.GetOTPByEmail(ctx, refs.StringValue(user.Email))
|
||||
if err != nil {
|
||||
log.Infof("No OTP found for email (%s): %v", user.Email, err)
|
||||
// continue
|
||||
} else {
|
||||
err := db.Provider.DeleteOTP(ctx, otp)
|
||||
if err != nil {
|
||||
log.Debugf("Failed to delete otp for given email (%s): %v", user.Email, err)
|
||||
log.Debugf("Failed to delete otp for given email (%s): %v", refs.StringValue(user.Email), err)
|
||||
// continue
|
||||
}
|
||||
}
|
||||
|
||||
// delete otp for given phone number
|
||||
otp, err = db.Provider.GetOTPByPhoneNumber(ctx, refs.StringValue(user.PhoneNumber))
|
||||
if err != nil {
|
||||
log.Infof("No OTP found for email (%s): %v", refs.StringValue(user.Email), err)
|
||||
// continue
|
||||
} else {
|
||||
err := db.Provider.DeleteOTP(ctx, otp)
|
||||
if err != nil {
|
||||
log.Debugf("Failed to delete otp for given phone (%s): %v", refs.StringValue(user.PhoneNumber), err)
|
||||
// continue
|
||||
}
|
||||
}
|
||||
|
||||
// delete verification requests for given email
|
||||
for _, vt := range constants.VerificationTypes {
|
||||
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(ctx, user.Email, vt)
|
||||
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(ctx, refs.StringValue(user.Email), vt)
|
||||
if err != nil {
|
||||
log.Infof("No verification verification request found for email: %s, verification_request_type: %s. %v", user.Email, vt, err)
|
||||
log.Infof("No verification verification request found for email: %s, verification_request_type: %s. %v", refs.StringValue(user.Email), vt, err)
|
||||
// continue
|
||||
} else {
|
||||
err := db.Provider.DeleteVerificationRequest(ctx, verificationRequest)
|
||||
if err != nil {
|
||||
log.Debugf("Failed to DeleteVerificationRequest for email: %s, verification_request_type: %s. %v", user.Email, vt, err)
|
||||
log.Debugf("Failed to DeleteVerificationRequest for email: %s, verification_request_type: %s. %v", refs.StringValue(user.Email), vt, err)
|
||||
// continue
|
||||
}
|
||||
}
|
||||
|
@@ -106,7 +106,7 @@ func InviteMembersResolver(ctx context.Context, params model.InviteMemberInput)
|
||||
}
|
||||
|
||||
user := &models.User{
|
||||
Email: email,
|
||||
Email: refs.NewStringRef(email),
|
||||
Roles: strings.Join(defaultRoles, ","),
|
||||
}
|
||||
hostname := parsers.GetHost(gc)
|
||||
@@ -171,7 +171,7 @@ func InviteMembersResolver(ctx context.Context, params model.InviteMemberInput)
|
||||
}
|
||||
|
||||
// exec it as go routine so that we can reduce the api latency
|
||||
go emailservice.SendEmail([]string{user.Email}, constants.VerificationTypeInviteMember, map[string]interface{}{
|
||||
go emailservice.SendEmail([]string{refs.StringValue(user.Email)}, constants.VerificationTypeInviteMember, map[string]interface{}{
|
||||
"user": user.ToMap(),
|
||||
"organization": utils.GetOrganization(),
|
||||
"verification_url": utils.GetInviteVerificationURL(verifyEmailURL, verificationToken, redirectURL),
|
||||
|
@@ -145,7 +145,7 @@ func LoginResolver(ctx context.Context, params model.LoginInput) (*model.AuthRes
|
||||
otp := utils.GenerateOTP()
|
||||
expires := time.Now().Add(1 * time.Minute).Unix()
|
||||
otpData, err := db.Provider.UpsertOTP(ctx, &models.OTP{
|
||||
Email: user.Email,
|
||||
Email: refs.StringValue(user.Email),
|
||||
Otp: otp,
|
||||
ExpiresAt: expires,
|
||||
})
|
||||
|
@@ -56,7 +56,7 @@ func MagicLinkLoginResolver(ctx context.Context, params model.MagicLinkLoginInpu
|
||||
inputRoles := []string{}
|
||||
|
||||
user := &models.User{
|
||||
Email: params.Email,
|
||||
Email: refs.NewStringRef(params.Email),
|
||||
}
|
||||
|
||||
// find user with email
|
||||
|
@@ -131,7 +131,7 @@ func MobileSignupResolver(ctx context.Context, params *model.MobileSignUpInput)
|
||||
}
|
||||
|
||||
user := &models.User{
|
||||
Email: emailInput,
|
||||
Email: &emailInput,
|
||||
PhoneNumber: &mobile,
|
||||
}
|
||||
|
||||
|
@@ -100,7 +100,7 @@ func ResendOTPResolver(ctx context.Context, params model.ResendOTPRequest) (*mod
|
||||
|
||||
otp := utils.GenerateOTP()
|
||||
if _, err := db.Provider.UpsertOTP(ctx, &models.OTP{
|
||||
Email: user.Email,
|
||||
Email: refs.StringValue(user.Email),
|
||||
Otp: otp,
|
||||
ExpiresAt: time.Now().Add(1 * time.Minute).Unix(),
|
||||
}); err != nil {
|
||||
|
@@ -158,7 +158,7 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
|
||||
user.Password = &password
|
||||
if email != "" {
|
||||
user.SignupMethods = constants.AuthRecipeMethodBasicAuth
|
||||
user.Email = email
|
||||
user.Email = &email
|
||||
}
|
||||
if params.GivenName != nil {
|
||||
user.GivenName = params.GivenName
|
||||
|
@@ -39,7 +39,7 @@ func TestEndpointResolver(ctx context.Context, params model.TestEndpointRequest)
|
||||
|
||||
user := model.User{
|
||||
ID: uuid.NewString(),
|
||||
Email: "test_endpoint@foo.com",
|
||||
Email: refs.NewStringRef("test_endpoint@authorizer.dev"),
|
||||
EmailVerified: true,
|
||||
SignupMethods: constants.AuthRecipeMethodMagicLinkLogin,
|
||||
GivenName: refs.NewStringRef("Foo"),
|
||||
|
@@ -196,7 +196,7 @@ func UpdateProfileResolver(ctx context.Context, params model.UpdateProfileInput)
|
||||
|
||||
hasEmailChanged := false
|
||||
|
||||
if params.Email != nil && user.Email != refs.StringValue(params.Email) {
|
||||
if params.Email != nil && refs.StringValue(user.Email) != refs.StringValue(params.Email) {
|
||||
// check if valid email
|
||||
if !validators.IsValidEmail(*params.Email) {
|
||||
log.Debug("Failed to validate email: ", refs.StringValue(params.Email))
|
||||
@@ -220,7 +220,7 @@ func UpdateProfileResolver(ctx context.Context, params model.UpdateProfileInput)
|
||||
go memorystore.Provider.DeleteAllUserSessions(user.ID)
|
||||
go cookie.DeleteSession(gc)
|
||||
|
||||
user.Email = newEmail
|
||||
user.Email = &newEmail
|
||||
isEmailVerificationDisabled, err := memorystore.Provider.GetBoolStoreEnvVariable(constants.EnvKeyDisableEmailVerification)
|
||||
if err != nil {
|
||||
log.Debug("Failed to get disable email verification env variable: ", err)
|
||||
@@ -257,7 +257,7 @@ func UpdateProfileResolver(ctx context.Context, params model.UpdateProfileInput)
|
||||
}
|
||||
|
||||
// exec it as go routine so that we can reduce the api latency
|
||||
go email.SendEmail([]string{user.Email}, verificationType, map[string]interface{}{
|
||||
go email.SendEmail([]string{refs.StringValue(user.Email)}, verificationType, map[string]interface{}{
|
||||
"user": user.ToMap(),
|
||||
"organization": utils.GetOrganization(),
|
||||
"verification_url": utils.GetEmailVerificationURL(verificationToken, hostname, redirectURL),
|
||||
|
@@ -127,7 +127,7 @@ func UpdateUserResolver(ctx context.Context, params model.UpdateUserInput) (*mod
|
||||
}
|
||||
}
|
||||
|
||||
if params.Email != nil && user.Email != *params.Email {
|
||||
if params.Email != nil && refs.StringValue(user.Email) != refs.StringValue(params.Email) {
|
||||
// check if valid email
|
||||
if !validators.IsValidEmail(*params.Email) {
|
||||
log.Debug("Invalid email: ", *params.Email)
|
||||
@@ -145,7 +145,7 @@ func UpdateUserResolver(ctx context.Context, params model.UpdateUserInput) (*mod
|
||||
go memorystore.Provider.DeleteAllUserSessions(user.ID)
|
||||
|
||||
hostname := parsers.GetHost(gc)
|
||||
user.Email = newEmail
|
||||
user.Email = &newEmail
|
||||
user.EmailVerifiedAt = nil
|
||||
// insert verification request
|
||||
_, nonceHash, err := utils.GenerateNonce()
|
||||
@@ -173,7 +173,7 @@ func UpdateUserResolver(ctx context.Context, params model.UpdateUserInput) (*mod
|
||||
}
|
||||
|
||||
// exec it as go routine so that we can reduce the api latency
|
||||
go email.SendEmail([]string{user.Email}, constants.VerificationTypeBasicAuthSignup, map[string]interface{}{
|
||||
go email.SendEmail([]string{refs.StringValue(user.Email)}, constants.VerificationTypeBasicAuthSignup, map[string]interface{}{
|
||||
"user": user.ToMap(),
|
||||
"organization": utils.GetOrganization(),
|
||||
"verification_url": utils.GetEmailVerificationURL(verificationToken, hostname, redirectURL),
|
||||
|
Reference in New Issue
Block a user