users

package
v1.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2017 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package users represents the user resource

Index

Constants

View Source
const (
	// TableName is the database table for this resource
	TableName = "users"
	// KeyName is the primary key value for this resource
	KeyName = "id"
	// Order defines the default sort order in sql for this resource
	Order = "name asc, id desc"
)
View Source
const (
	Anon   = 0
	Editor = 10
	Reader = 20
	Admin  = 100
)

User roles

Variables

This section is empty.

Functions

func Admins

func Admins() *query.Query

Admins returns a query which finds all admin users

func AllowedParams

func AllowedParams() []string

AllowedParams returns an array of allowed param keys for Update and Create.

func Count

func Count() int64

Count returns a count of users

func Editors

func Editors() *query.Query

Editors returns a query which finds all editor users

func Published

func Published() *query.Query

Published returns a query for all users with status >= published.

func Query

func Query() *query.Query

Query returns a new query for users with a default order.

func Readers

func Readers() *query.Query

Readers returns a query which finds all reader users

func Where

func Where(format string, args ...interface{}) *query.Query

Where returns a new query for users with the format and arguments supplied.

Types

type User

type User struct {
	// resource.Base defines behaviour and fields shared between all resources
	resource.Base

	// status.ResourceStatus defines a status field and associated behaviour
	status.ResourceStatus

	// Authorisation
	Role int64

	// Authentication
	PasswordHash       string
	PasswordResetToken string
	PasswordResetAt    time.Time

	// User details
	Email   string
	Name    string
	Title   string
	Summary string
	Text    string
	ImageID int64
}

User handles saving and retreiving users from the database

func Find

func Find(id int64) (*User, error)

Find fetches a single user record from the database by id.

func FindAll

func FindAll(q *query.Query) ([]*User, error)

FindAll fetches all user records matching this query from the database.

func FindFirst

func FindFirst(format string, args ...interface{}) (*User, error)

FindFirst fetches a single user record from the database using a where query with the format and args provided.

func MockAdmin

func MockAdmin() *User

MockAdmin returns a mock user for testing with Role Admin.

func MockAnon

func MockAnon() *User

MockAnon returns a mock user for testing with Role Anon.

func New

func New() *User

New creates and initialises a new user instance.

func NewWithColumns

func NewWithColumns(cols map[string]interface{}) *User

NewWithColumns creates a new user instance and fills it with data from the database cols provided.

func (*User) Admin

func (u *User) Admin() bool

Admin returns true if this user is an Admin.

func (*User) Anon

func (u *User) Anon() bool

Anon returns true if this user is not a logged in user.

func (*User) Reader

func (u *User) Reader() bool

Reader returns true if this user is an Reader.

func (*User) RoleDisplay

func (u *User) RoleDisplay() string

RoleDisplay returns the string representation of the Role status

func (*User) RoleID

func (u *User) RoleID() int64

RoleID returns the user role for auth.

func (*User) RoleOptions

func (u *User) RoleOptions() []helpers.Option

RoleOptions returns an array of Role values for this model (embedders may override this and roledisplay to extend)

func (*User) SelectName

func (u *User) SelectName() string

SelectName returns a string representation of the user for select options

func (*User) UserID

func (u *User) UserID() int64

UserID returns the user id for auth.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL