store

package
v0.0.0-...-183fe7b Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmailConfig

type EmailConfig struct {
	Address  string
	Port     int
	Username string
	Password string
	From     string
}

type Store

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

func NewStore

func NewStore(db *sql.DB) *Store

func (*Store) ChangeAccountEmail

func (s *Store) ChangeAccountEmail(id int, newEmail string) error

Updates an account email address

func (*Store) ChangeAccountPassword

func (s *Store) ChangeAccountPassword(id int, newPassword string) error

Changes an account password

func (*Store) ChangeLastLogin

func (s *Store) ChangeLastLogin(id int) error

Changes an account last login

func (*Store) DeleteAccount

func (s *Store) DeleteAccount(id int) error

Deletes the account by id

func (*Store) DeleteEmailVerificationCodes

func (s *Store) DeleteEmailVerificationCodes(id int) error

Deletes an email verification code

func (*Store) GenerateBackupCodes

func (s *Store) GenerateBackupCodes(id int, lenght, number int) ([]string, error)

Generates a new set of backup codes

func (*Store) GenerateEmailVerificationCode

func (s *Store) GenerateEmailVerificationCode() (string, error)

Generates a email verification code

func (*Store) GenerateTOTP

func (s *Store) GenerateTOTP(issuer, email, algorithm string) (secret string, qr image.Image, err error)

Genereates a new TOTP secret key and QR code

func (*Store) GetAccountByEmail

func (s *Store) GetAccountByEmail(email string) (*types.Account, error)

Queries the database for an account with a given email

func (*Store) GetAccountByID

func (s *Store) GetAccountByID(id int) (*types.Account, error)

Queries the database for an account with a given id

func (*Store) InitJWT

func (s *Store) InitJWT(secret string) *jwtauth.JWTAuth

Initializes JWT

func (*Store) InitSMTP

func (s *Store) InitSMTP(address string, port int, username, password, from string) *EmailConfig

func (*Store) InvalidateAllSessions

func (s *Store) InvalidateAllSessions(accountID int) error

Invalidats all JWTs for an account

func (*Store) InvalidateSession

func (s *Store) InvalidateSession(token string) error

Invalidates JWTs

func (*Store) IsEmailVerificationCodeValid

func (s *Store) IsEmailVerificationCodeValid(id int, code string) (bool, error)

Compares payload and database email verification codes

func (*Store) IsTOTPBackupCodeValid

func (s *Store) IsTOTPBackupCodeValid(id int, code string) (bool, error)

Validates a TOTP backup code and consumes it

func (*Store) IsTokenValid

func (s *Store) IsTokenValid(token string) (exists bool, err error)

Verifies the JWT is active

func (*Store) LockAccount

func (s *Store) LockAccount(id int, lockTime time.Time) error

Lockes an account

func (*Store) NewAccount

func (s *Store) NewAccount(email, hashedPassword string) error

Inserts a new account in the database

func (*Store) NewBackupCodes

func (s *Store) NewBackupCodes(id int, codes []string) error

Insert TOTP backup codes in the database

func (*Store) NewEmailVerificationCode

func (s *Store) NewEmailVerificationCode(id int, code string) error

Inserts a new email verification code

func (*Store) NewJWT

func (s *Store) NewJWT(claims map[string]interface{}) (string, error)

Creates new JWTs

func (*Store) NewTOTP

func (s *Store) NewTOTP(id int, secret string) error

Inserts a TOTP secret in the database(can replace existing)

func (*Store) Ping

func (s *Store) Ping() error

Pings the database

func (*Store) ResetLoginAttempts

func (s *Store) ResetLoginAttempts(id int) error

Resets an account login attempts

func (*Store) SendEmail

func (s *Store) SendEmail(to, subject, message string) error

Sends a verification email

func (*Store) StartSessionCleanup

func (s *Store) StartSessionCleanup(interval time.Duration)

Cleans up expired JWTs

func (*Store) ToggleAccount2FA

func (s *Store) ToggleAccount2FA(id int, value bool) error

Changes an account 2FA status

func (*Store) TrackLoginAttempts

func (s *Store) TrackLoginAttempts(id, attempts int) error

Changes an account login attempts

func (*Store) ValidateTOTP

func (s *Store) ValidateTOTP(id int, code, algorithm string, skew uint) (bool, error)

Validates a TOTP code using the database stored secret

func (*Store) VerifyAccount

func (s *Store) VerifyAccount(id int) error

Changes an account verification status

Jump to

Keyboard shortcuts

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