db

package
v0.0.0-...-062e030 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrThereIsNoSessionTokenForThatUser            = errors.New("There is no session token for that user")
	ErrThereIsNoSessionIdentityForThatSessionToken = errors.New("There is no session identity for that session token")
)
View Source
var ErrUserDoesNotExist = errors.New("User does not exist")
View Source
var ErrUsernameTaken = errors.New("Username taken")

Functions

func ChangeUserBalance

func ChangeUserBalance(username string, change int) (int, error)

func CheckIfUsernameTaken

func CheckIfUsernameTaken(username string) bool

func Connect

func Connect()

func Disconnect

func Disconnect()

func NewUser

func NewUser(username string, passwordHash string) error

func Ping

func Ping(ctx context.Context) error

func RemoveUser

func RemoveUser(username string) error

func RevokeSession

func RevokeSession(sessionToken string) error

RevokeSession removes the SessionIdentity (in the db) that contains the provided session token

Types

type SessionIdentity

type SessionIdentity struct {
	ID             primitive.ObjectID `bson:"_id,omitempty"`
	Username       string             `bson:"username,omitempty"`
	SessionToken   string             `bson:"sessionToken,omitempty"`
	ExpirationDate int64              `bson:"expirationDate,omitempty"`
}

func CreateNewSession

func CreateNewSession(username string, sessionToken string) (SessionIdentity, error)

func FindSessionIdentityFromSessionToken

func FindSessionIdentityFromSessionToken(sessionToken string) (SessionIdentity, error)

type User

type User struct {
	ID           primitive.ObjectID `bson:"_id,omitempty"`
	Username     string             `bson:"username,omitempty"`
	PasswordHash string             `bson:"passwordHash,omitempty"`
	Balance      int                `bson:"balance,omitempty"`
}

func GetUser

func GetUser(username string) (User, error)

Jump to

Keyboard shortcuts

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