database

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SQLiteDB

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

func NewSQLiteDB

func NewSQLiteDB(dbPath string) (*SQLiteDB, error)

NewSQLiteDB initializes a new SQLiteDB instance. - Enables foreign key support. - Ensures schema is created.

func (*SQLiteDB) AddPasswordToHistory added in v0.4.2

func (s *SQLiteDB) AddPasswordToHistory(userID int64, passwordHash string) error

AddPasswordToHistory adds a password hash to the user's password history

func (*SQLiteDB) CleanupExpiredTokens

func (s *SQLiteDB) CleanupExpiredTokens() error

CleanupExpiredTokens removes tokens that have expired or were revoked.

func (*SQLiteDB) CleanupOldPasswords added in v0.4.2

func (s *SQLiteDB) CleanupOldPasswords(userID int64, keep int) error

CleanupOldPasswords removes old password entries keeping only the latest n entries

func (*SQLiteDB) CountActiveTokens

func (s *SQLiteDB) CountActiveTokens(userID int64) (int, error)

CountActiveTokens returns the number of active tokens for a user.

func (*SQLiteDB) CreateAuditLog

func (s *SQLiteDB) CreateAuditLog(log *models.AuditLog) error

CreateAuditLog inserts a new audit log into the audit_logs table.

func (*SQLiteDB) CreateToken

func (s *SQLiteDB) CreateToken(token *models.Token) error

CreateToken inserts a new token into the tokens table.

func (*SQLiteDB) CreateUser

func (s *SQLiteDB) CreateUser(user *models.User) error

User methods CreateUser inserts a new user into the users table.

func (*SQLiteDB) GetPasswordHistory added in v0.4.2

func (s *SQLiteDB) GetPasswordHistory(userID int64, limit int) ([]string, error)

GetPasswordHistory retrieves the password history for a user

func (*SQLiteDB) GetTokenByJTI

func (s *SQLiteDB) GetTokenByJTI(jti string) (*models.Token, error)

GetTokenByJTI retrieves a token by its unique identifier.

func (*SQLiteDB) GetTokenByRefreshToken

func (s *SQLiteDB) GetTokenByRefreshToken(refreshToken string, userID int64) (*models.Token, error)

GetTokenByRefreshToken retrieves a token by its refresh token and user ID.

func (*SQLiteDB) GetUserByID

func (s *SQLiteDB) GetUserByID(id int64) (*models.User, error)

GetUserByID retrieves a user by their ID.

func (*SQLiteDB) GetUserByUsername

func (s *SQLiteDB) GetUserByUsername(username string) (*models.User, error)

GetUserByUsername retrieves a user by their username. - Returns the user record or an error if not found.

func (*SQLiteDB) GetUserSessions

func (s *SQLiteDB) GetUserSessions(userID int64) ([]models.Session, error)

GetUserSessions retrieves all active sessions for a user.

func (*SQLiteDB) ListUsers

func (s *SQLiteDB) ListUsers() ([]models.User, error)

ListUsers retrieves a list of all users in the database.

func (*SQLiteDB) RevokeAllUserTokens

func (s *SQLiteDB) RevokeAllUserTokens(userID int64) error

RevokeAllUserTokens revokes all active tokens for a user.

func (*SQLiteDB) UpdateToken

func (s *SQLiteDB) UpdateToken(token *models.Token) error

UpdateToken updates a token's last used and revoked timestamps.

func (*SQLiteDB) UpdateUser

func (s *SQLiteDB) UpdateUser(user *models.User) error

UpdateUser updates user-specific details such as last login and failed attempts.

func (*SQLiteDB) UpdateUserPassword

func (s *SQLiteDB) UpdateUserPassword(user *models.User) error

UpdateUserPassword updates a user's password and previous passwords.

Jump to

Keyboard shortcuts

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