models

package
v0.0.0-...-692b37b Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Validation constants
	MaxNameSize            = 255
	MaxValueSize           = 4096
	MaxEmailLocalPartSize  = 64
	MaxEmailServerPartSize = 255
)

Variables

View Source
var (
	// Regular expression list
	// Meant to provide a simple syntax check; e.g. good luck validating
	// emails
	UsernameRe     = regexp.MustCompile(`^\w(?:\S?\w){2,127}$`)
	EmailAddressRe = regexp.MustCompile(`^.+@.+\..+$`)
	PhoneRe        = regexp.MustCompile(`^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$`)

	// Errors list
	ErrorInvalidName         = fmt.Errorf("Name exceeds max length of %d", MaxNameSize)
	ErrorInvalidEmailAddress = errors.New("Email address is invalid")
	ErrorInvalidUsername     = errors.New("Username is invalid")
	ErrorInvalidPhonenumber  = errors.New("Phonenumber is invalid")
	ErrorInvalidOptions      = errors.New("Options contain invalid key-value pair")
)
View Source
var UserTypeStrings = []string{
	"USER",
	"GUEST",
	"ADMIN",
}

UserTypeStrings is a list of string representations of user types.

Functions

func Base64URLDecode

func Base64URLDecode(s string) ([]byte, error)

Base64URLEncode returns the bytes for the given base64 URL encoded string.

func Base64URLEncode

func Base64URLEncode(b []byte) string

Base64URLEncode returns a base64 URL encoded string for the given bytes.

func Decode

func Decode(s string) ([]byte, error)

Encode returns the bytes for a base64 (w/o padding) encoded string.

func DecodeJSON

func DecodeJSON(s string, v interface{}) error

DecodeJSON sets the given data struct to the decoded bytes of the given string.

func Encode

func Encode(v []byte) string

Encode returns a base64 (w/o padding) encoded string for the given bytes.

func EncodeJSON

func EncodeJSON(data interface{}) (string, error)

EncodeJSON returns the encoded string for a given data struct.

func ValidEmailAddress

func ValidEmailAddress(email string) bool

ValidEmailAddress return true if the given email address is valid.

func ValidOptions

func ValidOptions(options Options) bool

ValidOptions returns true if the options map is valid.

func ValidPhonenumber

func ValidPhonenumber(phone string) bool

ValidPhonenumber returns true if the given phonenumber is valid.

func ValidUsername

func ValidUsername(username string) bool

ValidUsername returns true if the given username is valid.

Types

type AccessToken

type AccessToken struct {
	Token        string `json:"token"`
	RefreshToken string `json:"refresh_token"`
	OtpRequired  bool   `json:"otp_required"`
}

AccessToken represents an access and refresh tokens.

type Login

type Login struct {
	Name     string `json:"name"`
	Password string `json:"password"`
}

Login represents a login request.

type Options

type Options map[string]string

Options represents a map of optional user attributes.

func (Options) GormDBDataType

func (o Options) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType returns the DB datatype for the given database's dialect. This implements the migrator.GormDataTypeInterface interface.

func (Options) GormDataType

func (o Options) GormDataType() string

GormDataType returns the GORM datatype of the options. This implements the schema.GormDataTypeInterface interface.

func (Options) GormValue

func (o Options) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

GormValue returns the GORM expression for the given database and options. This implements the gorm.Valuer interface.

func (Options) MarshalJSON

func (o Options) MarshalJSON() ([]byte, error)

MarshalJSON marshals the options value and encodes as JSON.

func (*Options) Scan

func (o *Options) Scan(val interface{}) error

Scan scans the given bytes or string value into the given options. This implements the sql.Scanner interface.

func (*Options) UnmarshalJSON

func (o *Options) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the given JSON bytes into the options.

func (*Options) Value

func (o *Options) Value() (driver.Value, error)

Value returns the SQL driver value for the given options. This implements the gorm.Valuer interface.

type SignedPublicKey

type SignedPublicKey struct {
	Id        string `json:"id"`
	Alg       string `json:"alg"`
	KTy       string `json:"kty"`
	User      string `json:"user"`
	PublicKey string `json:"public_key"`
	Signature string `json:"signature"`
}

SignedPublicKey respresents a public key authentication request.

func (*SignedPublicKey) SigningAlgorithm

func (key *SignedPublicKey) SigningAlgorithm() (algorithms.SigningAlgorithm, error)

SigningAlgorithm returns the signing algorithm of the signed public key.

func (*SignedPublicKey) SigningString

func (key *SignedPublicKey) SigningString() (string, error)

SigningString returns the encoded signing string of the signed public key.

func (*SignedPublicKey) Valid

func (key *SignedPublicKey) Valid(secret []byte) error

Valid verifies the signed public key's signature using the given secret.

type Totp

type Totp struct {
	Enabled bool   `json:"enabled"`
	Otp     string `json:"otp"`
	Qr      []byte `json:"qr"`
}

Totp represents a timed-based OTP.

type User

type User struct {
	ID           uint           `gorm:"primarykey" json:"-"`
	CreatedAt    time.Time      `json:"created_at"`
	UpdatedAt    time.Time      `json:"updated_at"`
	DeletedAt    gorm.DeletedAt `gorm:"index" json:"-"`
	FirstName    string         `json:"first_name"`
	LastName     string         `json:"last_name"`
	Password     string         `json:"password"`
	Email        string         `json:"email"`
	Username     string         `json:"username"`
	Phone        string         `json:"phone"`
	UserType     string         `json:"user_type"`
	UserId       string         `json:"user_id"`
	Token        string         `json:"-"`
	RefreshToken string         `json:"-"`
	TotpEnabled  bool           `json:"totp_enabled"`
	Totp         string         `json:"-"`
	Options      Options        `gorm:"serializer:json" json:"options"`
	PublicKey    string         `json:"public_key"`
}

User models a user in the authentication service.

func (User) Valid

func (u User) Valid() error

Valid returns nil when the user is valid, otherwise an error is returned.

type UserType

type UserType int

UserType represents a user's type.

const (
	// User types
	BaseUserType UserType = iota
	GuestUserType
	AdminUserType
)

func ToUserType

func ToUserType(s string) (UserType, error)

ToUserType returns the UserType for a value user type string. Otherwise an error is returned.

func (UserType) String

func (ut UserType) String() string

String returns the string representation of the user type.

type Users

type Users struct {
	Total int    `json:"total_count"`
	Users []User `json:"user_items"`
}

Users represents a list of users.

Jump to

Keyboard shortcuts

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