Documentation
¶
Overview ¶
Package settings holds the Githome web front's account settings handlers. The account settings tree lives under /settings and is gated to the signed-in viewer: it administers the viewer's own account. The surface is function-private rather than secret (every account has settings), so an anonymous request is bounced to the sign-in form with return_to carrying the page it wanted, the 302 github.com answers; nothing leaks because there is nothing to confirm. Githome backs one account section today, the appearance preference, since the color mode and themes ride cookies the color-mode middleware already reads; the unbacked sections (profile, emails, keys, tokens, sessions, security) get no nav entry rather than a dead link, the same honest absence the profile took for its unbacked tabs. Every mutation posts and redirects, so the no-JS flow lands on a clean GET, and the CSRF guard the page chain installs verifies each post. See implementation/13.
Index ¶
- type AccountSection
- type Deps
- type Flasher
- type Handlers
- func (h *Handlers) Appearance(c *mizu.Ctx) error
- func (h *Handlers) CreateToken(c *mizu.Ctx) error
- func (h *Handlers) DeleteToken(c *mizu.Ctx) error
- func (h *Handlers) Index(c *mizu.Ctx) error
- func (h *Handlers) Keys(c *mizu.Ctx) error
- func (h *Handlers) NewToken(c *mizu.Ctx) error
- func (h *Handlers) Profile(c *mizu.Ctx) error
- func (h *Handlers) SaveAppearance(c *mizu.Ctx) error
- func (h *Handlers) SaveProfile(c *mizu.Ctx) error
- func (h *Handlers) Section(sec AccountSection) mizu.Handler
- func (h *Handlers) Tokens(c *mizu.Ctx) error
- type PAT
- type TokenService
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountSection ¶ added in v0.1.3
type AccountSection struct {
Path string
// contains filtered or unexported fields
}
AccountSection is one stubbed account-settings section: the URL that selects it (exported so the mount can register the route), the page title, and the blankslate heading and description the stub shows.
func AccountSections ¶ added in v0.1.3
func AccountSections() []AccountSection
AccountSections returns the known stubbed sections so the mount can register a route for each. The handler is Section.
type Deps ¶
type Deps struct {
Render *render.Set
View *view.Builder
Flash Flasher
Users *domain.UserService
Tokens TokenService // nil keeps the tokens page on its honest-absence stub
Logger *slog.Logger
}
Deps are the account settings handlers' dependencies: the render set, the view builder for the shell chrome, the flash store for the one-shot outcome notice a save reports after its redirect, the user service for reading and writing account profile fields, and a logger.
type Flasher ¶
Flasher is the slice of the flash store the settings handlers use: stage a one-shot message to show on the page the redirect lands on. The webmw.Flash satisfies it; the narrow interface keeps the handler testable without a cookie round-trip.
type Handlers ¶
type Handlers struct {
// contains filtered or unexported fields
}
Handlers is the account settings handler set. One is built at boot and shared; it holds no per-request state.
func (*Handlers) Appearance ¶
Appearance renders the appearance form, prefilled from the color mode the middleware resolved for this request, so the form opens showing the viewer's current choice rather than a default.
func (*Handlers) CreateToken ¶ added in v0.1.3
CreateToken mints a new token from the form's note and scopes and re-renders the page with the one-time plaintext. It renders rather than redirects: the secret must not survive the response, so it never enters a cookie.
func (*Handlers) DeleteToken ¶ added in v0.1.3
DeleteToken revokes one of the viewer's tokens and redirects back to the list. Deleting a token the viewer does not have lands on the same flash as a double-submit: the row is gone either way.
func (*Handlers) Index ¶
Index redirects the bare /settings root to the first backed section. A bookmark of /settings keeps working as Githome adds sections, always landing on a real page rather than a blank index.
func (*Handlers) Keys ¶ added in v0.1.3
Keys renders the SSH and GPG keys stub. The key store is not backed today, so this page shows an honest-absence message rather than an empty list that looks like everything is working.
func (*Handlers) NewToken ¶ added in v0.1.3
NewToken renders the mint-a-token form at /settings/tokens/new, the dedicated page github.com links to for creating a classic token. It renders the same tokens page the list lives on, whose mint form is the focus here; with no token service wired it falls back to the honest-absence stub.
func (*Handlers) Profile ¶ added in v0.1.3
Profile renders the profile settings form, prefilled with the viewer's current account fields so they only edit what they want to change.
func (*Handlers) SaveAppearance ¶
SaveAppearance validates the submitted mode and themes against the closed catalogs the form offered, writes the three cookies, and redirects back to the form with a flash. The form can only present valid values, so a value outside the catalogs is a forged post: it is rejected with an error flash and no cookie is written, rather than poisoning the preference with a theme that does not exist.
func (*Handlers) SaveProfile ¶ added in v0.1.3
SaveProfile validates and writes the submitted profile fields, then redirects back to the form with a flash notice.
type PAT ¶ added in v0.1.3
type PAT struct {
ID int64
Note string
Scopes string
LastEight string
CreatedAt time.Time
LastUsedAt *time.Time
}
PAT is the displayable summary of one personal access token. It carries everything the page shows and nothing that authenticates.
type TokenService ¶ added in v0.1.3
type TokenService interface {
CreatePAT(ctx context.Context, userPK int64, note string, scopes []string) (string, error)
ListPATs(ctx context.Context, userPK int64) ([]PAT, error)
DeletePAT(ctx context.Context, userPK, id int64) error
}
TokenService is the slice of the auth service the tokens page uses: mint, list, delete. cmd/githome adapts *auth.Service to it; the narrow interface keeps the web front off the auth package and the handler testable with a fake.