db

package
v0.0.0-...-bc94fc3 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package `db` manages the user and roles database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ban

type Ban struct {
	BanID     int
	IPID      string
	HDID      string
	Reason    string
	Moderator string
	Start     time.Time
	End       time.Time
}

Represents a ban in the database.

type Database

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

Represents a connection to the database. Used for database operations, goroutine-safe.

func Init

func Init(path string) (*Database, error)

Opens a connection to the database, creating it and initializing the tables if necessary.

func (*Database) AddAuth

func (d *Database) AddAuth(username string, password string, role string) error

Adds a new user that can authenticate to the passed role.

func (*Database) AddBan

func (d *Database) AddBan(ipid string, hdid string, reason string, moderator string, duration time.Duration) error

Adds a new ban to the database.

func (*Database) CheckAuth

func (d *Database) CheckAuth(username string, password string) (ok bool, role string, err error)

Checks whether a given username and password authenticate to a user. Returns whether the authentication was successful and the role the user has been authenticated to, along with an error should a DB error happen.

func (*Database) CheckBanned

func (d *Database) CheckBanned(ipid string, hdid string) (bool, []Ban, error)

Verify if a given IPID and HDID is banned. If either are a match, returns a list of non-expired bans on this user.

func (*Database) Close

func (d *Database) Close() error

Closes the database connection.

func (*Database) GetBans

func (d *Database) GetBans(ipid string, hdid string) ([]Ban, error)

Gets all bans that correspond to the passed IPID and HDID (including expired ones).

func (*Database) NullBan

func (d *Database) NullBan(id int) error

Nullifies a ban by setting its end time to the current time.

func (*Database) NullBans

func (d *Database) NullBans(ipid string, hdid string) error

Nullifies all bans for the passed IPID and HDID.

func (*Database) RemoveAuth

func (d *Database) RemoveAuth(username string) error

Removes a user from the auth table.

Jump to

Keyboard shortcuts

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