Documentation ¶
Index ¶
- Constants
- Variables
- type Permission
- type Role
- type User
- func (u *User) Create(ctx context.Context) (err error)
- func (u *User) Permissions(ctx context.Context, reset bool) (_ []string, err error)
- func (u *User) Role(ctx context.Context, reset bool) (_ *Role, err error)
- func (u *User) Update(ctx context.Context) (err error)
- func (u *User) UpdateLastSeen(ctx context.Context) (err error)
- func (u *User) UpdatePassword(ctx context.Context) (err error)
Constants ¶
const DefaultRoleID int64 = 2
Variables ¶
var ( ErrNoUserID = errors.New("this operation requires a user id") ErrNotDerivedKey = errors.New("passwords must be stored as a derived key") )
Standard errors for database operations and checking.
Functions ¶
This section is empty.
Types ¶
type Permission ¶
type Permission struct { ID int64 Title string Description sql.NullString Created time.Time Modified time.Time }
Database model for a permission object.
type Role ¶
type Role struct { ID int64 Title string Description sql.NullString Created time.Time Modified time.Time // contains filtered or unexported fields }
Database model for a role object.
func (*Role) Permissions ¶
type User ¶
type User struct { ID int64 FullName sql.NullString Email string Username string Password string RoleID int64 LastSeen sql.NullTime PasswordChanged sql.NullTime Created time.Time Modified time.Time // contains filtered or unexported fields }
Database model for a user object.
func UserFromEmail ¶
UserFromEmail gets a user and populates the role and permissions if claims is true. This function returns the password for login purposes unless claims is false.
func UserFromID ¶
UserFromID gets a user without password or claims and should be used for non-login purposes.
func UserFromUsername ¶
UserFromUsername gets a user and populates the role and permissions if claims is true. This function returns the password for login purposes unless claims is false.
func (*User) Create ¶
Create a user from the model. The ID, Created, and Modified timestamps will be populated on the model after creation. Note that the LastSeen timestamp is ignored and the PasswordChange timestamp is set to now (no matter what it was set to before). TODO: handle specific database errors like uniqueness constraints or other schema errors.
func (*User) Permissions ¶
Permissions returns the claims associated with the user. If the permissions are not cached on the struct, then a database query to the user_permissions view is executed. Use the reset bool to force a database query even if the permissions are cached.
func (*User) Role ¶
Role returns the role associated with the user. If the role is not cached on the struct then a database query is performed and an error may be returned. Use the reset bool to force a database query even if the role is cached on the struct.
func (*User) Update ¶
Update a user's full name, email, username, role id, and/or last seen timestamp. The user must have an ID field populated or ErrNoUserID will be returned.
func (*User) UpdateLastSeen ¶
Update a user's last seen timestamp to now. The user must have an ID field populated or ErrNotDerivedKey will be returned.