pgrepo

package
v0.34.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	SessionTTL  time.Duration
	AbsoluteTTL time.Duration

	PATPrefix string
}

type Repo

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

func New

func New(pool *pgxpool.Pool, cfg Config) *Repo

func (*Repo) CleanupAttempts

func (r *Repo) CleanupAttempts(ctx context.Context, before time.Time) error

func (*Repo) ConfirmMFA added in v0.5.0

func (r *Repo) ConfirmMFA(ctx context.Context, userID string, now time.Time) error

func (*Repo) ConfirmSessionMFA added in v0.5.0

func (r *Repo) ConfirmSessionMFA(ctx context.Context, sessionID string, now time.Time) error

ConfirmSessionMFA stamps mfa_confirmed_at on a live session — the second freshness fact (POST /auth/verify-mfa step-up), symmetric to ConfirmSessionPassword.

func (*Repo) ConfirmSessionPassword added in v0.4.0

func (r *Repo) ConfirmSessionPassword(ctx context.Context, sessionID string, now time.Time) error

func (*Repo) ConsumeBackupCode added in v0.5.0

func (r *Repo) ConsumeBackupCode(ctx context.Context, userID, codeHash string, now time.Time) (bool, error)

ConsumeBackupCode marks one pending code consumed in a single conditional UPDATE — consume-once under concurrency without an application-level lock.

func (*Repo) ConsumeChallenge

func (r *Repo) ConsumeChallenge(ctx context.Context, id string) error

func (*Repo) CountRecentAttempts

func (r *Repo) CountRecentAttempts(ctx context.Context, ipHash, identity string, since time.Time) (int, error)

func (*Repo) CreateChallenge

func (r *Repo) CreateChallenge(ctx context.Context, email, kind, secretHash string, expiresAt time.Time) error

func (*Repo) CreateImpersonatedSession

func (r *Repo) CreateImpersonatedSession(ctx context.Context, userID, impersonatedBy, ipHash, userAgent string, now time.Time) (string, time.Time, error)

func (*Repo) CreatePAT

func (r *Repo) CreatePAT(ctx context.Context, userID, name, tokenHash, prefix string, expiresAt *time.Time, scope *webx.CredentialScope) (app.PAT, error)

func (*Repo) CreateSession

func (r *Repo) CreateSession(ctx context.Context, in webx.SessionCreate) (string, time.Time, error)

func (*Repo) CreateUserWithPassword

func (r *Repo) CreateUserWithPassword(ctx context.Context, email, passwordHash, displayName string) (app.User, error)

func (*Repo) CreateUserWithPasswordTx

func (r *Repo) CreateUserWithPasswordTx(ctx context.Context, tx pgx.Tx, email, passwordHash, displayName string) (app.User, error)

func (*Repo) DeleteFedProvider

func (r *Repo) DeleteFedProvider(ctx context.Context, workspaceID string) error

func (*Repo) DeleteMFA added in v0.5.0

func (r *Repo) DeleteMFA(ctx context.Context, userID string) error

func (*Repo) EarliestRecentAttempt added in v0.11.3

func (r *Repo) EarliestRecentAttempt(ctx context.Context, ipHash, identity string, since time.Time) (time.Time, bool, error)

func (*Repo) FindOAuthAccount

func (r *Repo) FindOAuthAccount(ctx context.Context, provider, subject string) (string, bool, error)

func (*Repo) GetFedProvider

func (r *Repo) GetFedProvider(ctx context.Context, workspaceID string) (*app.FedProviderRow, bool, error)

func (*Repo) GetMFA added in v0.5.0

func (r *Repo) GetMFA(ctx context.Context, userID string) (secretSealed string, confirmedAt *time.Time, ok bool, err error)

func (*Repo) GetUser

func (r *Repo) GetUser(ctx context.Context, id string) (app.User, error)

func (*Repo) GetUserByEmail

func (r *Repo) GetUserByEmail(ctx context.Context, email string) (app.User, bool, error)

func (*Repo) IncChallengeAttempts

func (r *Repo) IncChallengeAttempts(ctx context.Context, id string) error

func (*Repo) LatestPendingChallenge

func (r *Repo) LatestPendingChallenge(ctx context.Context, email, kind string) (*app.Challenge, error)

func (*Repo) LinkOAuthAccount

func (r *Repo) LinkOAuthAccount(ctx context.Context, provider, subject, userID, emailAtLink string, now time.Time) error

LinkOAuthAccount 绑定 (provider, subject) → user。旧实现 ON CONFLICT DO NOTHING 静默吞掉「已绑到另一用户」的冲突(OA-1,oauth-admin-config- audit-2026-10-31):同一 provider 账号在改邮箱瞬间并发两次回调会造出 第二个用户且登录成功,而 oauth_account 行永久指向第一个用户——下次 登录回到旧账号,身份漂移且无告警。现在冲突时回读既有行比对 user_id: 一致(幂等重放)正常返回;不一致 fail-closed 报 app.ErrOAuthLinkConflict, 本次登录失败、用户重点一次即走 FindOAuthAccount 命中既有绑定。

func (*Repo) ListPATs

func (r *Repo) ListPATs(ctx context.Context, userID string) ([]app.PAT, error)

func (*Repo) ListUserSessions

func (r *Repo) ListUserSessions(ctx context.Context, userID string) ([]app.SessionInfo, error)

func (*Repo) ListUsersByIDs added in v0.5.0

func (r *Repo) ListUsersByIDs(ctx context.Context, ids []string) ([]app.User, error)

ListUsersByIDs batch-resolves users (aifengkong #7); unlike GetUser it returns rows regardless of status (a disabled author still deserves a name on audit trails) and skips missing ids instead of failing.

func (*Repo) RecordAttempt

func (r *Repo) RecordAttempt(ctx context.Context, ipHash, identity string, success bool, at time.Time) error

func (*Repo) RenewSession

func (r *Repo) RenewSession(ctx context.Context, token string, now time.Time) (time.Time, bool, error)

func (*Repo) ReplaceBackupCodes added in v0.5.0

func (r *Repo) ReplaceBackupCodes(ctx context.Context, userID string, codeHashes []string, now time.Time) error

func (*Repo) ResolvePAT

func (r *Repo) ResolvePAT(ctx context.Context, token string, now time.Time) (*webx.Principal, error)

func (*Repo) RevokeAllUserSessions

func (r *Repo) RevokeAllUserSessions(ctx context.Context, userID string) error

func (*Repo) RevokePAT

func (r *Repo) RevokePAT(ctx context.Context, userID, patID string, now time.Time) error

func (*Repo) RevokeSession

func (r *Repo) RevokeSession(ctx context.Context, token string) error

func (*Repo) RevokeUserSessionByID

func (r *Repo) RevokeUserSessionByID(ctx context.Context, userID, sessionID string, now time.Time) error

func (*Repo) RunInTx

func (r *Repo) RunInTx(ctx context.Context, fn func(ctx context.Context, tx pgx.Tx) error) error

func (*Repo) SetEmailVerified

func (r *Repo) SetEmailVerified(ctx context.Context, userID string, at time.Time) error

func (*Repo) SetPasswordHash

func (r *Repo) SetPasswordHash(ctx context.Context, userID, passwordHash string, now time.Time) error

func (*Repo) SoftDeleteUserTx

func (r *Repo) SoftDeleteUserTx(ctx context.Context, tx pgx.Tx, userID string, now time.Time) error

func (*Repo) UpdateProfile

func (r *Repo) UpdateProfile(ctx context.Context, id, displayName, avatarURL string) (app.User, error)

func (*Repo) UpsertFedProvider

func (r *Repo) UpsertFedProvider(ctx context.Context, row *app.FedProviderRow, now time.Time) error

func (*Repo) UpsertPendingMFA added in v0.5.0

func (r *Repo) UpsertPendingMFA(ctx context.Context, userID, secretSealed string, now time.Time) error

func (*Repo) UpsertUserByEmail

func (r *Repo) UpsertUserByEmail(ctx context.Context, email string, now time.Time) (app.User, error)

func (*Repo) VerifySession

func (r *Repo) VerifySession(ctx context.Context, token string, now time.Time) (*webx.Principal, error)

Jump to

Keyboard shortcuts

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