users

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 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 acceptable params in update

func Editors

func Editors() *query.Query

Editors returns a query which finds all editor users

func Published added in v1.0.1

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

	Email   string
	Name    string
	Points  int64
	Role    int64
	Summary string
	Text    string
	Title   string

	PasswordHash    string
	PasswordResetAt time.Time
}

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 added in v1.0.1

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 added in v1.0.1

func MockAdmin() *User

MockAdmin returns a mock user for testing with Role Admin.

func MockAnon added in v1.0.1

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) CanComment

func (u *User) CanComment() bool

CanComment returns true if this user can comment.

func (*User) CanDownvote

func (u *User) CanDownvote() bool

CanDownvote returns true if this user can downvote.

func (*User) CanFlag

func (u *User) CanFlag() bool

CanFlag returns true if this user can flag.

func (*User) CanStyle added in v1.0.1

func (u *User) CanStyle() bool

CanStyle returns true if this user can style text in comments/stories.

func (*User) CanSubmit

func (u *User) CanSubmit() bool

CanSubmit returns true if this user can submit.

func (*User) CanUpvote

func (u *User) CanUpvote() bool

CanUpvote returns true if this user can upvote.

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 added in v1.0.1

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) UserID added in v1.0.1

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