Documentation ¶
Overview ¶
Package users contains the models and functions to manage users.
Index ¶
- Constants
- Variables
- func NewRolesField(tr forms.Translator, user *User) forms.Field
- type Manager
- type ReaderSettings
- type User
- func (u *User) CheckPassword(password string) bool
- func (u *User) Delete() error
- func (u *User) GetLastModified() []time.Time
- func (u *User) GetSumStrings() []string
- func (u *User) HasPermission(obj, act string) bool
- func (u *User) HashPassword(password string) (string, error)
- func (u *User) IsAnonymous() bool
- func (u *User) Permissions() []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 UserForm
- 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") )
var IsValidPassword = forms.StringValidator(func(v string) bool { if strings.TrimSpace(v) == "" { return false } return len(v) >= 8 }, errors.New("password must be at least 8 character long"))
IsValidPassword is the password validation rule.
var IsValidUsername = forms.StringValidator(func(v string) bool { return rxUsername.MatchString(v) }, errors.New(`must contain English letters, digits, "_" and "-" only`))
IsValidUsername is the username validation rule.
Functions ¶
func NewRolesField ¶
func NewRolesField(tr forms.Translator, user *User) forms.Field
NewRolesField returns a forms.Field with user's role choices.
Types ¶
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 ReaderSettings ¶
type ReaderSettings struct { Font string `json:"font"` FontSize int `json:"font_size"` LineHeight int `json:"line_height"` }
ReaderSettings contains the reader settings.
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) GetLastModified ¶
GetLastModified returns the last modified times.
func (*User) GetSumStrings ¶
GetSumStrings returns the string used to generate the etag of the user.
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) Permissions ¶
Permissions returns all the user's implicit permissions.
func (*User) SetPassword ¶
SetPassword set a new user password.
type UserForm ¶
UserForm is the form used for user creation and update.
func NewUserForm ¶
func NewUserForm(tr forms.Translator) (f *UserForm)
NewUserForm returns a UserForm instance.
func (*UserForm) Bind ¶
func (f *UserForm) Bind()
Bind prepares the form before data binding. It changes some validators in case of user update.
func (*UserForm) CreateUser ¶
CreateUser performs the user creation.
func (*UserForm) UpdateUser ¶
UpdateUser performs a user update and returns a mapping of updated fields.
type UserSettings ¶
type UserSettings struct { DebugInfo bool `json:"debug_info"` Lang string `json:"lang"` ReaderSettings ReaderSettings `json:"reader_settings"` }
UserSettings contains some user settings.
func (*UserSettings) Scan ¶
func (s *UserSettings) Scan(value interface{}) error
Scan loads a UserSettings instance from a column.