Documentation ¶
Index ¶
- Variables
- type CreatorBinding
- type LookingFor
- type UpdaterBinding
- type User
- func GetByAPIKey(key string, db *gorm.DB) (u User, err error)
- func GetByEmail(email string, db *gorm.DB) (u User, err error)
- func GetByID(id string, db *gorm.DB) (u User, err error)
- func GetByUsername(username string, db *gorm.DB) (u User, err error)
- func GetRelated(r UserIDer, us []User) (User, bool)
- func ListByIDs(ids []string, db *gorm.DB) (us []User, err error)
- func ListByUsernames(db *gorm.DB, usernames ...string) (us []User, err error)
- func ListRelated(rs UserIDerSlice, db *gorm.DB) (us []User, err error)
- func New(b CreatorBinding) (u User, errs models.ValidationErrors)
- func (u *User) AttachAvatar(f multipart.File) error
- func (u User) CheckPassword(pw string) error
- func (u *User) DestroyAPIKey()
- func (u *User) GenAPIKey() error
- func (u *User) GeneratePasswordHash(password, confirm string) error
- func (u User) GetID() string
- func (u *User) GetLocation() error
- func (u User) GetPoliticalMap() matcher.PoliticalMap
- func (u User) GetSubscriberType() string
- func (u *User) Update(b UpdaterBinding) (errs models.ValidationErrors)
- func (u *User) UpdateAPIKey() error
- func (u *User) Validate() (errs models.ValidationErrors)
- func (u *User) ValidateAPIKey() error
- type UserIDer
- type UserIDerSlice
Constants ¶
This section is empty.
Variables ¶
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 ListByUsernames ¶
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) CheckPassword ¶
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) GeneratePasswordHash ¶
GeneratePasswordHash generates a new password hash from the provided password and confirmation
func (*User) GetLocation ¶
GetLocation finds the latitude/longitude by postal code
func (User) GetPoliticalMap ¶
func (u User) GetPoliticalMap() matcher.PoliticalMap
func (User) GetSubscriberType ¶
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 ¶
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 ¶
ValidateAPIKey checks if an APIKey exists, and if it's expired
type UserIDerSlice ¶
type UserIDerSlice interface {
GetUserIDs() []string
}