Documentation ¶
Index ¶
- func Delete(client *mongo.Client, ctx context.Context, account *Account, database string) (int64, error)
- func DeleteByEmail(client *mongo.Client, ctx context.Context, database string, email string) (int64, error)
- func Insert(client *mongo.Client, ctx context.Context, database string, account *Account) error
- func Update(account *Account, client *mongo.Client, ctx context.Context, database string, ...) (*mongo.UpdateResult, error)
- type Account
- func Find(db *mongo.Client, ctx context.Context, database string, condition primitive.E) (*Account, error)
- func FindByEmail(db *mongo.Client, ctx context.Context, database string, email string) (*Account, error)
- func FindByID(db *mongo.Client, ctx context.Context, database string, ID primitive.ObjectID) (*Account, error)
- func (account *Account) Delete(client *mongo.Client, ctx context.Context, database string) (int64, error)
- func (account *Account) Insert(client *mongo.Client, ctx context.Context, database string) error
- func (account *Account) Update(client *mongo.Client, ctx context.Context, database string, changes bson.D) (*mongo.UpdateResult, error)
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.
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.