users

package
v0.0.0-...-6dfde0d Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2017 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPasswordConfirmMatch = errors.New("Password and Password Confirm don't match. Try retyping.")
	ErrEmailValidation      = errors.New("Email looks malformed. Check for typos.")
	ErrUsernameValidation   = errors.New("Username can only have letters, numbers, dashes and underscores, and can't be longer than 16 characters. Ex: my_username123")
	ErrNoAPIKey             = errors.New("There is no APIKey for this user")
	ErrAPIKeyExpired        = errors.New("This APIKey has expired")
)

Functions

This section is empty.

Types

type CreatorBinding

type CreatorBinding struct {
	Username        string `json:"username" binding:"required"`
	Email           string `json:"email" binding:"required"`
	PostalCode      string `json:"postal_code" binding:"required"`
	Password        string `json:"password" binding:"required"`
	PasswordConfirm string `json:"password_confirm" binding:"required"`
	DeviceToken     string `json:"device_token"`
}

CreatorBinding is a struct for fields neeeded to create a user via JSON Binding

type LookingFor

type LookingFor int

LookingFor is a bitfield for determining what sort of interaction the user is looking for

const (
	// LNone is the zero value
	LNone LookingFor = 0
	// LFriends - the user is looking for friends
	LFriends LookingFor = 1 << iota
	// LLove - the user is looking for love
	LLove
	// LEnemies - the user is looking for enemies
	LEnemies
)

type UpdaterBinding

type UpdaterBinding struct {
	Gender     string     `json:"gender"`
	Birthdate  string     `json:"birthdate"`
	LookingFor LookingFor `json:"looking_for"`
	Summary    string     `json:"summary"`
	PostalCode string     `json:"postal_code"`
}

UpdaterBinding is a struct for fields neeeded to update a user via JSON Binding

type User

type User struct {
	ID                 string               `json:"id" gorm:"primary_key" sql:"type:uuid;default:uuid_generate_v4()"`
	Username           string               `json:"username" sql:"not null;unique_index" binding:"required"`
	Email              string               `json:"email" sql:"not null;unique_index" binding:"required"`
	Gender             string               `json:"gender"`
	Birthdate          time.Time            `json:"birthdate"`
	AvatarURL          string               `json:"avatar_url"`
	AvatarThumbnailURL string               `json:"avatar_thumbnail_url"`
	PoliticalMap       matcher.PoliticalMap `json:"-" sql:"type:varchar(255)"`
	CenterX            int                  `json:"-"`
	CenterY            int                  `json:"-"`
	PostalCode         string               `json:"postal_code"`
	Location           string               `json:"location"`
	Longitude          float64              `json:"-"`
	Latitude           float64              `json:"-"`
	LookingFor         LookingFor           `json:"looking_for"`
	Summary            string               `json:"summary"`
	CreatedAt          time.Time            `json:"created_at"`
	UpdatedAt          time.Time            `json:"updated_at"`
	APIKey             string               `json:"-" sql:"type:uuid;default:uuid_generate_v4()"`
	APIKeyExp          time.Time            `json:"-"`
	PasswordHash       []byte               `json:"-"`
	DeviceToken        string               `json:"-"`
}

User the user model

func GetByAPIKey

func GetByAPIKey(key string, db *gorm.DB) (u User, err error)

func GetByEmail

func GetByEmail(email string, db *gorm.DB) (u User, err error)

func GetByID

func GetByID(id string, db *gorm.DB) (u User, err error)

func GetByUsername

func GetByUsername(username string, db *gorm.DB) (u User, err error)

func GetRelated

func GetRelated(r UserIDer, us []User) (User, bool)

func ListByIDs

func ListByIDs(ids []string, db *gorm.DB) (us []User, err error)

func ListByUsernames

func ListByUsernames(db *gorm.DB, usernames ...string) (us []User, err error)

func ListRelated

func ListRelated(rs UserIDerSlice, db *gorm.DB) (us []User, err error)

func New

func New(b CreatorBinding) (u User, errs models.ValidationErrors)

New initializes a new User based on the CreatorBinding. Performs Validation and generates location and password.

func (*User) AttachAvatar

func (u *User) AttachAvatar(f multipart.File) error

func (User) CheckPassword

func (u User) CheckPassword(pw string) error

CheckPassword checks the provided password with the password hash, returns an error if they don't match

func (*User) DestroyAPIKey

func (u *User) DestroyAPIKey()

func (*User) GenAPIKey

func (u *User) GenAPIKey() error

GenAPIKey generates a new APIKey and expiration date one week from now

func (*User) GeneratePasswordHash

func (u *User) GeneratePasswordHash(password, confirm string) error

GeneratePasswordHash generates a new password hash from the provided password and confirmation

func (User) GetID

func (u User) GetID() string

func (*User) GetLocation

func (u *User) GetLocation() error

GetLocation finds the latitude/longitude by postal code

func (User) GetPoliticalMap

func (u User) GetPoliticalMap() matcher.PoliticalMap

func (User) GetSubscriberType

func (u User) GetSubscriberType() string

func (*User) Update

func (u *User) Update(b UpdaterBinding) (errs models.ValidationErrors)

Update updates a User based on the UpdaterBinding. Performs Validation and generates location. Does not save to the db.

func (*User) UpdateAPIKey

func (u *User) UpdateAPIKey() error

UpdateAPIKey is meant to be used when a user makes a request, to update the expiration of their APIKey. An APIKey will expire after 1 week of inactivity.

func (*User) Validate

func (u *User) Validate() (errs models.ValidationErrors)

Validate validates the user to ensure it meets the requirements of the system

func (*User) ValidateAPIKey

func (u *User) ValidateAPIKey() error

ValidateAPIKey checks if an APIKey exists, and if it's expired

type UserIDer

type UserIDer interface {
	GetUserID() string
}

type UserIDerSlice

type UserIDerSlice interface {
	GetUserIDs() []string
}

Jump to

Keyboard shortcuts

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