Documentation ¶
Index ¶
- Constants
- Variables
- func AvailableGroups() map[string]string
- func ValidGroups() []string
- type CreateForm
- type GroupChoice
- type Manager
- type PasswordForm
- type ProfileForm
- type UpdateForm
- type User
- func (u *User) CheckPassword(password string) bool
- func (u *User) Delete() error
- func (u *User) HasPermission(obj, act string) bool
- func (u *User) HashPassword(password string) (string, error)
- func (u *User) IsAnonymous() bool
- func (u *User) Roles() []string
- func (u *User) Save() error
- func (u *User) SetPassword(password string) error
- func (u *User) SetSeed() int
- func (u *User) Update(v interface{}) error
- type UserSettings
Constants ¶
const (
// TableName is the user table name in database.
TableName = "user"
)
Variables ¶
var ( // Users is the user manager. Users = Manager{} // ErrNotFound is returned when a user record was not found. ErrNotFound = errors.New("not found") )
Functions ¶
func AvailableGroups ¶
AvailableGroups returns the available group names. This is a mapping of ID => name.
Types ¶
type CreateForm ¶
type CreateForm struct { Username string `json:"username" conform:"trim"` Email string `json:"email" conform:"trim"` Group *GroupChoice `json:"group" conform:"trim"` Password string `json:"password"` }
CreateForm describes a user creation form
func (*CreateForm) Validate ¶
func (uf *CreateForm) Validate(f *form.Form)
Validate validates the form.
type GroupChoice ¶
type GroupChoice string
func (*GroupChoice) Options ¶
func (c *GroupChoice) Options() [][2]string
func (*GroupChoice) String ¶
func (c *GroupChoice) String() string
type Manager ¶
type Manager struct{}
Manager is a query helper for user entries.
func (*Manager) Create ¶
Create insert a new user in the database. The password must be present. It will be hashed and updated before insertion.
type PasswordForm ¶
PasswordForm is a form to update a user's password.
func (*PasswordForm) SetUser ¶
func (pf *PasswordForm) SetUser(f *form.Form, u *User)
SetUser adds a user to the wrapping form's context.
func (*PasswordForm) Validate ¶
func (pf *PasswordForm) Validate(f *form.Form)
Validate validates the form.
type ProfileForm ¶
type ProfileForm struct { Username *string `json:"username" conform:"trim"` Email *string `json:"email" conform:"trim"` }
ProfileForm is the form used by the profile update routes.
func (*ProfileForm) Validate ¶
func (sf *ProfileForm) Validate(f *form.Form)
Validate validates the form
type UpdateForm ¶
type UpdateForm struct { Username *string `json:"username" conform:"trim"` Email *string `json:"email" conform:"trim"` Group *GroupChoice `json:"group" conform:"trim"` Password *string `json:"password"` Settings *UserSettings `json:"settings"` }
UpdateForm describes a user update form.
func (*UpdateForm) SetUser ¶
func (uf *UpdateForm) SetUser(f *form.Form, u *User)
SetUser adds a user to the wrapping form's context.
func (*UpdateForm) Validate ¶
func (uf *UpdateForm) Validate(f *form.Form)
Validate validates the form
type User ¶
type User struct { ID int `db:"id" goqu:"skipinsert,skipupdate"` Created time.Time `db:"created" goqu:"skipupdate"` Updated time.Time `db:"updated"` Username string `db:"username"` Email string `db:"email"` Password string `db:"password"` Group string `db:"group"` Settings *UserSettings `db:"settings"` Seed int `db:"seed"` }
User is a user record in database
func (*User) CheckPassword ¶
CheckPassword checks if the given password matches the current user password.
func (*User) HasPermission ¶
HasPermission returns true if the user can perform "act" action on "obj" object.
func (*User) HashPassword ¶
HashPassword returns a new hashed password
func (*User) IsAnonymous ¶
IsAnonymous returns true when the instance is not set to any existing user (when ID is 0)
func (*User) SetPassword ¶
SetPassword set a new user password
type UserSettings ¶
type UserSettings struct {
DebugInfo bool `json:"debug_info"`
}
func (*UserSettings) Scan ¶
func (s *UserSettings) Scan(value interface{}) error