serviceemail

package
v0.0.0-...-8c930d8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAccountGatewayNotConfigured is returned until the host application
	// installs a real AccountGateway for email account operations.
	ErrAccountGatewayNotConfigured = errors.New("email account gateway is not configured")

	// ErrAccountGatewayInvalidAccount means a gateway returned an account snapshot that
	// does not satisfy the email module identity contract.
	ErrAccountGatewayInvalidAccount = errors.New("email account gateway returned invalid account")

	// ErrAccountNotFound lets gateways report missing accounts without leaking the
	// concrete account store implementation into email services.
	ErrAccountNotFound = errors.New("email account not found")

	// ErrAccountAuthenticationFailed hides account-not-found, inactive-account, and
	// invalid-password details behind one safe verification failure signal.
	ErrAccountAuthenticationFailed = errors.New("email account authentication failed")
)

Functions

func SetAccountGateway

func SetAccountGateway(gateway AccountGateway)

SetAccountGateway installs the host application's account gateway. Call it during application/module initialization before serving email routes. Passing nil restores the safe default that fails account-backed email flows with ErrAccountGatewayNotConfigured.

Types

type AccountGateway

type AccountGateway interface {
	// FindByEmail resolves the account currently bound to email.
	FindByEmail(ctx *gst.ServiceContext, email string) (*AccountSnapshot, error)

	// GetByID loads a stable account snapshot by account ID.
	GetByID(ctx *gst.ServiceContext, userID string) (*AccountSnapshot, error)

	// VerifyPassword validates the current password for the account.
	VerifyPassword(ctx *gst.ServiceContext, userID, password string) error

	// UpdatePassword persists a new password according to the host password policy.
	UpdatePassword(ctx *gst.ServiceContext, userID, newPassword string) error

	// MarkEmailVerified persists the email verification state for the account.
	MarkEmailVerified(ctx *gst.ServiceContext, userID string, verifiedAt time.Time) error

	// ApplyEmailChange persists a confirmed email change for the account.
	ApplyEmailChange(ctx *gst.ServiceContext, userID, newEmail string, changedAt time.Time) error

	// InvalidateSessions revokes cached sessions for an account after password reset.
	//
	// It takes the request context like every other method here, so the revoke
	// it performs is attributed to the request that caused it rather than
	// appearing as unowned background work in traces.
	InvalidateSessions(ctx *gst.ServiceContext, userID string)
}

AccountGateway connects the email module to the host application's account system. Implementations own account lookup, password verification, password hashing, account updates, and session invalidation for their account store.

The email service intentionally depends only on this gateway and AccountSnapshot so copied email module code does not import a concrete IAM user model.

type AccountSnapshot

type AccountSnapshot struct {
	ID            string
	Email         string
	Active        bool
	EmailVerified bool
}

AccountSnapshot is the minimal account state required by email flows. ID must be the same stable account identifier stored in email flow state. Active must be true only when the host account is allowed to start or complete email flows.

type ChangeCancelService

ChangeCancelService handles the token cancellation step that revokes a pending email change before confirmation happens.

func (*ChangeCancelService) Create

Create consumes the cancellation token and records that matching confirmation tokens must no longer complete the email change.

type ChangeConfirmService

ChangeConfirmService handles the token confirmation step that finalizes a pending email change.

func (*ChangeConfirmService) Create

Create consumes the confirmation token and updates the account email when the current database state still matches the pending change flow.

type ChangeRequestService

ChangeRequestService handles authenticated requests that start the email change flow for the current account.

func (*ChangeRequestService) Create

Create validates the current password, checks the target email, and issues one-time confirmation and cancellation tokens for the email change flow.

type ChangeResendService

ChangeResendService handles authenticated requests that resend confirmation emails for an in-progress email change flow.

func (*ChangeResendService) Create

Create revalidates the current account and reissues the confirmation email for the target new email address.

type PasswordResetConfirmService

PasswordResetConfirmService handles the token confirmation step that finalizes the email-driven password reset flow.

func (*PasswordResetConfirmService) Create

Create completes the password reset flow by consuming the one-time token, delegating the password update to the configured account gateway, and invalidating active sessions.

type PasswordResetRequestService

PasswordResetRequestService handles public password reset requests that start the email-driven password recovery flow.

func (*PasswordResetRequestService) Create

Create starts the password reset flow for the provided email address. It always returns the same public-facing message for accepted requests so the caller cannot infer whether the account exists, while still enforcing throttle limits before any token is created or email is sent.

type VerificationConfirmService

type VerificationConfirmService struct {
	service.Base[*model.Empty, *modelemail.VerificationConfirmReq, *modelemail.VerificationConfirmRsp]
}

VerificationConfirmService handles the token confirmation step that finalizes the email verification flow.

func (*VerificationConfirmService) Create

Create consumes the one-time verification token and marks the corresponding email address as verified when the current account state still matches.

type VerificationRequestService

type VerificationRequestService struct {
	service.Base[*model.Empty, *modelemail.VerificationRequestReq, *modelemail.VerificationRequestRsp]
}

VerificationRequestService handles public requests that start the email verification flow for an eligible user account.

func (*VerificationRequestService) Create

Create starts an email verification flow and returns a generic acceptance message so callers cannot infer whether the target account exists.

type VerificationResendService

type VerificationResendService struct {
	service.Base[*model.Empty, *modelemail.VerificationResendReq, *modelemail.VerificationResendRsp]
}

VerificationResendService handles public requests that resend verification emails for accounts that are still pending verification.

func (*VerificationResendService) Create

Create resends a verification email for an eligible account while keeping the response stable for unknown or already verified accounts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址