emailverifier

package
v1.5.1-0...-475df33 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package emailverifier implements email-verified self-registration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SendVerificationEmail

func SendVerificationEmail(cfg config.SMTP, to, code string) error

SendVerificationEmail mirrors emailVerifier.ts's sendVerificationEmail: a multipart/alternative (text + html) message with the same subject and bodies, sent via cfg (Config.values.smtp).

cfg.Secure mirrors nodemailer's `secure` option: true dials straight into TLS (SMTPS, typically port 465); false dials plaintext and upgrades via STARTTLS if the server offers it - which is exactly what net/smtp.SendMail already does unconditionally, so that branch reuses it directly rather than reimplementing STARTTLS negotiation.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store mirrors emailVerifier.ts's module-level `pending` map plus its setInterval sweep, wrapped in a struct per this codebase's usual pattern for what was process-global state in Node.

func New

func New() *Store

New starts the periodic expiry sweep immediately, matching the module-level `setInterval(...)` in emailVerifier.ts running from the moment the file is first imported.

func (*Store) AllowRegistration

func (s *Store) AllowRegistration(ip, email string) bool

AllowRegistration limits verification-email delivery by source IP and normalized email address. The check and increment are atomic so concurrent WebSocket connections cannot bypass the limit by racing one another.

func (*Store) Stop

func (s *Store) Stop()

Stop halts the periodic sweep. Not present in the Node original (a long-running process never needs to cancel its setInterval) - added so Go tests and graceful shutdown don't leak a background timer.

func (*Store) StorePending

func (s *Store) StorePending(user, hashedPassword, email string) (string, error)

StorePending mirrors emailVerifier.ts's storePending.

func (*Store) VerifyCode

func (s *Store) VerifyCode(user, code string) *Verified

VerifyCode mirrors emailVerifier.ts's verifyCode exactly, including incrementing Attempts before the max-attempts check (so the Nth failed attempt at MAX_ATTEMPTS is the one that evicts the entry) and comparing codes via a constant-time comparison (internal/auth.SafeCompareTokens, the same helper server/util.ts's safeCompareTokens backs both here and in session-token comparison).

type Verified

type Verified struct {
	HashedPassword string
	Email          string
}

Verified mirrors verifyCode's `Pick<PendingRegistration, "hashedPassword" | "email">` return type.

Jump to

Keyboard shortcuts

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