Documentation
¶
Index ¶
- Variables
- func SetAccountGateway(gateway AccountGateway)
- type AccountGateway
- type AccountSnapshot
- type ChangeCancelService
- type ChangeConfirmService
- type ChangeRequestService
- type ChangeResendService
- type PasswordResetConfirmService
- type PasswordResetRequestService
- type VerificationConfirmService
- type VerificationRequestService
- type VerificationResendService
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
type ChangeCancelService struct {
service.Base[*modelemail.ChangeCancel, *modelemail.ChangeCancelReq, *modelemail.ChangeCancelRsp]
}
ChangeCancelService handles the token cancellation step that revokes a pending email change before confirmation happens.
func (*ChangeCancelService) Create ¶
func (s *ChangeCancelService) Create(ctx *gst.ServiceContext, req *modelemail.ChangeCancelReq) (rsp *modelemail.ChangeCancelRsp, err error)
Create consumes the cancellation token and records that matching confirmation tokens must no longer complete the email change.
type ChangeConfirmService ¶
type ChangeConfirmService struct {
service.Base[*modelemail.ChangeConfirm, *modelemail.ChangeConfirmReq, *modelemail.ChangeConfirmRsp]
}
ChangeConfirmService handles the token confirmation step that finalizes a pending email change.
func (*ChangeConfirmService) Create ¶
func (s *ChangeConfirmService) Create(ctx *gst.ServiceContext, req *modelemail.ChangeConfirmReq) (rsp *modelemail.ChangeConfirmRsp, err error)
Create consumes the confirmation token and updates the account email when the current database state still matches the pending change flow.
type ChangeRequestService ¶
type ChangeRequestService struct {
service.Base[*modelemail.ChangeRequest, *modelemail.ChangeRequestReq, *modelemail.ChangeRequestRsp]
}
ChangeRequestService handles authenticated requests that start the email change flow for the current account.
func (*ChangeRequestService) Create ¶
func (s *ChangeRequestService) Create(ctx *gst.ServiceContext, req *modelemail.ChangeRequestReq) (rsp *modelemail.ChangeRequestRsp, err error)
Create validates the current password, checks the target email, and issues one-time confirmation and cancellation tokens for the email change flow.
type ChangeResendService ¶
type ChangeResendService struct {
service.Base[*modelemail.ChangeResend, *modelemail.ChangeResendReq, *modelemail.ChangeResendRsp]
}
ChangeResendService handles authenticated requests that resend confirmation emails for an in-progress email change flow.
func (*ChangeResendService) Create ¶
func (s *ChangeResendService) Create(ctx *gst.ServiceContext, req *modelemail.ChangeResendReq) (rsp *modelemail.ChangeResendRsp, err error)
Create revalidates the current account and reissues the confirmation email for the target new email address.
type PasswordResetConfirmService ¶
type PasswordResetConfirmService struct {
service.Base[*modelemail.PasswordResetConfirm, *modelemail.PasswordResetConfirmReq, *modelemail.PasswordResetConfirmRsp]
}
PasswordResetConfirmService handles the token confirmation step that finalizes the email-driven password reset flow.
func (*PasswordResetConfirmService) Create ¶
func (s *PasswordResetConfirmService) Create(ctx *gst.ServiceContext, req *modelemail.PasswordResetConfirmReq) (rsp *modelemail.PasswordResetConfirmRsp, err error)
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 ¶
type PasswordResetRequestService struct {
service.Base[*modelemail.PasswordResetRequest, *modelemail.PasswordResetRequestReq, *modelemail.PasswordResetRequestRsp]
}
PasswordResetRequestService handles public password reset requests that start the email-driven password recovery flow.
func (*PasswordResetRequestService) Create ¶
func (s *PasswordResetRequestService) Create(ctx *gst.ServiceContext, req *modelemail.PasswordResetRequestReq) (rsp *modelemail.PasswordResetRequestRsp, err error)
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 ¶
func (s *VerificationConfirmService) Create(ctx *gst.ServiceContext, req *modelemail.VerificationConfirmReq) (rsp *modelemail.VerificationConfirmRsp, err error)
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 ¶
func (s *VerificationRequestService) Create(ctx *gst.ServiceContext, req *modelemail.VerificationRequestReq) (rsp *modelemail.VerificationRequestRsp, err error)
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 ¶
func (s *VerificationResendService) Create(ctx *gst.ServiceContext, req *modelemail.VerificationResendReq) (rsp *modelemail.VerificationResendRsp, err error)
Create resends a verification email for an eligible account while keeping the response stable for unknown or already verified accounts.