user

package
v0.0.0-...-4d10510 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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 ChangePassFirstLogin(ctx context.Context, client *ent.Client, id uuid.UUID, password string) error

func CreateFirst

func CreateFirst(ctx context.Context, client *ent.Client, username, email, password string) error

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

func DeleteUserByID(ctx context.Context, client *ent.Client, strID string) error

DeleteUserByID returns nil on successful deletion, err otherwise.

func EmailExists

func EmailExists(ctx context.Context, client *ent.Client, email string) (bool, error)

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

func Exists(ctx context.Context, client *ent.Client, username, email string) (bool, error)

Exists determines whether the username OR email in question was previously used to register a user.

func ListAll

func ListAll(ctx context.Context, client *ent.Client) ([]*ent.User, error)

func ListAllAdmins

func ListAllAdmins(ctx context.Context, client *ent.Client) ([]*ent.User, error)

func ListAllRegular

func ListAllRegular(ctx context.Context, client *ent.Client) ([]*ent.User, error)

func NoUsers

func NoUsers(ctx context.Context, client *ent.Client) (bool, error)

NoUsers checks whether there are any users at all in the db.

func QueryUser

func QueryUser(ctx context.Context, client *ent.Client, username string) (*ent.User, error)

func QueryUserByID

func QueryUserByID(ctx context.Context, client *ent.Client, strID string) (*ent.User, error)

QueryUserByID returns user for the provided ID, and nil if err == nil, nil and err otherwise.

func QueryUserByUUID

func QueryUserByUUID(ctx context.Context, client *ent.Client, id uuid.UUID) (*ent.User, error)

QueryUserByUUID returns user for the provided ID, and nil if err == nil, nil and err otherwise.

func UpdateUserByAdmin

func UpdateUserByAdmin(ctx context.Context, client *ent.Client, id uuid.UUID, email, username, password string, isAdmin bool, isActive *bool) error

func UpdateUserLastLogin

func UpdateUserLastLogin(ctx context.Context, client *ent.Client, id uuid.UUID, isAdmin bool) error

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

func UsernameExists(ctx context.Context, client *ent.Client, username string) (bool, error)

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}.

func UsrFinishedSetup

func UsrFinishedSetup(ctx context.Context, client *ent.Client, id uuid.UUID) (bool, error)

Types

type CtxKey

type CtxKey struct{}

CtxKey serves as a key to context values for this package.

type User

type User struct {
	ID         uuid.UUID
	Username   string
	Email      string
	IsActive   bool
	IsAdmin    bool
	CreatedAt  time.Time
	UpdatedAt  time.Time
	IsLoggedIn bool
	LastLogin  time.Time
}

Jump to

Keyboard shortcuts

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