entity

package
v0.0.0-...-4c9bff6 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UsernameLengthMax = 16
	UsernameLengthMin = 8

	PasswordLengthMax = 16
	PasswordLengthMin = 8

	NameLengthMax = 20
)
View Source
const (
	// UserAccountStatusUnknown unknown user
	UserAccountStatusUnknown = iota
	// UserAccountStatusActive user normal status
	UserAccountStatusActive
	// UserAccountStatusSuspend user has been suspended by admin
	UserAccountStatusSuspend
	// UserAccountStatusNotConfirmed user not confirmed
	UserAccountStatusNotConfirmed
)
View Source
const (
	SigninKey = "WfAtSGjzzEw8JeL5GZjs99QLzV5bMdxy"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	Model     string
	Name      string
	OSVersion string
}

type Identity

type Identity struct {
	*User
	*Session
}

Identity aggregate user and session

func (*Identity) NewAccessToken

func (i *Identity) NewAccessToken() string

NewAccessToken new access token

func (*Identity) NewRefreshToken

func (i *Identity) NewRefreshToken() string

NewRefreshToken new refresh token

type NewSessionOption

type NewSessionOption func(p *Session)

func WithDevice

func WithDevice(device Device) NewSessionOption

func WithIdpProvider

func WithIdpProvider(idpProvider string) NewSessionOption

type NewUserOption

type NewUserOption func(p *User) error

func WithEmail

func WithEmail(email string) NewUserOption

WithEmail validate email format

func WithNickname

func WithNickname(nickname string) NewUserOption

WithNickname the method will check nickname format

type Session

type Session struct {
	ID          string
	UserID      string
	CreateAt    time.Time
	UpdateAt    time.Time
	ExpireAt    time.Time
	IPAddress   string
	IdpProvider string
	Platform    string
	Device      Device
}

Session define session

func NewSession

func NewSession(id string, userID string, ip string, platform string, opts ...NewSessionOption) *Session

type User

type User struct {
	// ID unique identity number
	ID string
	// Username user login identity account
	Username string
	// Password user login password
	Password string
	// Nickname of user
	Nickname string
	// FirstName user first name
	FirstName string
	// LastName user last name
	LastName string
	// Email user email address
	Email string
	// Avatar means user profile picture URL
	Avatar string
	// CreatedAt this account create time
	CreatedAt time.Time
	// UpdatedAt this account update time
	UpdatedAt time.Time
	// Status this account is suspend
	Status UserAccountStatus
}

User define user information

func NewUser

func NewUser(
	ID string,
	Username string,
	Password string,
	opts ...NewUserOption,
) (*User, error)

NewUser new user constructor

func (*User) IsActive

func (p *User) IsActive() bool

func (*User) ValidatePassword

func (p *User) ValidatePassword(password string) bool

ValidatePassword check input password match rule password length min <= len <= max password need alphabet password don't have any space or special symbol

func (*User) ValidatePasswordFormat

func (p *User) ValidatePasswordFormat(password string) bool

ValidatePasswordFormat check input password match rule password length min <= len <= max password need alphabet password don't have any space or special symbol

type UserAccountStatus

type UserAccountStatus int8

func (UserAccountStatus) ToString

func (s UserAccountStatus) ToString() string

ToString ..

Jump to

Keyboard shortcuts

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