Documentation ¶
Overview ¶
Package user provides the database implementation for the User entity.
Index ¶
- Variables
- func Model(uu []*User) func(int) database.Model
- func Select(col string, opts ...query.Option) query.Query
- func WhereHandle(handle string) query.Option
- type DeleteForm
- type EmailForm
- type LoginForm
- type NewPasswordForm
- type PasswordForm
- type PasswordResetForm
- type RegisterForm
- type Store
- func (s *Store) All(opts ...query.Option) ([]*User, error)
- func (s *Store) Auth(handle, password string) (*User, error)
- func (s *Store) Bind(_ ...database.Model)
- func (s *Store) Create(email, username string, password []byte) (*User, string, error)
- func (s *Store) Delete(id int64, password []byte) error
- func (s *Store) Get(opts ...query.Option) (*User, error)
- func (s *Store) Load(key string, vals []interface{}, load database.LoaderFunc) error
- func (*Store) New() *User
- func (s *Store) RequestVerify(id int64) (string, error)
- func (s *Store) ResetPassword(id int64) (string, error)
- func (s *Store) Update(id int64, email string, cleanup bool, password []byte) error
- func (s *Store) UpdatePassword(tok string, password []byte) error
- func (s *Store) Verify(tok string) error
- type User
- func (*User) Bind(_ ...database.Model)
- func (*User) Endpoint(_ ...string) string
- func (u *User) IsZero() bool
- func (u *User) JSON(_ string) map[string]interface{}
- func (u *User) Primary() (string, int64)
- func (u *User) SetPermission(perm string)
- func (u *User) SetPrimary(id int64)
- func (u *User) Values() map[string]interface{}
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Model ¶
Model is called along with database.ModelSlice to convert the given slice of User models to a slice of database.Model interfaces.
func Select ¶
Select returns a query that selects the given column from the users table, with each given query.Option applied to the returned query.
func WhereHandle ¶
WhereHandle returns a query.Option that when applied to a query will add two WHERE clauses that will check the given handle against the email column or the username column.
Types ¶
type DeleteForm ¶
type DeleteForm struct {
Password string `schema:"delete_password"`
}
func (DeleteForm) Fields ¶
func (f DeleteForm) Fields() map[string]string
func (DeleteForm) Validate ¶
func (f DeleteForm) Validate() error
type EmailForm ¶
type EmailForm struct { User *User `schema:"-"` Users *Store `schema:"-"` Email string `schema:"email"` VerifyPassword string `schema:"verify_password"` }
type LoginForm ¶
type LoginForm struct { Handle string `schema:"handle"` Password string `schema:"password"` RedirectURI string `schema:"redirect_uri"` }
type NewPasswordForm ¶
type NewPasswordForm struct { Token string `schema:"token"` Password string `schema:"password"` VerifyPassword string `schema:"verify_password"` }
func (NewPasswordForm) Fields ¶
func (f NewPasswordForm) Fields() map[string]string
func (NewPasswordForm) Validate ¶
func (f NewPasswordForm) Validate() error
type PasswordForm ¶
type PasswordForm struct { User *User `schema:"-"` Users *Store `schema:"-"` OldPassword string `schema:"old_password"` NewPassword string `schema:"new_password"` VerifyPassword string `schema:"verify_password"` }
func (PasswordForm) Fields ¶
func (PasswordForm) Fields() map[string]string
Fields will return an empty map of strings.
func (PasswordForm) Validate ¶
func (f PasswordForm) Validate() error
Validate the current PasswordForm. This checks for the presence of the old, new, and current password fields, as well as if the current password is valid based on what is in the database.
type PasswordResetForm ¶
type PasswordResetForm struct {
Email string `schema:"email"`
}
func (PasswordResetForm) Fields ¶
func (f PasswordResetForm) Fields() map[string]string
func (PasswordResetForm) Validate ¶
func (f PasswordResetForm) Validate() error
type RegisterForm ¶
type RegisterForm struct { Users *Store Email string `schema:"email"` Username string `schema:"username"` Password string `schema:"password"` VerifyPassword string `schema:"verify_password"` }
func (RegisterForm) Fields ¶
func (f RegisterForm) Fields() map[string]string
Fields returns a map of the Email and Username fields.
func (RegisterForm) Validate ¶
func (f RegisterForm) Validate() error
Validate checks to see if the Email field is present and valid. An email is considered valid if it is less than 254 characters in length, and contains an @ character. The Username field is checked for presence, uniqueness, and validitity. A username must be between 3 and 64 characters, and only contain letters, numbers, dashes, and dots. The Password field is checked for presence, and length. It should be between 6 and 60 characters.
type Store ¶
Store is the type for creating and modifying User models in the database.
func NewStore ¶
NewStore returns a new Store for querying the users table. Each database passed to this function will be bound to the returned Store.
func (*Store) Auth ¶
Auth looks up the user by the given handle, and checks that the given password matches the hash in the database.
func (*Store) Create ¶
Create creates a new user with the given email, username and password. The given password is hashed via bcrypt using the default cost.
func (*Store) Delete ¶
Delete the user with the given id. This will set the deleted_at field in the table to the time at which this method was called.
func (*Store) Load ¶
func (s *Store) Load(key string, vals []interface{}, load database.LoaderFunc) error
Load loads in a slice of User models where the given key is in the list of given vals. Each database is loaded individually via a call to the given load callback.
type User ¶
type User struct { ID int64 `db:"id"` Email string `db:"email"` Username string `db:"username"` Password []byte `db:"password"` Verified bool `db:"verified"` Cleanup bool `db:"cleanup"` CreatedAt time.Time `db:"created_at"` UpdatedAt time.Time `db:"updated_at"` DeletedAt sql.NullTime `db:"deleted_at"` Permissions map[string]struct{} `db:"-"` }
User represents a user account in the database. This will either be created through registration, or sign-on via an OAuth provider.
func FromContext ¶
FromContext returns the *User database from the given context value, if any.
func (*User) Endpoint ¶
Endpoint implements the database.Model interface. This returns an empty string.
func (*User) JSON ¶
JSON implements the database.Model interface. This will return a map with the values of the current user under each key. This will not include the password field.
func (*User) SetPermission ¶
SetPermission set's the given permission in the underlying Permissions map of the current User. If the map is nil then it will be initialized.
func (*User) SetPrimary ¶
SetPrimary implements the database.Model interface.