feat: add ability to force email verification (#1837)

This commit is contained in:
Elias Schneider
2026-10-13 22:04:33 +02:00
committed by GitHub
parent eb8ea6bed2
commit 0ffeb170cf
81 changed files with 2310 additions and 263 deletions
+15 -2
View File
@@ -1,6 +1,7 @@
package emailverification
import (
"context"
"fmt"
"github.com/gin-gonic/gin"
@@ -16,8 +17,8 @@ type Dependencies struct {
DB *gorm.DB
Actors francishost.Host
Users UserProvider
EmailSender EmailSender
ScimSync ScimSyncScheduler
AppConfig appconfig.AppConfigResolver
AppURL string
}
@@ -33,15 +34,27 @@ func New(deps Dependencies) (*Module, error) {
return nil, fmt.Errorf("error registering the %s actor: %w", ActorType, err)
}
service := newService(deps.DB, deps.Actors.Service(), deps.Users, deps.EmailSender, deps.AppURL)
service := newService(deps.DB, deps.Actors.Service(), deps.EmailSender, deps.ScimSync, deps.AppURL)
return &Module{
service: service,
handler: newHandler(service, deps.AppConfig),
}, nil
}
// Send issues a new verification token for the user's current email and emails the verification link
func (m *Module) Send(ctx context.Context, dbConfig *appconfig.AppConfigModel, userID string) error {
return m.service.Send(ctx, dbConfig, userID)
}
// RequestEmailChange emails a verification link to a new address, which replaces the user's current email once the link is used
func (m *Module) RequestEmailChange(ctx context.Context, dbConfig *appconfig.AppConfigModel, userID, newEmail string) error {
return m.service.RequestEmailChange(ctx, dbConfig, userID, newEmail)
}
// RegisterRoutes mounts the email verification endpoints
func (m *Module) RegisterRoutes(r *authz.Router, sendRateLimit, verifyRateLimit gin.HandlerFunc) {
r.POST("/users/me/send-email-verification", authz.AccountWrite, sendRateLimit, httpserver.Handle(m.handler.send))
r.POST("/users/me/verify-email", authz.AccountWrite, verifyRateLimit, httpserver.Handle(m.handler.verify))
r.GET("/users/me/email-change", authz.AccountRead, httpserver.Handle(m.handler.pendingEmailChange))
r.DELETE("/users/me/email-change", authz.AccountWrite, httpserver.Handle(m.handler.cancelEmailChange))
}