user

package
v0.0.0-...-1ad4281 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserNameLength 5 to 64 characters
	ErrUserNameLength = errtools.InvalidLen(5, 64)
	// ErrUserNameTaken characters
	ErrUserNameTaken = errors.New(taken)
)
View Source
var (
	// ErrEmailInvalid Invalid Email
	ErrEmailInvalid = errors.New("invalid-email")
	// ErrEmailTaken characters
	ErrEmailTaken = errors.New(taken)
)
View Source
var (
	ErrPasswordLength   = errtools.InvalidLen(8, 1024)
	ErrPasswordStrength = errors.New("weak-password")
)

ErrPasswordLength 8 to 1024

View Source
var (
	// ErrBioLength 0 to 255 characters
	ErrBioLength = errtools.InvalidLen(0, 255)
)
View Source
var (
	// ErrNameLength 1 to 128 characters
	ErrNameLength = errtools.InvalidLen(1, 128)
)
View Source
var ErrViewMeNot = errors.New("user/view: Error can't view user")

Functions

func Accept

func Accept(userId, followerUserId int64) error

Accept userId Accept followerUserId request

func AcceptAll

func AcceptAll(userId int64) error

AcceptAll userId Accept all follow request Called when accounts goes from private to public

func CanView

func CanView(userId int64, sUser *session.Session) error

CanView can userId be viewed by session user

return nil if userId can be viewed

func Decline

func Decline(userId, followerUserId int64) error

Decline userId Decline followerUserId request

func Follow

func Follow(userId int64, followUserId int64) error

Follow userId follow followUserId

func FollowExt

func FollowExt(userId int64, followUserId int64, accepted bool) error

func Followers

func Followers(userId int64) (followers int64, err error)

Followers count userId followers

func GetEmailByID

func GetEmailByID(userID int64) (email string, err error)

GetEmailByID get email by user id

func GetIDByEmail

func GetIDByEmail(email string) (userID int64, err error)

GetIDByEmail get user id by email

func GetIDByUserName

func GetIDByUserName(username string) (userID int64, err error)

GetIDByUserName get user id by username

func GetUserNameByID

func GetUserNameByID(userID int64) (userName string, err error)

GetUserNameByID get userName by user id

func IsVerified

func IsVerified(userID int64) (bool, error)

IsVerified is user type != Unverified

func ListFollowers

func ListFollowers(userId int64) ([]int64, error)

ListFollows return a slice of userId(s) that follow userId

func ListFollowing

func ListFollowing(userId int64) ([]int64, error)

ListFollowing return a slice of userId(s) that userId follows

func ListRequests

func ListRequests(userId int64) (map[int64]int64, error)

ListRequests return a ordered map of userId(s) that request to follow userId TODO limit

func Unfollow

func Unfollow(userId, unfollowId int64) error

func UpdateBio

func UpdateBio(userId int64, bio string) error

func UpdateName

func UpdateName(userId int64, name string) error

func UpdateType

func UpdateType(userID int64, t Types) error

UpdateType update user's type

func ValidBio

func ValidBio(bio string) error

func ValidEmail

func ValidEmail(email string) error

ValidEmail Validate

func ValidName

func ValidName(name string) error

ValidName Validate

func ValidPassword

func ValidPassword(pass string, userInputs ...string) error

ValidPassword check password

Types

type FollowStruct

type FollowStruct struct {
	Following bool `msg:"-" json:"following"`
	Requested bool `msg:"-" json:"requested"`
}

func Following

func Following(userId, followUserId int64) (follow FollowStruct, err error)

Following is userId following followUserId

func (*FollowStruct) DecodeMsg

func (z *FollowStruct) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (FollowStruct) EncodeMsg

func (z FollowStruct) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (FollowStruct) MarshalMsg

func (z FollowStruct) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (FollowStruct) Msgsize

func (z FollowStruct) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*FollowStruct) UnmarshalMsg

func (z *FollowStruct) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type List

type List struct {
	Users ListUsers `json:"users"`
}

func (*List) AddUser

func (l *List) AddUser(s *session.Session, userID int64, userStruct ...*User) error

AddTo add user to list if not already

func (*List) Exist

func (l *List) Exist(userID int64) bool

Exist userid in map

type ListUsers

type ListUsers map[int64]*User

type Types

type Types int8

User Types

const (
	Unverified Types = iota
	Private
	Public
)

func GetType

func GetType(userID int64) (t Types, err error)

GetType get user's type

func (*Types) DecodeMsg

func (z *Types) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Types) EncodeMsg

func (z Types) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Types) MarshalMsg

func (z Types) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Types) Msgsize

func (z Types) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (Types) Private

func (t Types) Private() bool

Private is type == Private

func (Types) Public

func (t Types) Public() bool

Public is type == Public

func (*Types) UnmarshalMsg

func (z *Types) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (Types) Unverified

func (t Types) Unverified() bool

Unverified is type == Unverified

type User

type User struct {
	ID          int64        `msg:"id" json:"id"`
	UserName    string       `msg:"userName" json:"userName"`
	Name        string       `msg:"name" json:"name"`
	Email       string       `msg:"email" json:"email,omitempty"`
	Avatar      string       `msg:"-" json:"avatar"`
	Bio         string       `msg:"bio" json:"bio,omitempty"`
	SelfFollow  FollowStruct `msg:"-" json:"selfFollow,omitempty"`
	UserFollow  FollowStruct `msg:"-" json:"userFollow,omitempty"`
	Followers   int64        `msg:"followers" json:"followers"`
	Type        Types        `msg:"type" json:"type"`
	Permissions perms.Perms  `msg:"permissions" json:"-"`
	Created     int64        `msg:"created" json:"created,omitempty"`
}

User Struct

func GetPublic

func GetPublic(s *session.Session, userID int64) (user User, err error)

GetPublic user info for session user TODO: Cache

func New

func New(userName, name, email string) *User

New user

func (*User) DecodeMsg

func (z *User) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*User) EncodeMsg

func (z *User) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*User) Insert

func (u *User) Insert() error

Insert new user into database

returns nil and sets user.ID on success

func (*User) IsEmailUnique

func (u *User) IsEmailUnique() error

IsEmailUnique check if Email Exists

func (*User) MarshalMsg

func (z *User) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*User) Msgsize

func (z *User) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*User) SetDefaultPerms

func (u *User) SetDefaultPerms()

SetDefaultPerms sets default permissions

func (*User) UnmarshalMsg

func (z *User) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*User) ValidBio

func (u *User) ValidBio() error

ValidBio Validate

func (*User) ValidEmail

func (u *User) ValidEmail() error

ValidEmail Validate

func (*User) ValidName

func (u *User) ValidName() error

ValidName Validate

func (*User) ValidPassword

func (u *User) ValidPassword(pass string) error

ValidPassword check password

func (*User) ValidUserName

func (u *User) ValidUserName() error

ValidUserName Validate

func (*User) ValidatePublic

func (u *User) ValidatePublic() (v ValidationErrors)

ValidatePublic values

type ValidationErrStrings

type ValidationErrStrings struct {
	UserName string `json:"userName,omitempty"`
	Name     string `json:"name,omitempty"`
	Email    string `json:"email,omitempty"`
	Bio      string `json:"bio,omitempty"`
}

type ValidationErrors

type ValidationErrors struct {
	UserName error
	Name     error
	Email    error
	Bio      error
}

func (*ValidationErrors) Empty

func (v *ValidationErrors) Empty() bool

Empty Are all errors nil

func (*ValidationErrors) ToString

func (v *ValidationErrors) ToString() *ValidationErrStrings

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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