identity

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RequestPending  = "pending"
	RequestApproved = "approved"
	RequestDenied   = "denied"
	// RequestJoin asks to join the installation; RequestAlbum asks to view one Album.
	RequestJoin  = "join"
	RequestAlbum = "album"
)
View Source
const CookieName = "memento_session"
View Source
const HandoffCodeLifetime = time.Minute

HandoffCodeLifetime bounds the hand-off from the browser sheet to the app.

View Source
const MobileExchangePath = "/api/identity/mobile/exchange"

MobileExchangePath is the one browser-API mutation made without a session or a browser Origin, so the server's Origin check lets it through by path.

View Source
const SessionLifetime = 180 * 24 * time.Hour
View Source
const (
	// SignInCodeLifetime is how long an emailed Sign-in Code works.
	SignInCodeLifetime = 10 * time.Minute
)

Variables

View Source
var (
	ErrSignInCodesUnavailable = &errcodes.Error{HTTPCode: 404, Code: "sign_in_codes_unavailable", Message: "Signing in with an emailed code is not available here."}
	// ErrSignInCodeUnsent wraps the mail failure, which the server logs. The
	// browser sees server errors redacted and words this one itself.
	ErrSignInCodeUnsent = &errcodes.Error{HTTPCode: 503, Code: "sign_in_code_unsent", Message: "The sign-in code email could not be sent."}
	// ErrNameRequired means the code is right but the address is unknown: the
	// Person gives a name and verifies again to request access. The code is
	// not spent.
	ErrNameRequired = errors.New("a name is needed to request access")
)
View Source
var (
	ErrPreauthorizationConsumed = &errcodes.Error{HTTPCode: 409, Code: "preauthorization_consumed", Message: "This email has already been used to sign in, so there is nobody left to invite."}
	ErrPreauthorizationRevoked  = &errcodes.Error{HTTPCode: 409, Code: "preauthorization_revoked", Message: "This email approval was revoked. Approve the email again before inviting."}
	ErrPersonDeactivated        = &errcodes.Error{HTTPCode: 409, Code: "person_deactivated", Message: "This person is deactivated. Restore their access before inviting them."}
)
View Source
var (
	ErrAccessDenied    = &errcodes.Error{HTTPCode: 403, Code: "access_denied", Message: "This email does not have access to this installation."}
	ErrUnauthenticated = &errcodes.Error{HTTPCode: 401, Code: "unauthenticated", Message: "Sign in to continue."}
	ErrUnverifiedEmail = &errcodes.Error{HTTPCode: 403, Code: "unverified_email", Message: "Sign-in requires a verified email address."}
	// ErrAccessRequested means the verified address is unknown and a Curator now has one pending request for it.
	ErrAccessRequested = &errcodes.Error{HTTPCode: 403, Code: "access_requested", Message: "This email does not have access yet. Your Curator has been asked to review your request."}
)
View Source
var (
	ErrRequestResolved = &errcodes.Error{HTTPCode: 409, Code: "request_resolved", Message: "This request was already approved. Manage the Person directly instead."}
	ErrEmailInUse      = &errcodes.Error{HTTPCode: 409, Code: "email_in_use", Message: "This email is already approved for or linked to another Person. Review that Person before approving this request."}
)
View Source
var ErrFinalCurator = &errcodes.Error{HTTPCode: 409, Code: "final_curator", Message: "Keep at least one active Curator with a linked email before making this change."}
View Source
var ErrGoogleUnavailable = errors.New("google sign-in is unavailable")

ErrGoogleUnavailable means discovery or token exchange could not complete.

View Source
var ErrHandoffCodeInvalid = &errcodes.Error{HTTPCode: 401, Code: "invalid_code", Message: "That sign-in has expired. Start again from the app."}
View Source
var ErrLastEmail = &errcodes.Error{HTTPCode: 409, Code: "last_email", Message: "Link another email before removing your last one, or ask a Curator to remove it for you."}

Tips lists every Tip. A new one also needs a migration that admits its name to persons.retired_tips.

Functions

func AlbumRequestMessage added in v0.6.0

func AlbumRequestMessage(publicURL, personName, albumTitle string) notifications.Message

AlbumRequestMessage alerts Curators to a Person asking to see an Album. Like JoinRequestMessage, it has no recipient yet.

func InvitationMessage added in v0.6.0

func InvitationMessage(publicURL, personName, curatorName, email string) notifications.Message

InvitationMessage is plain outreach: it names the exact email to sign in with and links to ordinary sign-in. It carries no token or private link.

func JoinRequestMessage added in v0.6.0

func JoinRequestMessage(publicURL, name, email string) notifications.Message

JoinRequestMessage alerts Curators to someone new asking to join. It has no recipient; alertCurators addresses one copy to each Curator.

func RegisterGoogleRoutes

func RegisterGoogleRoutes(e *echo.Echo, cfg *config.Config, module UseCases, options ...GoogleOption)

RegisterGoogleRoutes adds browser sign-in when both Google credentials are configured, without network I/O. Options substitute the provider for local protocol and HTTP tests.

func SignInCodeMessage added in v0.6.0

func SignInCodeMessage(email, code string) notifications.Message

SignInCodeMessage puts the code in the subject, so it shows in a notification without opening the email.

func WithBrowser

func WithBrowser(ctx context.Context, userAgent string) context.Context

WithBrowser labels newly issued sessions without retaining a full user agent.

Types

type AccessRequest

type AccessRequest struct {
	ID string `json:"id"`
	// Kind is join for an unknown address and album for an existing Person's request.
	Kind        string     `json:"kind"`
	Email       string     `json:"email"`
	DisplayName string     `json:"display_name"`
	PersonID    string     `json:"person_id"`
	PersonName  string     `json:"person_name"`
	AlbumID     string     `json:"album_id"`
	AlbumTitle  string     `json:"album_title"`
	Status      string     `json:"status"`
	SignInCount int        `json:"sign_in_count"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
	ResolvedAt  *time.Time `json:"resolved_at"`
	ResolvedBy  string     `json:"resolved_by"`
}

AccessRequest shows what a Curator may inspect. It never asserts that the address and any Person are the same human.

type AdmissionUseCases

type AdmissionUseCases interface {
	CompleteOnboarding(context.Context, string, UpdateProfileRequest) (Person, error)
	SendInvitation(context.Context, string, string, SendInvitationRequest) (Invitation, error)
	RetryInvitation(context.Context, string, string, string) (Invitation, error)
	RequestAlbumAccess(context.Context, string, string) (AccessRequest, error)
	ListAccessRequests(context.Context, string) ([]AccessRequest, error)
	ApproveAccessRequest(context.Context, string, string, ApproveAccessRequestRequest) (AccessRequest, error)
	DenyAccessRequest(context.Context, string, string) (AccessRequest, error)
	ReconsiderAccessRequest(context.Context, string, string) (AccessRequest, error)
}

AdmissionUseCases covers Onboarding, Invitations, and Access Requests.

type AnnouncedContent

type AnnouncedContent struct {
	Albums  int `json:"albums"`
	Entries int `json:"entries"`
}

AnnouncedContent counts a Person's notification baseline.

type Announcements

type Announcements interface {
	RecordBaseline(context.Context, bun.Tx, string) (notifications.Baseline, error)
	RecordOfferedAlbums(context.Context, bun.Tx, string) error
	Announced(context.Context, bun.IDB, string) (notifications.Baseline, error)
}

Announcements is the consumer-owned view of Notifications for Onboarding baselines and for turning "Tell me about albums I can join" back on.

type ApproveAccessRequestRequest

type ApproveAccessRequestRequest struct {
	PersonID    string   `json:"person_id" validate:"omitempty,uuid"`
	DisplayName string   `json:"display_name" validate:"omitempty,max=100" mod:"trim"`
	CircleIDs   []string `json:"circle_ids"`
}

ApproveAccessRequestRequest links an unknown address to an existing Person or creates one, and adds that Person to any picked Circles. Requests from an existing Person need none of the fields.

func (ApproveAccessRequestRequest) ValidationMessage

func (ApproveAccessRequestRequest) ValidationMessage(field, rule string) string

type AuthenticationUseCases

type AuthenticationUseCases interface {
	Claimed(context.Context) (bool, error)
	SignIn(context.Context, Claims) (Session, error)
	Authenticate(context.Context, string) (Session, error)
	SignOut(context.Context, string) error
	SignInCodesAvailable() bool
	RequestSignInCode(context.Context, RequestSignInCodeRequest) error
	VerifySignInCode(context.Context, VerifySignInCodeRequest) (Session, error)
	IssueHandoffCode(context.Context, string) (string, error)
	ExchangeHandoffCode(context.Context, string, string) (Session, error)
}

type BrowserSession

type BrowserSession struct {
	ID            string    `json:"id"`
	LinkedEmailID string    `json:"linked_email_id"`
	Email         string    `json:"email"`
	Device        string    `json:"device"`
	CreatedAt     time.Time `json:"created_at"`
	LastUsedAt    time.Time `json:"last_used_at"`
	ExpiresAt     time.Time `json:"expires_at"`
	Current       bool      `json:"current"`
}

BrowserSession exposes no credential or token hash.

type Circle added in v0.5.0

type Circle struct {
	ID      string   `json:"id"`
	Name    string   `json:"name"`
	Members []Person `json:"members"`
}

Circle is a Curator-named set of People with its members in name order. Circles are Curator-only and never appear in a viewer response.

type CircleMembersRequest added in v0.5.0

type CircleMembersRequest struct {
	PersonIDs []string `json:"person_ids" validate:"required"`
}

CircleMembersRequest is the complete set of People in a Circle.

func (CircleMembersRequest) ValidationMessage added in v0.5.0

func (CircleMembersRequest) ValidationMessage(field, _ string) string

type CircleRequest added in v0.5.0

type CircleRequest struct {
	Name string `json:"name" validate:"required,max=100" mod:"trim"`
}

CircleRequest names a new Circle or renames one.

func (CircleRequest) ValidationMessage added in v0.5.0

func (CircleRequest) ValidationMessage(field, rule string) string

type CircleUseCases added in v0.5.0

type CircleUseCases interface {
	ListCircles(context.Context, string) ([]Circle, error)
	CreateCircle(context.Context, string, CircleRequest) (Circle, error)
	RenameCircle(context.Context, string, string, CircleRequest) (Circle, error)
	DeleteCircle(context.Context, string, string) error
	SetCircleMembers(context.Context, string, string, CircleMembersRequest) (Circle, error)
	SetPersonCircles(context.Context, string, string, PersonCirclesRequest) error
}

type Claims

type Claims struct {
	Email         string
	EmailVerified bool
	DisplayName   string
}

Claims are one verified address and the name the verifier reported. They must come from a trusted adapter, never an unchecked browser body, and any way of verifying an address (Google, a Sign-in Code) produces the same shape.

func FakeClaims

func FakeClaims(request SignInRequest) Claims

FakeClaims treats a typed address as verified, only on explicitly enabled development routes. Real adapters call the same SignIn after verifying it.

type CreatePersonFromFaceRequest

type CreatePersonFromFaceRequest struct {
	DisplayName  string `json:"display_name" validate:"required,max=100" mod:"trim"`
	SourceFaceID string `json:"source_face_id" validate:"required,max=1024" mod:"trim"`
}

func (CreatePersonFromFaceRequest) ValidationMessage

func (CreatePersonFromFaceRequest) ValidationMessage(field, rule string) string

type CreatePersonRequest

type CreatePersonRequest struct {
	DisplayName string `json:"display_name" validate:"required,max=100" mod:"trim"`
}

func (CreatePersonRequest) ValidationMessage

func (CreatePersonRequest) ValidationMessage(field, rule string) string

type ExchangeHandoffCodeRequest added in v0.4.0

type ExchangeHandoffCodeRequest struct {
	Code     string `json:"code" validate:"required,max=64" mod:"trim"`
	Platform string `json:"platform" validate:"required,max=40" mod:"trim"`
}

ExchangeHandoffCodeRequest carries the Hand-off Code the web sign-in gave the Mobile App, and the platform that names its session.

type GoogleOption

type GoogleOption func(*GoogleProvider)

func WithGoogleIssuer

func WithGoogleIssuer(issuer string, client *http.Client) GoogleOption

WithGoogleIssuer substitutes a local OIDC server at the adapter boundary in tests. Production configuration deliberately has no issuer or transport override.

type GoogleProvider

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

GoogleProvider verifies Google credentials before exposing Identity claims. Discovery is lazy, so Google outages do not prevent startup or database health checks.

func NewGoogleProvider

func NewGoogleProvider(clientID, clientSecret, callbackURL string, options ...GoogleOption) *GoogleProvider

func (*GoogleProvider) AuthorizationURL

func (p *GoogleProvider) AuthorizationURL(ctx context.Context, state, nonce, verifier string) (string, error)

AuthorizationURL starts a code flow bound to the caller's one-use state, nonce and PKCE verifier.

func (*GoogleProvider) Exchange

func (p *GoogleProvider) Exchange(ctx context.Context, code, nonce, verifier string) (Claims, error)

Exchange returns only verified claims, never access or refresh tokens.

type Handlers

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

func RegisterRoutes

func RegisterRoutes(e *echo.Echo, cfg *config.Config, module UseCases) *Handlers

RegisterRoutes registers public authentication routes. Protected features reuse the guards.

func (*Handlers) RequireCurator

func (h *Handlers) RequireCurator(next echo.HandlerFunc) echo.HandlerFunc

RequireCurator restricts administration to active Curators.

func (*Handlers) RequirePerson

func (h *Handlers) RequirePerson(next echo.HandlerFunc) echo.HandlerFunc

RequirePerson admits every active signed-in Person, without inventing onboarding completion.

func (*Handlers) RequireSetupOrCurator

func (h *Handlers) RequireSetupOrCurator(next echo.HandlerFunc) echo.HandlerFunc

RequireSetupOrCurator exposes installation diagnostics only to installers or Curators.

type Invitation

type Invitation struct {
	ID                 string             `json:"id"`
	PreauthorizationID string             `json:"preauthorization_id"`
	Email              string             `json:"email"`
	SentBy             string             `json:"sent_by"`
	CreatedAt          time.Time          `json:"created_at"`
	Delivery           InvitationDelivery `json:"delivery"`
}

type InvitationDelivery

type InvitationDelivery struct {
	Status      string     `json:"status"`
	Attempts    int        `json:"attempts"`
	Message     string     `json:"message"`
	UpdatedAt   time.Time  `json:"updated_at"`
	DeliveredAt *time.Time `json:"delivered_at"`
}

InvitationDelivery is Memento's delivery state; status is queued, sending, delivered, failed, or uncertain.

type LinkFaceRequest

type LinkFaceRequest struct {
	SourceFaceID string `json:"source_face_id" validate:"required,max=1024" mod:"trim"`
}

func (LinkFaceRequest) ValidationMessage

func (LinkFaceRequest) ValidationMessage(field, _ string) string

type LinkedEmail added in v0.4.0

type LinkedEmail struct {
	ID        string    `json:"id"`
	Email     string    `json:"email"`
	CreatedAt time.Time `json:"created_at"`
}

LinkedEmail is a Linked Email as the Person page and profile show it.

type LinkedFace

type LinkedFace struct {
	SourceFaceID string `json:"source_face_id"`
	SourceName   string `json:"source_name"`
	ThumbnailURL string `json:"thumbnail_url"`
	ImmichURL    string `json:"immich_url"`
	Avatar       bool   `json:"avatar"`
}

type Mail

Mail is the consumer-owned view of Notifications for Invitations.

type MobileSession added in v0.3.0

type MobileSession struct {
	Token  string `json:"token"`
	Person Person `json:"person"`
}

MobileSession is what the Mobile App keeps after exchanging its code. The token goes in a bearer header; the app never sees a cookie.

type Module

type Module struct {

	// ImmichURL is the browser-reachable Immich origin used for "Open in
	// Immich" links on linked faces. Empty hides those links.
	ImmichURL string
	// PublicURL is the origin Invitation emails point at.
	PublicURL string
	// Mail is nil until the server wires Notifications; Invitations then report SMTP as unconfigured.
	Mail Mail
	// Announcements records the Onboarding baseline and Albums offered while
	// a Person was not hearing about them. Both fail without it.
	Announcements Announcements
	// Sender is nil until mail is configured, which turns Sign-in Codes off.
	Sender Sender
	// contains filtered or unexported fields
}

Module owns Identity transactions. The clock is replaceable for expiry tests.

func New

func New(db *bun.DB, now func() time.Time) *Module

func (*Module) ApproveAccessRequest

func (m *Module) ApproveAccessRequest(ctx context.Context, token, id string, request ApproveAccessRequestRequest) (AccessRequest, error)

ApproveAccessRequest records the decision and, for an unknown address, chooses or creates the Person, adds the Preauthorization that admits it, and adds the Person to the picked Circles. It never writes an Access Decision: Album access stays a separate review.

func (*Module) Authenticate

func (m *Module) Authenticate(ctx context.Context, token string) (Session, error)

Authenticate rejects expired sessions and extends active sessions at most daily.

func (*Module) Claimed

func (m *Module) Claimed(ctx context.Context) (bool, error)

func (*Module) CompleteOnboarding

func (m *Module) CompleteOnboarding(ctx context.Context, token string, request UpdateProfileRequest) (Person, error)

CompleteOnboarding is the one-time Person transition. It saves the confirmed profile and records the notification baseline in the same transaction, so a retry, another identity, or a later sign-in finds it already complete and changes nothing.

func (*Module) CreateCircle added in v0.5.0

func (m *Module) CreateCircle(ctx context.Context, token string, request CircleRequest) (Circle, error)

func (*Module) CreatePerson

func (m *Module) CreatePerson(ctx context.Context, token string, request CreatePersonRequest) (Person, error)

func (*Module) CreatePersonFromFace

func (m *Module) CreatePersonFromFace(ctx context.Context, token string, request CreatePersonFromFaceRequest) (PersonDetail, error)

func (*Module) DeleteCircle added in v0.5.0

func (m *Module) DeleteCircle(ctx context.Context, token, id string) error

DeleteCircle removes a Circle and its memberships. Its People stay.

func (*Module) DenyAccessRequest

func (m *Module) DenyAccessRequest(ctx context.Context, token, id string) (AccessRequest, error)

DenyAccessRequest records a reviewable refusal. Repeated matching sign-ins keep refreshing the denied request without reopening it.

func (*Module) ExchangeHandoffCode added in v0.4.0

func (m *Module) ExchangeHandoffCode(ctx context.Context, code, platform string) (Session, error)

ExchangeHandoffCode issues the app its own session, labeled by platform. The code is consumed as it is read, so concurrent exchanges admit one phone.

func (*Module) GetPerson

func (m *Module) GetPerson(ctx context.Context, token, id string) (PersonDetail, error)

func (*Module) IgnoreFace

func (m *Module) IgnoreFace(ctx context.Context, token, sourceID string) error

func (*Module) IssueHandoffCode added in v0.4.0

func (m *Module) IssueHandoffCode(ctx context.Context, token string) (string, error)

IssueHandoffCode hands the browser's signed-in session over to the Mobile App as a Hand-off Code, and ends that session in the same transaction: the phone's session replaces it, so the next sign-in from the app starts fresh and can be someone else. Expired codes are removed on the way.

func (*Module) LinkFace

func (m *Module) LinkFace(ctx context.Context, token, personID string, request LinkFaceRequest) (PersonDetail, error)

func (*Module) ListAccessRequests

func (m *Module) ListAccessRequests(ctx context.Context, token string) ([]AccessRequest, error)

ListAccessRequests shows pending work first, then recent decisions.

func (*Module) ListCircles added in v0.5.0

func (m *Module) ListCircles(ctx context.Context, token string) ([]Circle, error)

ListCircles returns every Circle in name order with its members.

func (*Module) ListPeople

func (m *Module) ListPeople(ctx context.Context, token, search string) ([]PersonSummary, error)

func (*Module) PendingAccessRequests

func (m *Module) PendingAccessRequests(ctx context.Context) (int, error)

PendingAccessRequests counts requests waiting for a decision, for the Curator dashboard. The dashboard route already requires a Curator.

func (*Module) Preauthorize

func (m *Module) Preauthorize(ctx context.Context, token, personID string, request PreauthorizeRequest) (Preauthorization, error)

func (*Module) Profile

func (m *Module) Profile(ctx context.Context, token string) (Profile, error)

func (*Module) ReconsiderAccessRequest

func (m *Module) ReconsiderAccessRequest(ctx context.Context, token, id string) (AccessRequest, error)

ReconsiderAccessRequest reopens a denied request for a fresh decision.

func (*Module) RenameCircle added in v0.5.0

func (m *Module) RenameCircle(ctx context.Context, token, id string, request CircleRequest) (Circle, error)

func (*Module) RequestAlbumAccess

func (m *Module) RequestAlbumAccess(ctx context.Context, token, albumID string) (AccessRequest, error)

RequestAlbumAccess is the explicit action for an existing Person who reached an Album they cannot see. Visiting alone never calls it. One open request per Person and Album absorbs repeated clicks.

func (*Module) RequestSignInCode added in v0.4.0

func (m *Module) RequestSignInCode(ctx context.Context, request RequestSignInCodeRequest) error

RequestSignInCode emails a new Sign-in Code that replaces any earlier one. It reports success whether or not Memento knows the address, and also when a send limit quietly sends nothing, so nobody can learn who belongs.

func (*Module) ResetTips added in v0.7.0

func (m *Module) ResetTips(ctx context.Context, token string) (Person, error)

ResetTips brings back every Tip for the signed-in Person. Only development installations expose it, so a developer can see the Tips again without creating another Person.

func (*Module) RetireTip added in v0.7.0

func (m *Module) RetireTip(ctx context.Context, token string, tip Tip) (Person, error)

RetireTip records that the signed-in Person dismissed or used a Tip, so no device shows it to them again. Retiring one twice changes nothing.

func (*Module) RetryInvitation

func (m *Module) RetryInvitation(ctx context.Context, token, personID, invitationID string) (Invitation, error)

RetryInvitation is the deliberate resend for failed or uncertain delivery. The delivery record decides whether any work is added, so repeated clicks are safe.

func (*Module) RevokePreauthorization

func (m *Module) RevokePreauthorization(ctx context.Context, token, personID, id string) error

func (*Module) SendInvitation

func (m *Module) SendInvitation(ctx context.Context, token, personID string, request SendInvitationRequest) (Invitation, error)

SendInvitation creates at most one Invitation per Preauthorization and commits its delivery record with the same transaction. Repeating the request returns the existing Invitation instead of sending another email.

func (*Module) Sessions

func (m *Module) Sessions(ctx context.Context, token string) ([]BrowserSession, error)

func (*Module) SetCircleMembers added in v0.5.0

func (m *Module) SetCircleMembers(ctx context.Context, token, id string, request CircleMembersRequest) (Circle, error)

SetCircleMembers makes the given People exactly the Circle's members.

func (*Module) SetPersonAvatar

func (m *Module) SetPersonAvatar(ctx context.Context, token, personID string, request SetPersonAvatarRequest) (PersonDetail, error)

func (*Module) SetPersonCircles added in v0.5.0

func (m *Module) SetPersonCircles(ctx context.Context, token, personID string, request PersonCirclesRequest) error

SetPersonCircles makes the given Circles exactly the ones a Person belongs to.

func (*Module) SignIn

func (m *Module) SignIn(ctx context.Context, claims Claims) (Session, error)

SignIn resolves a verified address with resolveAddress and issues a session, or records an Access Request when no step admits the address.

func (*Module) SignInCodesAvailable added in v0.4.0

func (m *Module) SignInCodesAvailable() bool

SignInCodesAvailable reports whether this Installation can email Sign-in Codes.

func (*Module) SignOut

func (m *Module) SignOut(ctx context.Context, token string) error

SignOut removes only the current browser's session and is safe to repeat.

func (*Module) SignOutEverywhere

func (m *Module) SignOutEverywhere(ctx context.Context, token string) error

func (*Module) UnlinkEmail added in v0.4.0

func (m *Module) UnlinkEmail(ctx context.Context, token, personID, emailID string) error

UnlinkEmail keeps the address on record but removes its sign-in access, ending its sessions. An empty personID selects the signed-in Person. The address is admitted again only through a new Preauthorization.

func (*Module) UpdatePerson

func (m *Module) UpdatePerson(ctx context.Context, token, id string, request UpdatePersonRequest) (Person, error)

func (*Module) UpdateProfile

func (m *Module) UpdateProfile(ctx context.Context, token string, request UpdateProfileRequest) (Profile, error)

func (*Module) VerifySignInCode added in v0.4.0

func (m *Module) VerifySignInCode(ctx context.Context, request VerifySignInCodeRequest) (Session, error)

VerifySignInCode checks the newest code sent to the address and resolves it the way Google sign-in does. A code works once, dies after five wrong guesses, and is not spent when an unknown address must first give a name (ErrNameRequired). With a name, an unknown address spends the code on an Access Request and gets ErrAccessRequested.

type Person

type Person struct {
	ID                    string     `json:"id"`
	DisplayName           string     `json:"display_name"`
	IsCurator             bool       `json:"is_curator"`
	OnboardingCompletedAt *time.Time `json:"onboarding_completed_at"`
	DeactivatedAt         *time.Time `json:"deactivated_at"`
	UpdateEmail           string     `json:"update_email"`
	EmailUpdates          bool       `json:"email_updates"`
	// OfferedAlbumUpdates is "Tell me about albums I can join".
	OfferedAlbumUpdates bool   `json:"offered_album_updates"`
	AvatarURL           string `json:"avatar_url"`
	// RetiredTips are the Tips this Person has dismissed or used, so the
	// viewer never shows them again on any device.
	RetiredTips []Tip `json:"retired_tips"`
}

Person is a public projection, not a writable database model.

type PersonCircle added in v0.5.0

type PersonCircle struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Member bool   `json:"member"`
}

PersonCircle is one Circle on a Person's details page and whether the Person belongs to it.

type PersonCirclesRequest added in v0.5.0

type PersonCirclesRequest struct {
	CircleIDs []string `json:"circle_ids" validate:"required"`
}

PersonCirclesRequest is the complete set of Circles a Person belongs to.

func (PersonCirclesRequest) ValidationMessage added in v0.5.0

func (PersonCirclesRequest) ValidationMessage(field, _ string) string

type PersonDetail

type PersonDetail struct {
	Person            Person             `json:"person"`
	Faces             []LinkedFace       `json:"faces"`
	Emails            []LinkedEmail      `json:"emails"`
	Preauthorizations []Preauthorization `json:"preauthorizations"`
	Invitations       []Invitation       `json:"invitations"`
	Sessions          []BrowserSession   `json:"sessions"`
	Announced         AnnouncedContent   `json:"announced"`
	Circles           []PersonCircle     `json:"circles"`
}

type PersonSummary

type PersonSummary struct {
	Person     `tstype:",extends"`
	Email      string     `json:"email"`
	Access     string     `json:"access"`
	LastSeenAt *time.Time `json:"last_seen_at"`
}

PersonSummary is a People list row: the Person plus where they stand on signing in, so a Curator can see who still needs an email, an approval, or a first visit. Email is the newest linked email, or the newest open Preauthorization when nothing is linked yet. Access is "none", "approved", "linked", or "onboarded"; the last two mean they can sign in.

type Preauthorization

type Preauthorization struct {
	ID         string     `json:"id"`
	Email      string     `json:"email"`
	CreatedAt  time.Time  `json:"created_at"`
	ConsumedAt *time.Time `json:"consumed_at"`
	RevokedAt  *time.Time `json:"revoked_at"`
}

type PreauthorizeRequest

type PreauthorizeRequest struct {
	Email string `json:"email" validate:"required,email,max=254" mod:"trim"`
}

func (PreauthorizeRequest) ValidationMessage

func (PreauthorizeRequest) ValidationMessage(field, rule string) string

type Profile

type Profile struct {
	Person Person        `json:"person"`
	Emails []LinkedEmail `json:"emails"`
}

type ProfileUseCases

type ProfileUseCases interface {
	Profile(context.Context, string) (Profile, error)
	UpdateProfile(context.Context, string, UpdateProfileRequest) (Profile, error)
	Sessions(context.Context, string) ([]BrowserSession, error)
	SignOutEverywhere(context.Context, string) error
	UnlinkEmail(context.Context, string, string, string) error
	RetireTip(context.Context, string, Tip) (Person, error)
	ResetTips(context.Context, string) (Person, error)
}

type RequestSignInCodeRequest added in v0.4.0

type RequestSignInCodeRequest struct {
	Email string `json:"email" validate:"required,email,max=254" mod:"trim"`
}

RequestSignInCodeRequest asks for a Sign-in Code to be emailed to an address.

func (RequestSignInCodeRequest) ValidationMessage added in v0.4.0

func (RequestSignInCodeRequest) ValidationMessage(field, rule string) string

type SendInvitationRequest

type SendInvitationRequest struct {
	PreauthorizationID string `json:"preauthorization_id" validate:"required,uuid"`
}

SendInvitationRequest names the unused Preauthorization the email should describe.

func (SendInvitationRequest) ValidationMessage

func (SendInvitationRequest) ValidationMessage(field, _ string) string

type Sender added in v0.4.0

type Sender interface {
	Send(context.Context, notifications.Message) error
}

Sender delivers one email now. Sign-in Codes skip the durable queue because a code is worthless after ten minutes and a retry is the wrong tool.

type Session

type Session struct {
	Person    Person
	Token     string
	ExpiresAt time.Time
	Renewed   bool
}

Session carries the opaque token only when issuing a new session.

type SetPersonAvatarRequest

type SetPersonAvatarRequest struct {
	SourceFaceID string `json:"source_face_id" validate:"required,max=1024" mod:"trim"`
}

func (SetPersonAvatarRequest) ValidationMessage

func (SetPersonAvatarRequest) ValidationMessage(field, _ string) string

type SignInCodeResult added in v0.4.0

type SignInCodeResult struct {
	Outcome string  `json:"outcome"`
	Person  *Person `json:"person"`
}

SignInCodeResult is where a verified Sign-in Code leaves the browser. Outcome is signed_in with Person set, name_required when an unknown address must give a name and verify again, or requested once a Curator has been asked to review it.

type SignInMethod added in v0.4.0

type SignInMethod string
const (
	SignInMethodCode   SignInMethod = "code"
	SignInMethodGoogle SignInMethod = "google"
	SignInMethodFake   SignInMethod = "fake"
)

type SignInRequest

type SignInRequest struct {
	Email       string `json:"email" validate:"required,email,max=254" mod:"trim"`
	DisplayName string `json:"display_name" validate:"required,max=100" mod:"trim"`
}

SignInRequest supplies claims from the explicitly enabled development provider. Production providers verify their own credentials before calling SignIn.

func (SignInRequest) ValidationMessage

func (SignInRequest) ValidationMessage(field, rule string) string

ValidationMessage supplies sign-in guidance for missing fields.

type Status

type Status struct {
	Claimed bool    `json:"claimed"`
	Person  *Person `json:"person"`
	// AuthMode and SignInCodes remain for older Mobile App clients. The web
	// uses SignInMethods because several methods can be available together.
	AuthMode      string         `json:"auth_mode"`
	SignInMethods []SignInMethod `json:"sign_in_methods"`
	SignInCodes   bool           `json:"sign_in_codes"`
	Version       string         `json:"version"`
}

Status describes installation claiming and the current browser's identity. It is public, and the Mobile App checks Version against the oldest server it supports before sign-in starts.

type Tip added in v0.7.0

type Tip string

Tip names a one-time note pointing a viewer at something Memento does differently from other photo apps.

const (
	TipVideos   Tip = "videos"
	TipJoin     Tip = "join"
	TipChapters Tip = "chapters"
)

type UpdatePersonRequest

type UpdatePersonRequest struct {
	DisplayName string `json:"display_name" validate:"required,max=100" mod:"trim"`
	IsCurator   bool   `json:"is_curator"`
	Deactivated bool   `json:"deactivated"`
	// OfferedAlbumUpdates keeps the current setting when omitted, so older
	// clients never turn it off by leaving it out.
	OfferedAlbumUpdates *bool `json:"offered_album_updates"`
}

func (UpdatePersonRequest) ValidationMessage

func (UpdatePersonRequest) ValidationMessage(field, rule string) string

type UpdateProfileRequest

type UpdateProfileRequest struct {
	DisplayName  string `json:"display_name" validate:"required,max=100" mod:"trim"`
	UpdateEmail  string `json:"update_email" validate:"omitempty,email,max=254"`
	EmailUpdates bool   `json:"email_updates"`
	// OfferedAlbumUpdates keeps the current setting when omitted, so older
	// clients never turn it off by leaving it out.
	OfferedAlbumUpdates *bool `json:"offered_album_updates"`
}

func (UpdateProfileRequest) ValidationMessage

func (UpdateProfileRequest) ValidationMessage(field, rule string) string

type UseCases

UseCases is the HTTP boundary; persistence and claim ordering stay in Module.

type VerifySignInCodeRequest added in v0.4.0

type VerifySignInCodeRequest struct {
	Email       string `json:"email" validate:"required,email,max=254" mod:"trim"`
	Code        string `json:"code" validate:"required,max=20"`
	DisplayName string `json:"display_name" validate:"max=100" mod:"trim"`
}

VerifySignInCodeRequest proves control of an address with the code emailed to it. The name is needed only when an unknown address requests access.

func (VerifySignInCodeRequest) ValidationMessage added in v0.4.0

func (VerifySignInCodeRequest) ValidationMessage(field, rule string) string

Jump to

Keyboard shortcuts

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