Documentation
¶
Index ¶
- Variables
- type EmailTemplate
- type Handler
- func (h *Handler) Cleanup()
- func (h *Handler) SendLoginLink(email string, redirectURL string, lang i18n.Language) error
- func (h *Handler) SetSender(sender Sender)
- func (h *Handler) VerifyOTP(otp string) (email string, redirectURL string, error error)
- func (h *Handler) VerifyToken(token string) (email string, redirectURL string, error error)
- type MockSender
- type SMTPSender
- type SendCall
- type SendGridSender
- type SendHTMLCall
- type Sender
- type SendmailSender
- type Token
- type TokenStore
- func (s *TokenStore) CleanupExpired()
- func (s *TokenStore) Count() int
- func (s *TokenStore) DeleteToken(tokenValue string)
- func (s *TokenStore) GenerateToken(email string, redirectURL string, duration time.Duration) (string, error)
- func (s *TokenStore) VerifyOTP(otpInput string) (email string, redirectURL string, err error)
- func (s *TokenStore) VerifyToken(tokenValue string) (email string, redirectURL string, err error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTokenNotFound is returned when a token is not found ErrTokenNotFound = errors.New("token not found") // ErrTokenExpired is returned when a token has expired ErrTokenExpired = errors.New("token has expired") // ErrTokenAlreadyUsed is returned when a token has already been used ErrTokenAlreadyUsed = errors.New("token has already been used") )
Functions ¶
This section is empty.
Types ¶
type EmailTemplate ¶
type EmailTemplate struct {
// contains filtered or unexported fields
}
EmailTemplate generates HTML emails using Hermes
func NewEmailTemplate ¶
func NewEmailTemplate(serviceName, logoURL, logoWidth, iconURL, baseURL string) *EmailTemplate
NewEmailTemplate creates a new email template generator
func (*EmailTemplate) GenerateLoginEmail ¶
func (t *EmailTemplate) GenerateLoginEmail(loginURL, otp string, validMinutes int, lang i18n.Language, translator *i18n.Translator) (htmlBody, textBody string, err error)
GenerateLoginEmail generates HTML and plain text for login link email
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler manages email authentication
func NewHandler ¶
func NewHandler( cfg config.EmailAuthConfig, serviceCfg config.ServiceConfig, baseURL string, authPathPrefix string, authzChecker authz.Checker, translator *i18n.Translator, cookieSecret string, tokenKVS kvs.Store, emailQuotaKVS kvs.Store, ) (*Handler, error)
NewHandler creates a new email authentication handler
func (*Handler) SendLoginLink ¶
SendLoginLink sends a login link to the specified email address with redirect URL
type MockSender ¶
type MockSender struct {
SendFunc func(to, subject, body string) error
SendHTMLFunc func(to, subject, htmlBody, textBody string) error
Calls []SendCall
HTMLCalls []SendHTMLCall
}
MockSender is a mock email sender for testing
func (*MockSender) Send ¶
func (m *MockSender) Send(to, subject, body string) error
Send records the call and optionally executes a custom function
func (*MockSender) SendHTML ¶
func (m *MockSender) SendHTML(to, subject, htmlBody, textBody string) error
SendHTML records the call and optionally executes a custom function
type SMTPSender ¶
type SMTPSender struct {
// contains filtered or unexported fields
}
SMTPSender sends emails via SMTP
func NewSMTPSender ¶
func NewSMTPSender(cfg config.SMTPConfig, parentEmail, parentName string) *SMTPSender
NewSMTPSender creates a new SMTP email sender
func (*SMTPSender) Send ¶
func (s *SMTPSender) Send(to, subject, body string) error
Send sends an email via SMTP
func (*SMTPSender) SendHTML ¶
func (s *SMTPSender) SendHTML(to, subject, htmlBody, textBody string) error
SendHTML sends an HTML email with plain text fallback via SMTP
type SendGridSender ¶
type SendGridSender struct {
// contains filtered or unexported fields
}
SendGridSender sends emails via SendGrid API
func NewSendGridSender ¶
func NewSendGridSender(cfg config.SendGridConfig, parentEmail, parentName string) *SendGridSender
NewSendGridSender creates a new SendGrid email sender
func (*SendGridSender) Send ¶
func (s *SendGridSender) Send(to, subject, body string) error
Send sends an email via SendGrid API
func (*SendGridSender) SendHTML ¶
func (s *SendGridSender) SendHTML(to, subject, htmlBody, textBody string) error
SendHTML sends an HTML email with plain text fallback via SendGrid API
type SendHTMLCall ¶
SendHTMLCall represents a call to SendHTML
type Sender ¶
type Sender interface {
Send(to, subject, body string) error
SendHTML(to, subject, htmlBody, textBody string) error
}
Sender is an interface for sending emails
type SendmailSender ¶ added in v0.2.0
type SendmailSender struct {
// contains filtered or unexported fields
}
SendmailSender sends emails via sendmail command
func NewSendmailSender ¶ added in v0.2.0
func NewSendmailSender(cfg config.SendmailConfig, parentEmail, parentName string) *SendmailSender
NewSendmailSender creates a new sendmail sender
func (*SendmailSender) Send ¶ added in v0.2.0
func (s *SendmailSender) Send(to, subject, body string) error
Send sends an email via sendmail command
func (*SendmailSender) SendHTML ¶ added in v0.2.0
func (s *SendmailSender) SendHTML(to, subject, htmlBody, textBody string) error
SendHTML sends an HTML email with plain text fallback via sendmail command
type Token ¶
type Token struct {
Value string
Email string
OTP string // One-Time Password (12-character alphanumeric)
RedirectURL string // Original URL to redirect to after authentication
CreatedAt time.Time
ExpiresAt time.Time
Used bool
}
Token represents an email authentication token
type TokenStore ¶
type TokenStore struct {
// contains filtered or unexported fields
}
TokenStore manages email authentication tokens using a KVS backend
func NewTokenStore ¶
func NewTokenStore(secret string, kvsStore kvs.Store) *TokenStore
NewTokenStore creates a new token store backed by KVS
func (*TokenStore) CleanupExpired ¶
func (s *TokenStore) CleanupExpired()
CleanupExpired removes expired tokens (no-op for KVS with TTL support) The underlying KVS automatically handles expiration, so this is a no-op for compatibility.
func (*TokenStore) Count ¶
func (s *TokenStore) Count() int
Count returns the number of tokens (for testing)
func (*TokenStore) DeleteToken ¶
func (s *TokenStore) DeleteToken(tokenValue string)
DeleteToken removes a token from the store
func (*TokenStore) GenerateToken ¶
func (s *TokenStore) GenerateToken(email string, redirectURL string, duration time.Duration) (string, error)
GenerateToken generates a new token for an email address with redirect URL
func (*TokenStore) VerifyOTP ¶
func (s *TokenStore) VerifyOTP(otpInput string) (email string, redirectURL string, err error)
VerifyOTP verifies an OTP and returns the associated email and redirect URL
func (*TokenStore) VerifyToken ¶
func (s *TokenStore) VerifyToken(tokenValue string) (email string, redirectURL string, err error)
VerifyToken verifies a token and returns the associated email and redirect URL