Documentation ¶
Index ¶
- Constants
- Variables
- func ChangePassFirstLogin(ctx context.Context, client *ent.Client, id uuid.UUID, password string) error
- func CreateFirst(ctx context.Context, client *ent.Client, username, email, password string) error
- func CreateUser(ctx context.Context, client *ent.Client, email, username, password string, ...) (*ent.User, error)
- func DeleteUserByID(ctx context.Context, client *ent.Client, strID string) error
- func EmailExists(ctx context.Context, client *ent.Client, email string) (bool, error)
- func Exists(ctx context.Context, client *ent.Client, username, email string) (bool, error)
- func ListAll(ctx context.Context, client *ent.Client) ([]*ent.User, error)
- func ListAllAdmins(ctx context.Context, client *ent.Client) ([]*ent.User, error)
- func ListAllRegular(ctx context.Context, client *ent.Client) ([]*ent.User, error)
- func NoUsers(ctx context.Context, client *ent.Client) (bool, error)
- func QueryUser(ctx context.Context, client *ent.Client, username string) (*ent.User, error)
- func QueryUserByID(ctx context.Context, client *ent.Client, strID string) (*ent.User, error)
- func QueryUserByUUID(ctx context.Context, client *ent.Client, id uuid.UUID) (*ent.User, error)
- func UpdateUserByAdmin(ctx context.Context, client *ent.Client, id uuid.UUID, ...) error
- func UpdateUserLastLogin(ctx context.Context, client *ent.Client, id uuid.UUID, isAdmin bool) error
- func UsernameExists(ctx context.Context, client *ent.Client, username string) (bool, error)
- func UsrFinishedSetup(ctx context.Context, client *ent.Client, id uuid.UUID) (bool, error)
- type CtxKey
- type User
Constants ¶
const ( // AdminUname is the username of the initial administrator user. AdminUname = "admin" // AdminEmail is the email of the initial administrator user. AdminEmail = "admin@adminmail.admindomain" )
Variables ¶
var ( ErrUsersAlreadyPresent = errors.New("don't call CreateFirst when there already are another users") ErrUserNotFound = errors.New("user not found") ErrFailedToQueryUser = errors.New("failed to query user") ErrBadUUID = errors.New("invalid uuid") ErrPasswordEmpty = errors.New("password was empty") ErrNewPasswordCannotEqual = errors.New("the new password cannot be the same as the old one") ErrUnfinishedSetupLastLoginUpdate = errors.New("not updating last_login for users with unfinished setup") )
Functions ¶
func ChangePassFirstLogin ¶
func CreateFirst ¶
CreateFirst creates the first user and makes them an administrator. To be used during app setup.
func CreateUser ¶
func CreateUser(ctx context.Context, client *ent.Client, email, username, password string, isAdmin ...bool) (*ent.User, error)
CreateUser adds a user entry to the database.
func DeleteUserByID ¶
DeleteUserByID returns nil on successful deletion, err otherwise.
func EmailExists ¶
EmailExists queries the database to check whether the email was already used; returns a bool and an error, which will be nil unless the error is not one of IsNot{Found,Singular}.
func Exists ¶
Exists determines whether the username OR email in question was previously used to register a user.
func ListAllAdmins ¶
func ListAllRegular ¶
func QueryUserByID ¶
QueryUserByID returns user for the provided ID, and nil if err == nil, nil and err otherwise.
func QueryUserByUUID ¶
QueryUserByUUID returns user for the provided ID, and nil if err == nil, nil and err otherwise.
func UpdateUserByAdmin ¶
func UpdateUserLastLogin ¶
UpdateUserLastLogin serves to update the last_login param of the user. This parameter will not get updated for users that never finished setting up, return nil on success and error on err.
func UsernameExists ¶
UsernameExists queries the database to check whether the username is available or taken, returns a bool and an error, which will be nil unless the error is one of IsNot{Found,Singular}.