signupgate

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package signupgate keeps platform sign-up invites and implements the systemauth.SignupGate that enforces them. With the gate installed a deployment creates accounts only for verified emails that hold an invite; people who already have an account sign in as before.

An invite is an email address, not a code: the person proves control of the address by signing in through the upstream provider, and the gate compares that verified address with the invites. Nothing is sent and nothing needs to be typed.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidEmail means the address is not a plain email address.
	ErrInvalidEmail = errors.New("signupgate: not a plain email address")

	// ErrAlreadyRedeemed means an account was already created with the
	// invite. Revoke it to invite the address again.
	ErrAlreadyRedeemed = errors.New("signupgate: invite already redeemed")

	// ErrNotFound means no invite exists for the address.
	ErrNotFound = errors.New("signupgate: no invite for that address")
)

Functions

func NormalizeEmail

func NormalizeEmail(raw string) (string, error)

NormalizeEmail returns the stored form of an address: trimmed and lower-case. A display name, a comment or a missing domain is refused.

func WriteWaitlistCSV

func WriteWaitlistCSV(out io.Writer, entries []WaitlistEntry) error

WriteWaitlistCSV writes entries as CSV with a header row: email, joined and last submitted times (RFC 3339, UTC) and the consent version.

Types

type AddOptions

type AddOptions struct {
	// Note is free-text context for operators.
	Note string
	// InvitedBy labels the operator creating the invite.
	InvitedBy string
	// ExpiresAt ends the invite; nil means it does not expire.
	ExpiresAt *time.Time
}

AddOptions are the optional parts of a new invite.

type Gate

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

Gate is the systemauth.SignupGate over a Store.

func NewGate

func NewGate(store *Store) *Gate

NewGate returns a gate that allows a sign-up when the login's verified email holds a pending invite.

func (*Gate) AllowSignup

func (g *Gate) AllowSignup(ctx context.Context, login systemauth.ExternalLogin) error

AllowSignup implements systemauth.SignupGate. Only a verified email can match: an unverified address is never trusted, and the directory refuses to create an account for one anyway.

func (*Gate) SignedUp

func (g *Gate) SignedUp(ctx context.Context, login systemauth.ExternalLogin, principalID uuid.UUID) error

SignedUp implements systemauth.SignupGate by consuming the invite.

type Invite

type Invite struct {
	Email      string
	Note       string
	InvitedBy  string
	CreatedAt  time.Time
	ExpiresAt  *time.Time
	RedeemedAt *time.Time
	RedeemedBy *uuid.UUID
}

Invite is a sign-up invite as listed to operators.

func (Invite) Status

func (i Invite) Status(now time.Time) string

Status is "redeemed", "expired" or "pending" at the given time.

type Store

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

Store reads and writes invites.

func NewStore

func NewStore(client *ent.Client) *Store

NewStore returns a Store over client.

func (*Store) Add

func (s *Store) Add(ctx context.Context, email string, opts AddOptions) (*Invite, error)

Add creates an invite, or updates the note, label and expiry of a pending one. It returns ErrAlreadyRedeemed for an address that already has an account created through its invite.

func (*Store) Allowed

func (s *Store) Allowed(ctx context.Context, email string) (bool, error)

Allowed reports whether the address holds an invite that is neither redeemed nor expired.

func (*Store) List

func (s *Store) List(ctx context.Context, includeRedeemed bool) ([]Invite, error)

List returns invites ordered by address. Redeemed invites are included only when includeRedeemed is set.

func (*Store) Redeem

func (s *Store) Redeem(ctx context.Context, email string, principalID uuid.UUID) error

Redeem marks the invite for an address as used by the principal. It does nothing, and reports no error, when the invite was already used, so a repeated call is harmless.

func (*Store) Revoke

func (s *Store) Revoke(ctx context.Context, email string) error

Revoke deletes the invite for an address, redeemed or not. Deleting a redeemed invite does not touch the account created with it; it only lets the address be invited again. It returns ErrNotFound when there is none.

type Waitlist

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

Waitlist stores the addresses that asked to be notified while a deployment is invite-only. It sends nothing itself: operators export it.

func NewWaitlist

func NewWaitlist(client *ent.Client) *Waitlist

NewWaitlist returns a Waitlist over client.

func (*Waitlist) Join

func (w *Waitlist) Join(ctx context.Context, email, consentVersion, consentText string) error

Join adds an address, or refreshes the consent recorded for one already listed. Either way the caller learns nothing about whether it was listed before, so a public form built on it cannot be used to probe addresses.

func (*Waitlist) List

func (w *Waitlist) List(ctx context.Context) ([]WaitlistEntry, error)

List returns every entry, oldest first.

func (*Waitlist) Remove

func (w *Waitlist) Remove(ctx context.Context, email string) error

Remove deletes an address, for example on request. It returns ErrNotFound when the address is not listed.

type WaitlistEntry

type WaitlistEntry struct {
	Email          string
	ConsentVersion string
	ConsentText    string
	// CreatedAt is when the address first joined; UpdatedAt when it was
	// last submitted.
	CreatedAt time.Time
	UpdatedAt time.Time
}

WaitlistEntry is an address waiting to be told that sign-up is open.

Directories

Path Synopsis
Package signupcmd provides the operator commands for invite-only sign-up as cobra commands a host CLI mounts: "invite" (add, list, revoke) and "waitlist" (list, remove).
Package signupcmd provides the operator commands for invite-only sign-up as cobra commands a host CLI mounts: "invite" (add, list, revoke) and "waitlist" (list, remove).

Jump to

Keyboard shortcuts

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