user

package
v0.0.0-...-8ef0ebb Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACTIVE   status = "active"
	PENDING  status = "pending"
	REJECTED status = "rejected"
	REVOKED  status = "revoked"
)

Variables

View Source
var ErrInvalidBanReason = errors.New("invalid ban reason")

ErrInvalidBanReason not present in config

View Source
var ErrInvalidUser = errors.New("invalid user to ban")

ErrInvalidUser user cannot be found

View Source
var UserNotFound = errors.New("User has not been found by given criteria.")

Functions

func CanBeTrusted

func CanBeTrusted(user User) bool

func FindNames

func FindNames(d deps, list ...bson.ObjectId) (common.UsersStringMap, error)

func IsBanned

func IsBanned(d deps, id bson.ObjectId) bool

func Page

func Page(limit int, reverse bool, before *bson.ObjectId, after *bson.ObjectId) common.Query

func ResetNotifications

func ResetNotifications(d deps, id bson.ObjectId) (err error)

Types

type Ban

type Ban struct {
	ID        bson.ObjectId  `bson:"_id,omitempty" json:"id,omitempty"`
	UserID    bson.ObjectId  `bson:"user_id" json:"user_id"`
	RelatedTo string         `bson:"related_to" json:"related_to"`
	RelatedID *bson.ObjectId `bson:"related_id,omitempty" json:"related_id,omitempty"`
	Content   string         `bson:"content" json:"content"`
	Status    status         `bson:"status" json:"status"`
	Reason    string         `bson:"reason" json:"reason"`
	Created   time.Time      `bson:"created_at" json:"created_at"`
	Updated   time.Time      `bson:"updated_at" json:"updated_at"`
	Until     time.Time      `bson:"until" json:"until"`
	Deleted   *time.Time     `bson:"deleted_at,omitempty" json:"-"`
}

Ban represents a ban sent by a user.

func UpsertBan

func UpsertBan(d deps, ban Ban) (Ban, error)

UpsertBan performs validations before upserting data struct

type Gaming

type Gaming struct {
	Swords  int `bson:"swords" json:"swords"`
	Tribute int `bson:"tribute" json:"tribute"`
	Shit    int `bson:"shit" json:"shit"`
	Coins   int `bson:"coins" json:"coins"`
	Level   int `bson:"level" json:"level"`
}

type User

type User struct {
	Id            bson.ObjectId          `bson:"_id,omitempty" json:"id"`
	FirstName     string                 `bson:"first_name" json:"first_name"`
	LastName      string                 `bson:"last_name" json:"last_name"`
	UserName      string                 `bson:"username" json:"username"`
	UserNameSlug  string                 `bson:"username_slug" json:"username_slug"`
	NameChanges   int                    `bson:"name_changes" json:"name_changes"`
	Password      string                 `bson:"password" json:"-"`
	Step          int                    `bson:"step,omitempty" json:"step"`
	Email         string                 `bson:"email" json:"email,omitempty"`
	Categories    []bson.ObjectId        `bson:"categories,omitempty" json:"categories,omitempty"`
	Roles         []UserRole             `bson:"roles" json:"roles,omitempty"`
	Permissions   []string               `bson:"permissions" json:"permissions,omitempty"`
	Description   string                 `bson:"description" json:"description,omitempty"`
	Image         string                 `bson:"image" json:"image"`
	Facebook      interface{}            `bson:"facebook,omitempty" json:"facebook,omitempty"`
	Notifications interface{}            `bson:"notifications,omitempty" json:"notifications,omitempty"`
	Profile       map[string]interface{} `bson:"profile,omitempty" json:"profile,omitempty"`
	Gaming        Gaming                 `bson:"gaming,omitempty" json:"gaming,omitempty"`
	//Stats         UserStats              `bson:"stats,omitempty" json:"stats,omitempty"`
	Version          string `bson:"version,omitempty" json:"version,omitempty"`
	Validated        bool   `bson:"validated" json:"validated"`
	VerificationCode string `bson:"ver_code,omitempty" json:"-"`

	Warnings    int        `bson:"warnings" json:"-"`
	ConfirmSent *time.Time `bson:"confirm_sent_at" json:"-"`
	Created     time.Time  `bson:"created_at" json:"created_at"`
	Updated     time.Time  `bson:"updated_at" json:"updated_at"`

	Banned       bool       `bson:"banned" json:"-"`
	BannedAt     *time.Time `bson:"banned_at" json:"-"`
	BannedUntil  *time.Time `bson:"banned_until" json:"-"`
	BannedReason *string    `bson:"banned_re" json:"-"`
	BannedTimes  int        `bson:"banned_times" json:"-"`
}

func FindEmail

func FindEmail(d deps, email string) (user User, err error)

func FindId

func FindId(d deps, id bson.ObjectId) (user User, err error)

func UseRecoveryToken

func UseRecoveryToken(d deps, clientIP, token string) (user User, jwtAuthToken string, err error)

UseRecoveryToken to generate auth token.

func (User) ConfirmationEmail

func (u User) ConfirmationEmail(d deps) (err error)

func (User) HasRole

func (usr User) HasRole(roles ...string) bool

func (User) RecoveryPasswordEmail

func (u User) RecoveryPasswordEmail(d deps) (err error)

type UserRole

type UserRole struct {
	Name string `bson:"name" json:"name"`
}

type Users

type Users []User

func FindList

func FindList(d deps, scopes ...common.Scope) (users Users, err error)

func (Users) Map

func (list Users) Map() map[bson.ObjectId]User

func (Users) UpdateCache

func (list Users) UpdateCache(d deps) (err error)

type UsersSet

type UsersSet struct {
	List  Users `json:"list"`
	Count int   `json:"count"`
}

func FetchBy

func FetchBy(d deps, query common.Query) (UsersSet, error)

Jump to

Keyboard shortcuts

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