Documentation
¶
Overview ¶
Package users implements user management and verification for a web application.
Index ¶
- Constants
- Variables
- type App
- type User
- type UserFormData
- type UserStore
- type Users
- func (u *Users) GetFormEdit(w http.ResponseWriter, r *http.Request)
- func (u *Users) GetFormLogin(w http.ResponseWriter, r *http.Request)
- func (u *Users) GetFormSignup(w http.ResponseWriter, r *http.Request)
- func (u *Users) NewUsersForm(data url.Values, token string) *UsersForm
- func (u *Users) PostFormEdit(w http.ResponseWriter, r *http.Request)
- func (u *Users) PostFormLogin(w http.ResponseWriter, r *http.Request)
- func (u *Users) PostFormSignup(w http.ResponseWriter, r *http.Request)
- func (u *Users) UserDisplayName(userId int64) string
- type UsersForm
Constants ¶
const ( // user status values UserRemoved = -10 // deletion in progress but cached access allowed UserSuspended = 0 // blocked from access or registration UserKnown = 1 // allowed to register and set display name and password UserActive = 2 // registered MaxName = 60 // maximum name characters )
Variables ¶
var ErrInvalidCredentials = errors.New("webparts/users: invalid credentials")
var WebFiles embed.FS
WebFiles are the package's web resources (templates and static files)
Functions ¶
This section is empty.
Types ¶
type App ¶
type App interface {
// Authenticated adds a logged-in user's ID to the session
Authenticated(r *http.Request, id int64)
// Flash adds a confirmation message to the next page, via the session
Flash(r *http.Request, msg string)
// GetRedirect returns the next page after log-in, probably from a session key
GetRedirect(r *http.Request) string
// Log optionally records an error
Log(error)
// LogThreat optionally records a rejected request to sign-up or log-in
LogThreat(msg string, r *http.Request)
// OnAddUser is called to add any additional application data for a user.
// It is called after the store request has been made.
OnAddUser(tx etx.TxId, user *User)
// OnRemoveUser is called to delete any application data for a user.
// It is called before the store entry is deleted.
OnRemoveUser(tx etx.TxId, user *User)
// OnUpdateUser is called to do any application processing when a user is updated.
// It is called after the store request has been made.
OnUpdateUser(tx etx.TxId, from *User, to *User)
// Render writes an HTTP response using the specified template and template field Users
Render(w http.ResponseWriter, r *http.Request, template string, usersData interface{})
// Rollback requests that the transaction started by Serialise be cancelled.
Rollback()
// Serialise optionally requests application-level serialisation.
// If updates=true, the store is to be updated and a transaction might be started (especially if a user is to be added or deleted).
// The returned function will be called at the end of the operation.
Serialise(updates bool) func()
// Token returns a token to be added to the form as the hidden field csrf_token.
Token(r *http.Request) string
}
App is the interface to functions provided by the parent application.
type User ¶
type User struct {
Id int64 // database ID
Parent int64 // parent ID, if multiple sets of user are supported
Username string // unique name for user, typically an email address
Name string // display name for user
Role int // user's role (normal, administrator, etc.)
Status int // user's status
Password []byte // hashed password
Created time.Time // time of first registration
}
User struct holds the stored data for a user.
func (*User) SetPassword ¶
setPassword stores a password hash
type UserFormData ¶
type UserStore ¶
type UserStore interface {
ByName() []*User // all users, in name order
DeleteId(id int64) error // delete user
Get(id int64) (*User, error) // get user by database ID
GetNamed(username string) (*User, error) // get user for username (expected to be unique)
IsNoRecord(error) bool // true if error is "record not found"
Name(id int64) string // get display name for user by database ID
Rollback() // (redundant)
Update(s *User) error // add or update user
}
UserStore is the interface for storage and update of user information. To be implemented by the parent application. Id and Username are unique keys for a user.
type Users ¶
type Users struct {
App App
Roles []string
RoleDisabled []bool
Store UserStore
TM *etx.TM
// contains filtered or unexported fields
}
Users holds the dependencies of this package on the parent application. It has no state of its own.
func (*Users) GetFormEdit ¶
func (u *Users) GetFormEdit(w http.ResponseWriter, r *http.Request)
GetFormEdit renders the form to manage users.
func (*Users) GetFormLogin ¶
func (u *Users) GetFormLogin(w http.ResponseWriter, r *http.Request)
GetFormLogin renders the form for a user to log in.
func (*Users) GetFormSignup ¶
func (u *Users) GetFormSignup(w http.ResponseWriter, r *http.Request)
GetFormSignup renders the form for a pre-approved user to sign-up.
func (*Users) NewUsersForm ¶
NewUsersForm returns a form to edit users.
func (*Users) PostFormEdit ¶
func (u *Users) PostFormEdit(w http.ResponseWriter, r *http.Request)
PostFormUsers processes the form with changes to users.
func (*Users) PostFormLogin ¶
func (u *Users) PostFormLogin(w http.ResponseWriter, r *http.Request)
PostFormLogin processes the log-in form.
func (*Users) PostFormSignup ¶
func (u *Users) PostFormSignup(w http.ResponseWriter, r *http.Request)
PostFormSignup processes the sign-up form.
func (*Users) UserDisplayName ¶
UserDisplayName returns the display name for a user.
type UsersForm ¶
type UsersForm struct {
multiforms.Form
RoleOpts []string
Children []*UserFormData
App interface{}
}
func (*UsersForm) AddTemplate ¶
AddTemplate appends the sub-form template for new users.