Documentation ¶
Index ¶
- Constants
- Variables
- func ValidatePasswordPlaintext(v *validator.Validator, password string)
- func ValidateTokenPlaintext(v *validator.Validator, tokenPlaintext string)
- func ValidateUser(v *validator.Validator, user *User)
- type Models
- type PermissionModel
- type Permissions
- type Token
- type TokenModel
- type User
- type UserModel
Constants ¶
const ( ScopeActivation = "activation" ScopeAuthentication = "authentication" )
Variables ¶
var ( ErrEditConflict = errors.New("edit conflict") ErrRecordNotFound = errors.New("record not found") )
var ( AnonymousUser = &User{} ErrDuplicateEmail = errors.New("duplicate email") )
Functions ¶
func ValidatePasswordPlaintext ¶
ValidatePasswordPlaintext ensures that a provided password satisfies the desired password requirements. Any violations will be added to the given validator.Validator under the "password" key.
func ValidateTokenPlaintext ¶
func ValidateUser ¶
ValidateUser checks if a user is considered valid and stores any errors in the provided validator.Validator struct.
Types ¶
type Models ¶
type Models struct { Permissions PermissionModel Tokens TokenModel Users UserModel }
type PermissionModel ¶
func (PermissionModel) AddForUser ¶
func (m PermissionModel) AddForUser(userID int64, codes ...string) error
func (PermissionModel) GetAllForUser ¶
func (m PermissionModel) GetAllForUser(userID int64) (Permissions, error)
type Permissions ¶
type Permissions []string
func (Permissions) Include ¶
func (p Permissions) Include(code string) bool
type TokenModel ¶
func (TokenModel) DeleteAllForUser ¶
func (m TokenModel) DeleteAllForUser(scope string, userID int64) error
func (TokenModel) Insert ¶
func (m TokenModel) Insert(token *Token) error
type User ¶
type User struct { ID int64 `json:"-"` Version int `json:"-"` CreatedAt time.Time `json:"-"` UpdatedAt time.Time `json:"-"` UserID string `json:"user_id"` Email string `json:"email"` Password password `json:"-"` Name string `json:"name"` FriendlyName *string `json:"friendly_name,omitempty"` BirthDate *jsonz.DateOnly `json:"birth_date,omitempty"` Gender *string `json:"gender,omitempty"` CountryCode *string `json:"country_code,omitempty"` TimeZone *string `json:"time_zone,omitempty"` Activated bool `json:"-"` Suspended bool `json:"-"` }
User represents a human user of a system.
func (*User) IsAnonymous ¶
IsAnonymous compares the User receiver to the AnonymousUser struct.
type UserModel ¶
func (UserModel) DeleteByEmail ¶
DeleteByEmail soft deletes the user with the given email address. If no matching record exists, ErrRecordNotFound is returned.
func (UserModel) GetByIdentifier ¶
GetByIdentifier queries the database for a user based on the given field for the given value. If no matching record exists, ErrRecordNotFound is returned. Valid field names are "email" and "user_id".
func (UserModel) GetForToken ¶
GetForToken retrieves a User from the database for a given Token. If the token is expired, or the user has been suspended or deleted, then an ErrRecordNotFound error is returned.