package user
import "git.dotya.ml/mirre-mt/pcmt/modules/user"
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, isAdmin ...bool) (*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, email, username, password string, isAdmin bool, isActive *bool) 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 ChangePassFirstLogin(ctx context.Context, client *ent.Client, id uuid.UUID, password string) error
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 ListAll ¶
func ListAllAdmins ¶
func ListAllRegular ¶
func NoUsers ¶
NoUsers checks whether there are any users at all in the db.
func QueryUser ¶
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 UpdateUserByAdmin(ctx context.Context, client *ent.Client, id uuid.UUID, email, username, password string, isAdmin bool, isActive *bool) error
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}.
func UsrFinishedSetup ¶
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 }
Source Files ¶
const.go context.go error.go user.go
- Version
- v0.0.0-20230910121657-4d10510f5ba4 (latest)
- Published
- Sep 10, 2023
- Platform
- linux/amd64
- Imports
- 10 packages
- Last checked
- 1 month ago –
Tools for package owners.