data

package
v0.0.0-...-5b94ac3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2021 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ScopeActivation is used to generate an activation token.
	ScopeActivation string = "activation"
	// ScopeAuthentication is used to generate an authentication token.
	ScopeAuthentication string = "authentication"
)

Variables

View Source
var (
	// ErrDuplicateKey is returned when a record with duplicate values is attempted to be inserted into the database.
	ErrDuplicateKey = errors.New("username and or email already taken")
	// ErrRecordNotFound is returned when a find database query returns no record.
	ErrRecordNotFound = errors.New("record not found")
	// ErrInvalidOrExpiredToken is returned when token find query returns no record.
	ErrInvalidOrExpiredToken = errors.New("invalid or expired token")
	// ErrInvalidProperty is returned when user activation data contains invalid properties.
	ErrInvalidProperty = errors.New("Invalid property")
)
View Source
var AnonymousUser = &User{}

AnonymousUser represents a user type instance with only defaults.

View Source
var EmailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")

EmailRegex represents an email regular expression.

Functions

func ValidateEmail

func ValidateEmail(v *validator.Validator, email string)

ValidateEmail validates an email address.

func ValidatePassword

func ValidatePassword(v *validator.Validator, password string)

ValidatePassword validates a password.

func ValidatePlainTextToken

func ValidatePlainTextToken(v *validator.Validator, token string)

ValidatePlainTextToken checks that the plaintext token is provided and is exactly 52 bytes long

Types

type Password

type Password struct {
	PlainText *string `bson:"-"`
	Hash      []byte
}

Password represents a password type model.

func (*Password) DoesMatch

func (p *Password) DoesMatch(plainTextPassword string) (bool, error)

DoesMatch compares the plain text password with a password hash.

func (*Password) Set

func (p *Password) Set(plainTextPassword string) error

Set calculates the password hash.

type Token

type Token struct {
	ID        string    `json:"-,omitempty" bson:"_id,omitempty"`
	PlainText string    `json:"token" bson:"-"`
	Hash      []byte    `json:"-"`
	UserID    string    `json:"-" bson:"user_id"`
	Expiry    time.Time `json:"expiry" bson:"expiry,omitempty"`
	Scope     string    `json:"-"`
}

Token encapsulates data for an individual token.

func GenerateToken

func GenerateToken(validFor time.Duration, userID string, scope string) (*Token, error)

GenerateToken returns a fully configured instance of a Token type.

type User

type User struct {
	ID        string    `json:"_id,omitempty" bson:"_id,omitempty"`
	Username  string    `json:"username" bson:"username"`
	Email     string    `json:"email" bson:"email"`
	Password  Password  `json:"-" bson:"password"`
	IsActive  bool      `json:"is_active" bson:"isactive"`
	IsSeller  bool      `json:"is_seller" bson:"isseller"`
	Version   int64     `json:"version" bson:"version"`
	CreatedAt time.Time `json:"created_at" bson:"created_at"`
}

User represents the user type model.

func (*User) IsAnonymous

func (u *User) IsAnonymous() bool

IsAnonymous performs an equality check on a user instance to verify if it's an anonymous user.

func (*User) Validate

func (u *User) Validate(v *validator.Validator)

Validate validates a user instance's field values.

Jump to

Keyboard shortcuts

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