Documentation
¶
Index ¶
- Constants
- Variables
- func AuthMiddleware(s *Service) gin.HandlerFunc
- func RequireHousehold() gin.HandlerFunc
- func RunCleanup(ctx context.Context, service *Service)
- type Handler
- func (h *Handler) Authenticate(c *gin.Context)
- func (h *Handler) Login(c *gin.Context)
- func (h *Handler) Logout(c *gin.Context)
- func (h *Handler) Register(c *gin.Context)
- func (h *Handler) RegisterView(c *gin.Context)
- func (h *Handler) SetupHousehold(c *gin.Context)
- func (h *Handler) WelcomeView(c *gin.Context)
- type Repo
- func (r *Repo) AddSession(ctx context.Context, session Session) (string, error)
- func (r *Repo) ConsumeToken(ctx context.Context, token string) error
- func (r *Repo) CreateHousehold(ctx context.Context, householdName string, userId int) error
- func (r *Repo) CreateUser(ctx context.Context, username string, hash string) (int, error)
- func (r *Repo) ExtendSession(ctx context.Context, id string, newExpiry time.Time) error
- func (r *Repo) JoinHousehold(ctx context.Context, inviteCode string, userId int) error
- func (r *Repo) RemoveExpiredSessions(ctx context.Context) error
- func (r *Repo) RemoveSession(ctx context.Context, id string) error
- func (r *Repo) User(ctx context.Context, uname string) (User, error)
- func (r *Repo) ValidateToken(ctx context.Context, token string) (bool, error)
- type Service
- func (s *Service) Authenticate(ctx context.Context, uname, pwd string) (string, error)
- func (s *Service) CreateHousehold(ctx context.Context, householdName string, userId int) error
- func (s *Service) CreateSessionForUser(ctx context.Context, userID int) (string, error)
- func (s *Service) CreateUser(ctx context.Context, username, pwd, token string) (int, error)
- func (s *Service) ExtendSession(ctx context.Context, sessionID string, ttl time.Duration) error
- func (s *Service) GetSession(ctx context.Context, sessionID string) (Session, error)
- func (s *Service) JoinHousehold(ctx context.Context, inviteCode string, userId int) error
- func (s *Service) Logout(ctx context.Context, uuid string)
- func (s *Service) RemoveExpiredSessions(ctx context.Context) error
- func (s *Service) ValidateToken(ctx context.Context, token string) (bool, error)
- type Session
- type User
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 ¶
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
func NewHandler ¶
func (*Handler) Authenticate ¶
func (*Handler) RegisterView ¶
func (*Handler) SetupHousehold ¶
func (*Handler) WelcomeView ¶
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
func (*Repo) AddSession ¶
func (*Repo) CreateHousehold ¶
func (*Repo) CreateUser ¶
func (*Repo) ExtendSession ¶
func (*Repo) JoinHousehold ¶
func (*Repo) RemoveExpiredSessions ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) Authenticate ¶
func (*Service) CreateHousehold ¶
func (*Service) CreateSessionForUser ¶
func (*Service) CreateUser ¶
func (*Service) ExtendSession ¶
func (*Service) GetSession ¶
func (*Service) JoinHousehold ¶
func (*Service) RemoveExpiredSessions ¶
Click to show internal directories.
Click to hide internal directories.