models

package
v0.0.0-...-0f5609b Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecordActivity

func RecordActivity(message string, gameAccount *GameAccount, session *Session) bool

Types

type Activity

type Activity struct {
	gorm.Model
	Message       string `gorm:"type:varchar(160);not null"`
	GameAccount   *GameAccount
	GameAccountID int
	Session       *Session
	SessionID     int
}

func (*Activity) Delete

func (activity *Activity) Delete()

func (*Activity) Update

func (activity *Activity) Update() *Activity

type GameAccount

type GameAccount struct {
	gorm.Model
	UID        int `gorm:"type:varchar(69);not null;unique;unique_index;primary_key"`
	Level      int `gorm:"type:varchar(6);not null"`
	LastActive int
	User       *User `gorm:"not null"`
	UserID     int
	Banned     bool
	Activities []*Activity `gorm:"many2many:game_activities;"`
}

func FindGameAccount

func FindGameAccount(uid int) (*GameAccount, error)

func RegisterGameAccount

func RegisterGameAccount(user *User, uid int, level int) (*GameAccount, error)

func (*GameAccount) Ban

func (gameAccount *GameAccount) Ban(doSave bool) *GameAccount

func (*GameAccount) Delete

func (gameAccount *GameAccount) Delete()

func (*GameAccount) RecordActivity

func (gameAccount *GameAccount) RecordActivity(message string) bool

func (*GameAccount) SetLevel

func (gameAccount *GameAccount) SetLevel(level int, doSave bool) *GameAccount

func (*GameAccount) SetUser

func (gameAccount *GameAccount) SetUser(user *User, doSave bool) *GameAccount

func (*GameAccount) Unban

func (gameAccount *GameAccount) Unban(doSave bool) *GameAccount

func (*GameAccount) Update

func (gameAccount *GameAccount) Update() *GameAccount

type Serial

type Serial struct {
	gorm.Model
	Code                 string `gorm:"type:varchar(69);not null;unique;unique_index;primary_key"`
	ExpireAt             int64  `gorm:"not null"`
	SubscriptionDuration int    `gorm:"default:30;not null"`
	Used                 bool   `gorm:"default:false;not null"`
	User                 *User
	UserID               int
}

func FindAndValidateSerial

func FindAndValidateSerial(serialCode string) (*Serial, error)

func FindSerial

func FindSerial(serialCode string) (*Serial, error)

func GenerateSerial

func GenerateSerial(expireAt, SubscriptionDuration int) (*Serial, error)

func ValidateSerial

func ValidateSerial(serial *Serial) (*Serial, error)

func (*Serial) Delete

func (serial *Serial) Delete()

func (*Serial) Expire

func (serial *Serial) Expire()

func (*Serial) Update

func (serial *Serial) Update() *Serial

func (*Serial) Validate

func (serial *Serial) Validate() (*Serial, error)

type Session

type Session struct {
	gorm.Model
	SessionID    string `gorm:"type:varchar(69);not null;unique;unique_index;primary_key"`
	LastActive   int    `gorm:"default:0;not null"`
	UserAgent    string `gorm:"type:varchar(180);not null"`
	User         *User  `gorm:"not null"`
	UserID       int
	Expired      bool
	Activities   []*Activity    `gorm:"many2many:session_activities;"`
	GameAccounts []*GameAccount `gorm:"many2many:session_accounts;"`
}

func CreateSession

func CreateSession(user *User, userAgent string) (*Session, string, error)

func FindAndValidateSession

func FindAndValidateSession(tokenString string, userAgent string) (*Session, error)

func FindSession

func FindSession(tokenString string) (*Session, error)

func (*Session) Delete

func (session *Session) Delete()

func (*Session) Expire

func (session *Session) Expire() *Session

func (*Session) RecordActivity

func (session *Session) RecordActivity(message string) bool

func (*Session) Update

func (session *Session) Update() *Session

type Setting

type Setting struct {
	gorm.Model
	Name   string `gorm:"type:varchar(16);not null"`
	User   *User  `gorm:"not null"`
	UserID int
}

func CreateSetting

func CreateSetting(user *User, name string) (*Setting, error)

func FindSetting

func FindSetting(user *User, name string) (*Setting, error)

func (*Setting) Delete

func (setting *Setting) Delete()

func (*Setting) Update

func (setting *Setting) Update() *Setting

func (*Setting) UpdateName

func (setting *Setting) UpdateName(name string) *Setting

type User

type User struct {
	gorm.Model
	Username     string         `gorm:"type:varchar(32);not null;unique;unique_index;primary_key"`
	Email        string         `gorm:"type:varchar(69);not null;unique;"`
	Password     string         `gorm:"not null"`
	Subscription int64          `gorm:"default:0"`
	Role         string         `gorm:"type:varchar(16);default:'Member';not null;"`
	GameAccounts []*GameAccount `gorm:"many2many:user_accounts;"`
	Settings     []*Setting
	Sessions     []*Session
}

func FindUser

func FindUser(username, password string) (*User, error)

func RegisterUser

func RegisterUser(username, email, password string) (*User, error)

func (*User) AfterCreate

func (user *User) AfterCreate(scope *gorm.Scope)

func (*User) Ban

func (user *User) Ban(doSave bool) *User

func (*User) CreateSession

func (user *User) CreateSession(userAgent string) (*Session, string, error)

func (*User) CreateSetting

func (user *User) CreateSetting(name string) (*Setting, error)

func (*User) Delete

func (user *User) Delete()

func (*User) FindSetting

func (user *User) FindSetting(name string) (*Setting, error)

func (*User) IsBanned

func (user *User) IsBanned() bool

func (*User) IsGuest

func (user *User) IsGuest() bool

func (*User) IsHasSubscription

func (user *User) IsHasSubscription() bool

func (*User) IsMember

func (user *User) IsMember() bool

func (*User) IsOwner

func (user *User) IsOwner() bool

func (*User) IsSubscriber

func (user *User) IsSubscriber() bool

func (*User) RegisterGameAccount

func (user *User) RegisterGameAccount(uid int, level int) (*GameAccount, error)

func (*User) Subscribe

func (user *User) Subscribe(serialCode string) error

func (*User) Unban

func (user *User) Unban(newRole string, doSave bool) *User

func (*User) Update

func (user *User) Update() *User

func (*User) ValidateSubscription

func (user *User) ValidateSubscription() error

Jump to

Keyboard shortcuts

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