Auth: Fix email verification bypass when using basic authentication (#82914)
This commit is contained in:
@@ -28,15 +28,25 @@ type EmailSender interface {
|
||||
SendEmailCommandHandlerSync(ctx context.Context, cmd *SendEmailCommandSync) error
|
||||
SendEmailCommandHandler(ctx context.Context, cmd *SendEmailCommand) error
|
||||
}
|
||||
type PasswordResetMailer interface {
|
||||
SendResetPasswordEmail(ctx context.Context, cmd *SendResetPasswordEmailCommand) error
|
||||
ValidateResetPasswordCode(ctx context.Context, query *ValidateResetPasswordCodeQuery, userByLogin GetUserByLoginFunc) (*user.User, error)
|
||||
}
|
||||
type EmailVerificationMailer interface {
|
||||
SendVerificationEmail(ctx context.Context, cmd *SendVerifyEmailCommand) error
|
||||
}
|
||||
type Service interface {
|
||||
WebhookSender
|
||||
EmailSender
|
||||
PasswordResetMailer
|
||||
EmailVerificationMailer
|
||||
}
|
||||
|
||||
var mailTemplates *template.Template
|
||||
var tmplResetPassword = "reset_password"
|
||||
var tmplSignUpStarted = "signup_started"
|
||||
var tmplWelcomeOnSignUp = "welcome_on_signup"
|
||||
var tmplVerifyEmail = "verify_email_update"
|
||||
|
||||
func ProvideService(bus bus.Bus, cfg *setting.Cfg, mailer Mailer, store TempUserStore) (*NotificationService, error) {
|
||||
ns := &NotificationService{
|
||||
@@ -257,6 +267,20 @@ func (ns *NotificationService) ValidateResetPasswordCode(ctx context.Context, qu
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (ns *NotificationService) SendVerificationEmail(ctx context.Context, cmd *SendVerifyEmailCommand) error {
|
||||
return ns.SendEmailCommandHandlerSync(ctx, &SendEmailCommandSync{
|
||||
SendEmailCommand: SendEmailCommand{
|
||||
To: []string{cmd.Email},
|
||||
Template: tmplVerifyEmail,
|
||||
Data: map[string]any{
|
||||
"Code": url.QueryEscape(cmd.Code),
|
||||
"Name": cmd.User.Name,
|
||||
"VerificationEmailLifetimeHours": int(ns.Cfg.VerificationEmailMaxLifetime.Hours()),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (ns *NotificationService) signUpStartedHandler(ctx context.Context, evt *events.SignUpStarted) error {
|
||||
if !ns.Cfg.VerifyEmailEnabled {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user