login

package
v0.0.0-...-e9e14f9 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const MaxSessionLifetime = 30 * 24 * time.Hour // 30 days
View Source
const SessionTTL = 14 * 24 * time.Hour

Variables

View Source
var ErrNotFound = errors.New("login: not found")

ErrNotFound is returned when a user or session lookup yields no row.

Functions

func AuthMiddleware

func AuthMiddleware(s *Service) gin.HandlerFunc

func RequireHousehold

func RequireHousehold() gin.HandlerFunc

RequireHousehold guards routes that act on a household. The household is resolved per request from current membership (see getSession), so a user who has been removed from their household no longer has a household_id and is sent to onboarding instead of being allowed to operate on it.

func RunCleanup

func RunCleanup(ctx context.Context, service *Service)

Types

type Handler

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

func NewHandler

func NewHandler(s *Service) *Handler

func (*Handler) Authenticate

func (h *Handler) Authenticate(c *gin.Context)

func (*Handler) Login

func (h *Handler) Login(c *gin.Context)

func (*Handler) Logout

func (h *Handler) Logout(c *gin.Context)

func (*Handler) Register

func (h *Handler) Register(c *gin.Context)

func (*Handler) RegisterView

func (h *Handler) RegisterView(c *gin.Context)

func (*Handler) SetupHousehold

func (h *Handler) SetupHousehold(c *gin.Context)

func (*Handler) WelcomeView

func (h *Handler) WelcomeView(c *gin.Context)

type Repo

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

func NewRepo

func NewRepo(db *pgxpool.Pool) *Repo

func (*Repo) AddSession

func (r *Repo) AddSession(ctx context.Context, session Session) (string, error)

func (*Repo) ConsumeToken

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

func (*Repo) CreateHousehold

func (r *Repo) CreateHousehold(ctx context.Context, householdName string, userId int) error

func (*Repo) CreateUser

func (r *Repo) CreateUser(ctx context.Context, username string, hash string) (int, error)

func (*Repo) ExtendSession

func (r *Repo) ExtendSession(ctx context.Context, id string, newExpiry time.Time) error

func (*Repo) JoinHousehold

func (r *Repo) JoinHousehold(ctx context.Context, inviteCode string, userId int) error

func (*Repo) RemoveExpiredSessions

func (r *Repo) RemoveExpiredSessions(ctx context.Context) error

func (*Repo) RemoveSession

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

func (*Repo) User

func (r *Repo) User(ctx context.Context, uname string) (User, error)

func (*Repo) ValidateToken

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

type Service

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

func NewService

func NewService(repo *Repo) *Service

func (*Service) Authenticate

func (s *Service) Authenticate(ctx context.Context, uname, pwd string) (string, error)

func (*Service) CreateHousehold

func (s *Service) CreateHousehold(ctx context.Context, householdName string, userId int) error

func (*Service) CreateSessionForUser

func (s *Service) CreateSessionForUser(ctx context.Context, userID int) (string, error)

func (*Service) CreateUser

func (s *Service) CreateUser(ctx context.Context, username, pwd, token string) (int, error)

func (*Service) ExtendSession

func (s *Service) ExtendSession(ctx context.Context, sessionID string, ttl time.Duration) error

func (*Service) GetSession

func (s *Service) GetSession(ctx context.Context, sessionID string) (Session, error)

func (*Service) JoinHousehold

func (s *Service) JoinHousehold(ctx context.Context, inviteCode string, userId int) error

func (*Service) Logout

func (s *Service) Logout(ctx context.Context, uuid string)

func (*Service) RemoveExpiredSessions

func (s *Service) RemoveExpiredSessions(ctx context.Context) error

func (*Service) ValidateToken

func (s *Service) ValidateToken(ctx context.Context, token string) (bool, error)

type Session

type Session struct {
	ID          string
	User        User
	HouseholdID *int
	ExpiresAt   time.Time
	CreatedAt   time.Time
}

type User

type User struct {
	ID      int
	Uname   string
	Hash    string
	IsAdmin bool
}

Jump to

Keyboard shortcuts

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