account

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(client *mongo.Client, ctx context.Context, account *Account, database string) (int64, error)

This function deletes the account given in the function parameters.

It returns the count of deleted accounts, which can be either 0 or 1, or an error when something went wrong while deleting the database entry.

func DeleteByEmail

func DeleteByEmail(client *mongo.Client, ctx context.Context, database string, email string) (int64, error)

This function deletes the account with the email given in the function parameters.

It returns the count of deleted accounts, which can be either 0 or 1, or an error when something went wrong while deleting the database entry.

func Insert

func Insert(client *mongo.Client, ctx context.Context, database string, account *Account) error

This function inserts the session given in its parameters into the database. If anything went wrong during the insertion, returns an error.

func Update

func Update(account *Account, client *mongo.Client, ctx context.Context, database string, changes bson.D) (*mongo.UpdateResult, error)

Updates the account given in the functino parameters with the specified changes, also given in the function parameters.

Types

type Account

type Account struct {
	ID        primitive.ObjectID `bson:"_id"`
	CreatedAt time.Time          `bson:"created_at"`
	UpdatedAt time.Time          `bson:"updated_at"`
	// The permission level is to be freely interpreted
	// and used by the one using the library.
	// Defaults to global.DEFAULT_PERMISSION_LEVEL
	PermissionLevel uint8 `bson:"permission_level"`
	// This is the email associated to the account.
	// It is used as the primary identification of the account.
	Email string `bson:"email"`
	// The hash of the password.
	Pass []byte `bson:"pass"`
	// A randomly generated salt used for hashing.
	Salt []byte `bson:"salt"`
	// Whether to enable multi-factor authentication.
	MFAEnabled bool `bson:"mfa_enabled"`
	// The secret used for generating one time passwords.
	OTPSecret string `bson:"otp_secret"`
	// A list of fallback recovery codes.
	OTPRecoveryCodes []string `bson:"otp_recovery_codes"`
	// This field can be set to anything the library user
	// wants to additionaly store inside the account entry
	// in the database.
	CustomData interface{} `bson:"custom_data"`
}

This type represents an account in the database

func Find

func Find(db *mongo.Client, ctx context.Context, database string, condition primitive.E) (*Account, error)

This function searches the database for an account matching the given contdition and returns it if it was found. If no match was found, returns an error.

func FindByEmail

func FindByEmail(db *mongo.Client, ctx context.Context, database string, email string) (*Account, error)

This function searches the database for a user with the given email and returns it if it was found. If no match was found, returns an error.

func FindByID

func FindByID(db *mongo.Client, ctx context.Context, database string, ID primitive.ObjectID) (*Account, error)

This function searches the database for a user with the given ID and returns it if it was found. If no match was found, returns an error.

func (*Account) Delete

func (account *Account) Delete(client *mongo.Client, ctx context.Context, database string) (int64, error)

This function deletes the account it is called upon.

It returns the count of deleted accounts, which can be either 0 or 1, or an error when something went wrong while deleting the database entry.

func (*Account) Insert

func (account *Account) Insert(client *mongo.Client, ctx context.Context, database string) error

This function inserts the session it is called upon into the database. If anything went wrong during the insertion, returns an error.

func (*Account) Update

func (account *Account) Update(client *mongo.Client, ctx context.Context, database string, changes bson.D) (*mongo.UpdateResult, error)

Updates the account it is called upon with the changes given in the function parameters.

Jump to

Keyboard shortcuts

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