mysql

package
v0.0.0-...-a97d171 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DonationSourcePatreon = "patreon"
	DonationSourceManual  = "manual"
)
View Source
const (
	ProductKeyTypeApp     = "app"
	ProductKeyTypePackage = "package"

	ProductKeyFieldCommon   = "common"
	ProductKeyFieldExtended = "extended"
	ProductKeyFieldUFS      = "ufs"
	ProductKeyFieldConfig   = "config"
)
View Source
const (
	UserLevelGuest UserLevel = iota // Guest
	UserLevelFree                   // Free
	UserLevel1                      // Level 1
	UserLevel2                      // Level 2
	UserLevel3                      // Level 3

	// Pages
	UserLevelLimitGuest = 5   // Guest
	UserLevelLimitFree  = 10  // Free
	UserLevelLimit1     = 10  // Level 1
	UserLevelLimit2     = 100 // Level 2
	UserLevelLimit3     = 0   // Level 3
)
View Source
const (
	ConsumerSessionLength = time.Second * 70 // Time to keep the key for

)

Variables

View Source
var ErrExpiredVerification = errors.New("verification code expired")
View Source
var (
	ErrRecordNotFound = gorm.ErrRecordNotFound
)

Functions

func CheckExistingUserProvider

func CheckExistingUserProvider(provider oauth.ProviderEnum, id string, userID int) (used bool, err error)

func Close

func Close()

func CountUsers

func CountUsers() (count int, err error)

func DeleteUserProvider

func DeleteUserProvider(providerEnum oauth.ProviderEnum, userID int) (err error)

func GetAllConfigs

func GetAllConfigs() (configsMap map[string]Config, err error)

func GetConsumer

func GetConsumer(tag string) (err error)

func GetDonationCountByUser

func GetDonationCountByUser(userID int) (count int, err error)

func GetMySQLClient

func GetMySQLClient() (conn *gorm.DB, err error)

func GetUserSteamID

func GetUserSteamID(userID int) int64

func GetUserVerification

func GetUserVerification(code string) (userID int, err error)

func SendUserVerification

func SendUserVerification(userID int, userEmail string, r *http.Request) error

func SetChatBotSettings

func SetChatBotSettings(discordID string, callback func(s *ChatBotSetting)) (err error)

func SetConfig

func SetConfig(id ConfigID, value string) (err error)

func UpdateUserProvider

func UpdateUserProvider(userID int, provider oauth.ProviderEnum, resp oauth.User) error

func VerifyUser

func VerifyUser(userID int) error

Types

type ChatBotSetting

type ChatBotSetting struct {
	CreatedAt   time.Time          `gorm:"not null"`
	UpdatedAt   time.Time          `gorm:"not null"`
	DeletedAt   *time.Time         `gorm:""`
	DiscordID   string             `gorm:"not null;column:discord_id;primary_key"`
	ProductCode steamapi.ProductCC `gorm:"not null;column:product_cc;index:name"`
}

func GetChatBotSettings

func GetChatBotSettings(discordID string) (settings ChatBotSetting, err error)

type Config

type Config struct {
	ID        string     `gorm:"not null;column:id;primary_key"`
	UpdatedAt *time.Time `gorm:"not null;column:updated_at"`
	Value     string     `gorm:"not null;column:value"`
}

func GetConfig

func GetConfig(id ConfigID) (config Config, err error)

type ConfigID

type ConfigID string

func (ConfigID) String

func (c ConfigID) String() string

type Consumer

type Consumer struct {
	Key         string    `gorm:"not null;column:key;primary_key"`
	Use         bool      `gorm:"not null;column:use;"`
	Expires     time.Time `gorm:"not null;column:expires;type:datetime"`
	Owner       string    `gorm:"not null;column:owner"`
	IP          string    `gorm:"not null;column:ip"`
	Environment string    `gorm:"not null;column:environment"`
	Version     string    `gorm:"not null;column:version"`
	Commits     string    `gorm:"not null;column:commits"`
	Notes       string    `gorm:"-"`
}

type Donation

type Donation struct {
	ID               int       `gorm:"not null;column:id;primary_key;auto_increment"`
	CreatedAt        time.Time `gorm:"not null;column:created_at"`
	UserID           int       `gorm:"not null;column:user_id"`
	PlayerID         int64     `gorm:"not null;column:player_id"`
	Email            string    `gorm:"not null;column:email"`
	AmountUSD        int       `gorm:"not null;column:amount_usd"`
	OriginalCurrency string    `gorm:"not null;column:original_currency"`
	OriginalAmount   int       `gorm:"not null;column:original_amount"`
	Source           string    `gorm:"not null;column:source"`
	Anon             bool      `gorm:"not null;column:anon"`
	PatreonRef       string    `gorm:"column:patreon_ref"` // Nullable, indexed
}

func GetDonationsByUser

func GetDonationsByUser(userID int, offset int) (donations []Donation, err error)

func LatestDonations

func LatestDonations() (donations []Donation, err error)

func (Donation) Format

func (d Donation) Format() string

type DonationSource

type DonationSource string

type GroupedDonation

type GroupedDonation struct {
	PlayerID  int64 `json:"player_id"`
	Donations int   `json:"donations"`
}

func TopDonators

func TopDonators() (donations []GroupedDonation, err error)

func (GroupedDonation) Format

func (d GroupedDonation) Format() string

type ProductKey

type ProductKey struct {
	Type      string     `gorm:"not null;primary_key"`
	Field     string     `gorm:"not null;primary_key"`
	Key       string     `gorm:"not null;primary_key"`
	CreatedAt time.Time  `gorm:"not null"`
	UpdatedAt time.Time  `gorm:"not null"`
	DeletedAt *time.Time `gorm:""`
	Count     int        `gorm:"not null"`
}

func GetProductKeys

func GetProductKeys() (keys []ProductKey, err error)

func (ProductKey) FieldTitle

func (key ProductKey) FieldTitle() string

func (ProductKey) Save

func (key ProductKey) Save() error

type User

type User struct {
	ID             int                `gorm:"not null;column:id;primary_key"`
	CreatedAt      time.Time          `gorm:"not null;column:created_at"`
	UpdatedAt      time.Time          `gorm:"not null;column:updated_at"`
	LoggedInAt     *time.Time         `gorm:"column:logged_in_at;type:datetime"`
	Email          string             `gorm:"not null;column:email;unique_index"`
	EmailVerified  bool               `gorm:"not null;column:email_verified"`
	Password       string             `gorm:"not null;column:password"`
	Level          UserLevel          `gorm:"not null;column:level"`
	ProductCC      steamapi.ProductCC `gorm:"not null;column:country_code"`
	APIKey         string             `gorm:"not null;column:api_key"`
	DonatedPatreon int                `gorm:"not null;column:donated_patreon"`
}

func GetUserByAPIKey

func GetUserByAPIKey(key string) (user User, err error)

func GetUserByEmail

func GetUserByEmail(email string) (user User, err error)

func GetUserByID

func GetUserByID(id int) (user User, err error)

func GetUserByProviderID

func GetUserByProviderID(provider oauth.ProviderEnum, providerID string) (user User, err error)

func NewUser

func NewUser(r *http.Request, userEmail, password string, prodCC steamapi.ProductCC, verified bool) (user User, err error)

func (*User) SetAPIKey

func (user *User) SetAPIKey()

func (User) SetPassword

func (user User) SetPassword(b []byte) error

func (User) SetProdCC

func (user User) SetProdCC(cc steamapi.ProductCC) error

func (User) TouchLoggedInTime

func (user User) TouchLoggedInTime() error

type UserLevel

type UserLevel uint8

func (UserLevel) MaxOffset

func (ul UserLevel) MaxOffset(limit int64) int64

func (UserLevel) MaxResults

func (ul UserLevel) MaxResults(limit int64) int64

type UserProvider

type UserProvider struct {
	UserID    int                `gorm:"not null;column:user_id;primary_key"`
	Provider  oauth.ProviderEnum `gorm:"not null;column:provider;primary_key"`
	CreatedAt time.Time          `gorm:"not null;column:created_at"`
	UpdatedAt time.Time          `gorm:"not null;column:updated_at"`
	DeletedAt *time.Time         `gorm:"not null;column:deleted_at"`
	Token     string             `gorm:"not null;column:token"`
	ID        string             `gorm:"not null;column:id"`
	Email     string             `gorm:"not null;column:email"`
	Username  string             `gorm:"not null;column:username"`
	Avatar    string             `gorm:"not null;column:avatar"`
}

func GetUserProviderByProviderID

func GetUserProviderByProviderID(provider oauth.ProviderEnum, providerID string) (userProvider UserProvider, err error)

func GetUserProviderByUserID

func GetUserProviderByUserID(enum oauth.ProviderEnum, userID int) (userProvider UserProvider, err error)

func GetUserProviders

func GetUserProviders(userID int) (providers []UserProvider, err error)

func (UserProvider) GetToken

func (up UserProvider) GetToken() (token oauth2.Token, err error)

type UserVerification

type UserVerification struct {
	CreatedAt time.Time `gorm:"not null;column:created_at"`
	Code      string    `gorm:"not null;column:code;primary_key"`
	UserID    int       `gorm:"not null;column:user_id"`
	Expires   time.Time `gorm:"not null;column:expires"`
}

func CreateUserVerification

func CreateUserVerification(userID int) (userVerification UserVerification, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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