user

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Admin

type Admin struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	Email    string `json:"email"`
	Phone    string `json:"phone,omitempty"`
	Role     string `json:"role"`     // display name, e.g. "Club Secretary"
	RoleCode string `json:"roleCode"` // input code, e.g. "club_secretary"
	TeamID   int    `json:"teamId,omitempty"`
	ImageURL string `json:"imageUrl,omitempty"`
}

Admin is a user as the user-management API returns it. It never contains password material.

type CreateInput

type CreateInput struct {
	Name   string
	Email  string
	Phone  string
	Role   string
	TeamID int
}

CreateInput is a new user. Role is a role code (e.g. "manager"); TeamID is kept only for managers.

type Created

type Created struct {
	User      Admin  `json:"user"`
	EmailSent bool   `json:"emailSent"`
	SetupURL  string `json:"setupUrl,omitempty"`
}

Created is the result of creating a user. SetupURL, the user's link to set their password, is set only when the signup email could not be sent, so the admin can pass it on.

type Handlers

type Handlers struct {
	// contains filtered or unexported fields
}

Handlers serves /users. Every route needs Club Secretary or higher.

func NewHandlers

func NewHandlers(svc *Service) *Handlers

func (*Handlers) Register

func (h *Handlers) Register(g *echo.Group, guards web.Guards)

Register mounts the user-management routes on the /api/v1 group.

type HashParams

type HashParams struct {
	WorkFactor  int
	BlockSize   int
	Parallelism int
	KeyLength   int
}

HashParams are the scrypt parameters for new users' initial passwords.

type ResetResult

type ResetResult struct {
	EmailSent bool   `json:"emailSent"`
	ResetURL  string `json:"resetUrl,omitempty"`
}

ResetResult is the result of an admin-triggered password reset. ResetURL is set only when the email could not be sent.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is user administration.

func NewService

func NewService(store store, teams TeamGetter, files *upload.Files, mailer emails.Sender, tokens TokenSetter,
	hash HashParams, domain string) *Service

func (*Service) Create

func (s *Service) Create(ctx context.Context, in CreateInput, image *upload.File) (Created, error)

Create adds a user and emails them a link to set their password, valid for as long as a reset link. If the email can't be sent the link is returned so the admin can pass it on. The user's initial password is random and never shown to anyone.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id int) (Admin, error)

Delete removes the user and their photo, returning what was deleted.

func (*Service) Get

func (s *Service) Get(ctx context.Context, id int) (Admin, error)

func (*Service) List

func (s *Service) List(ctx context.Context) ([]Admin, error)

func (*Service) ResetPassword

func (s *Service) ResetPassword(ctx context.Context, id int) (ResetResult, error)

ResetPassword forces a reset on next login, signs the user out everywhere and emails a 48-hour reset link. If the email can't be sent, the link is returned for the admin to pass on.

func (*Service) Update

func (s *Service) Update(ctx context.Context, id int, in UpdateInput, image *upload.File) (Admin, error)

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store stores the dependencies

func NewUserRepo

func NewUserRepo(db *sqlx.DB) *Store

NewUserRepo stores our dependency

func (*Store) AddUser

func (s *Store) AddUser(ctx context.Context, userParam User) (User, error)

func (*Store) ClearLegacyPasswords

func (s *Store) ClearLegacyPasswords(ctx context.Context) ([]int, error)

ClearLegacyPasswords removes the old site's unsalted SHA-512 password digests, along with any hash and salt on those accounts, flags each account for reset and signs it out everywhere.

After migration 003 drops the column it does nothing. Those users can no longer sign in until they follow a reset link. It returns the IDs it cleared; running it again clears nothing.

func (*Store) DeleteUser

func (s *Store) DeleteUser(ctx context.Context, userParam User) error

func (*Store) DetachTeam

func (s *Store) DetachTeam(ctx context.Context, teamID int) error

DetachTeam removes teamID from every user (managers of that team).

func (*Store) EditUser

func (s *Store) EditUser(ctx context.Context, userParam User) (User, error)

func (*Store) EditUserImage

func (s *Store) EditUserImage(ctx context.Context, userParam User) error

func (*Store) EditUserPassword

func (s *Store) EditUserPassword(ctx context.Context, userParam User, workFactor, blockSize, parallelismFactor, keyLen int) error

func (*Store) EndSessions

func (s *Store) EndSessions(ctx context.Context, id int) error

EndSessions makes every session the user has stopped working, by bumping the version their session cookies must match.

func (*Store) GetUser

func (s *Store) GetUser(ctx context.Context, userParam User) (User, error)

func (*Store) GetUserByUUID

func (s *Store) GetUserByUUID(ctx context.Context, id string) (User, error)

GetUserByUUID finds a user by their public ID.

func (*Store) GetUsers

func (s *Store) GetUsers(ctx context.Context) ([]User, error)

func (*Store) GetUsersContact

func (s *Store) GetUsersContact(ctx context.Context) ([]User, error)

func (*Store) GetUsersManagersTeam

func (s *Store) GetUsersManagersTeam(ctx context.Context, teamParam team.Team) ([]User, error)

func (*Store) VerifyUser

func (s *Store) VerifyUser(ctx context.Context, userParam User, iter, workFactor, blockSize, parallelismFactor, keyLen int) (User, bool, error)

type TeamGetter

type TeamGetter interface {
	GetTeam(ctx context.Context, teamParam team.Team) (team.Team, error)
}

TeamGetter checks manager teams (satisfied by *team.Store).

type TokenSetter

type TokenSetter interface {
	Set(ctx context.Context, token string, userID int, ttl time.Duration) error
}

TokenSetter issues password reset tokens (satisfied by *auth.Tokens).

type UpdateInput

type UpdateInput struct {
	Name        *string
	Email       *string
	Phone       *string
	Role        *string
	TeamID      *int
	RemoveImage bool
}

UpdateInput changes a user; nil fields are left unchanged.

type User

type User struct {
	ID int `db:"id" json:"id"`
	// UUID is the public ID used in file links; see migrations/001.
	UUID          string      `db:"uuid" json:"-"`
	Name          string      `db:"name" json:"name"`
	Email         string      `db:"email" json:"email"`
	Phone         null.String `db:"phone" json:"phone"`
	TeamID        int         `db:"team_id" json:"team_id"`
	TempRole      string      `db:"role" json:"role"`
	Role          role.Role
	FileName      null.String `db:"file_name" json:"file_name"`
	ResetPassword bool        `db:"reset_password" json:"reset_password"`
	// SessionVersion is copied into the session cookie at sign-in; a
	// cookie with an older version is no longer accepted. See
	// EndSessions and migrations/002.
	SessionVersion int `db:"session_version" json:"-"`
	// Password is a plaintext password given to VerifyUser or
	// EditUserPassword. It is never read from or written to the database.
	Password      null.String `db:"-" json:"password"`
	Hash          null.String `db:"hash" json:"hash"`
	Salt          null.String `db:"salt" json:"salt"`
	Authenticated bool
}

User represents relevant user fields

Jump to

Keyboard shortcuts

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