Documentation
¶
Index ¶
- Variables
- type GormService
- func (s *GormService) ChangePassword(ctx context.Context, currentPassword, newPassword string) error
- func (s *GormService) CleanupExpiredSessions(ctx context.Context) error
- func (s *GormService) HasPassword(ctx context.Context) (bool, error)
- func (s *GormService) Login(ctx context.Context, password string, rememberMe bool) (string, time.Time, error)
- func (s *GormService) Logout(ctx context.Context, token string)
- func (s *GormService) SetLogger(l *slog.Logger)
- func (s *GormService) SetPassword(ctx context.Context, password string) error
- func (s *GormService) ValidateSession(ctx context.Context, token string) (Session, bool)
- type Session
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidCredentials = errors.New("invalid password")
ErrInvalidCredentials is returned when a password check fails.
var ErrPasswordNotSet = errors.New("dashboard password is not set")
ErrPasswordNotSet is returned when the server starts without a dashboard password.
Functions ¶
This section is empty.
Types ¶
type GormService ¶ added in v0.4.0
type GormService struct {
// contains filtered or unexported fields
}
GormService manages the dashboard password and dashboard sessions on the SQLite handles. The dashboard has one operator and no accounts: the password hash lives in the durable database, sessions in the cache file. Session tokens persist as SHA-256 hashes only; the plaintext token returns once at login and never lands in storage. Every statement runs through gorm.G with typed clauses.
func NewGorm ¶ added in v0.4.0
func NewGorm(database *db.Database) *GormService
NewGorm constructs a GORM-backed admin service on the SQLite handle. Construction performs no I/O.
func (*GormService) ChangePassword ¶ added in v0.4.0
func (s *GormService) ChangePassword(ctx context.Context, currentPassword, newPassword string) error
ChangePassword verifies the current password and stores the new hash. A wrong current password denies with ErrInvalidCredentials. Existing sessions survive.
func (*GormService) CleanupExpiredSessions ¶ added in v0.4.0
func (s *GormService) CleanupExpiredSessions(ctx context.Context) error
CleanupExpiredSessions removes sessions expired before now through the expires_at index on the cache handle. Valid sessions survive.
func (*GormService) HasPassword ¶ added in v0.8.1
func (s *GormService) HasPassword(ctx context.Context) (bool, error)
HasPassword reports whether the dashboard password is set. A true answer is cached: the password is never removed.
func (*GormService) Login ¶ added in v0.4.0
func (s *GormService) Login(ctx context.Context, password string, rememberMe bool) (string, time.Time, error)
Login verifies the password and persists a hashed session. The plaintext token returns once and never persists. A wrong or unset password denies with ErrInvalidCredentials.
func (*GormService) Logout ¶ added in v0.4.0
func (s *GormService) Logout(ctx context.Context, token string)
Logout invalidates a session token. Missing tokens are not errors.
func (*GormService) SetLogger ¶ added in v0.4.0
func (s *GormService) SetLogger(l *slog.Logger)
SetLogger sets structured logging.
func (*GormService) SetPassword ¶ added in v0.8.1
func (s *GormService) SetPassword(ctx context.Context, password string) error
SetPassword stores a new password hash without asking for the current password. Local database access is root-equivalent: this path serves CLI operators, never the dashboard. Existing sessions survive.
func (*GormService) ValidateSession ¶ added in v0.4.0
ValidateSession reports whether a session token is valid and not expired. The common path is read-only: the expiration moves forward only when less than half the session duration remains, so parallel dashboard calls never contend on one row. A failed refresh never invalidates a verified session. Expired sessions delete best-effort.