Documentation
¶
Index ¶
- type Admin
- type CreateInput
- type Created
- type Handlers
- type HashParams
- type ResetResult
- type Service
- func (s *Service) Create(ctx context.Context, in CreateInput, image *upload.File) (Created, error)
- func (s *Service) Delete(ctx context.Context, id int) (Admin, error)
- func (s *Service) Get(ctx context.Context, id int) (Admin, error)
- func (s *Service) List(ctx context.Context) ([]Admin, error)
- func (s *Service) ResetPassword(ctx context.Context, id int) (ResetResult, error)
- func (s *Service) Update(ctx context.Context, id int, in UpdateInput, image *upload.File) (Admin, error)
- type Store
- func (s *Store) AddUser(ctx context.Context, userParam User) (User, error)
- func (s *Store) ClearLegacyPasswords(ctx context.Context) ([]int, error)
- func (s *Store) DeleteUser(ctx context.Context, userParam User) error
- func (s *Store) DetachTeam(ctx context.Context, teamID int) error
- func (s *Store) EditUser(ctx context.Context, userParam User) (User, error)
- func (s *Store) EditUserImage(ctx context.Context, userParam User) error
- func (s *Store) EditUserPassword(ctx context.Context, userParam User, ...) error
- func (s *Store) EndSessions(ctx context.Context, id int) error
- func (s *Store) GetUser(ctx context.Context, userParam User) (User, error)
- func (s *Store) GetUserByUUID(ctx context.Context, id string) (User, error)
- func (s *Store) GetUsers(ctx context.Context) ([]User, error)
- func (s *Store) GetUsersContact(ctx context.Context) ([]User, error)
- func (s *Store) GetUsersManagersTeam(ctx context.Context, teamParam team.Team) ([]User, error)
- func (s *Store) VerifyUser(ctx context.Context, userParam User, ...) (User, bool, error)
- type TeamGetter
- type TokenSetter
- type UpdateInput
- type User
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 ¶
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 ¶
type HashParams ¶
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 ¶
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) ResetPassword ¶
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.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store stores the dependencies
func (*Store) ClearLegacyPasswords ¶
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) DetachTeam ¶
DetachTeam removes teamID from every user (managers of that team).
func (*Store) EditUserImage ¶
func (*Store) EditUserPassword ¶
func (*Store) EndSessions ¶
EndSessions makes every session the user has stopped working, by bumping the version their session cookies must match.
func (*Store) GetUserByUUID ¶
GetUserByUUID finds a user by their public ID.
func (*Store) GetUsersContact ¶
func (*Store) GetUsersManagersTeam ¶
type TeamGetter ¶
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