players now created with a name
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
.env
|
||||
.test.env
|
||||
*.db*
|
||||
.logs/
|
||||
server.log
|
||||
|
||||
124
.test.env
124
.test.env
@@ -1,124 +0,0 @@
|
||||
# Environment Configuration
|
||||
# Generated by ezconf
|
||||
#
|
||||
# Variables marked as (required) must be set
|
||||
# Variables with defaults can be left commented out to use the default value
|
||||
|
||||
# HLog Configuration
|
||||
###################
|
||||
# Log level for the logger - trace, debug, info, warn, error, fatal, panic (default: info)
|
||||
LOG_LEVEL=trace
|
||||
|
||||
# Output destination for logs - console, file, or both (default: console)
|
||||
# LOG_OUTPUT=console
|
||||
|
||||
# Directory path for log files (required)
|
||||
LOG_DIR=
|
||||
|
||||
# Name of the log file (required)
|
||||
LOG_FILE_NAME=
|
||||
|
||||
# Append to existing log file or overwrite (default: true)
|
||||
# LOG_APPEND=true
|
||||
|
||||
# HWS Configuration
|
||||
##################
|
||||
# Host to listen on (default: 127.0.0.1)
|
||||
# HWS_HOST=127.0.0.1
|
||||
|
||||
# Port to listen on (default: 3000)
|
||||
HWS_PORT=3333
|
||||
|
||||
# Flag for GZIP compression on requests (default: false)
|
||||
# HWS_GZIP=false
|
||||
|
||||
# Timeout for reading request headers in seconds (default: 2)
|
||||
# HWS_READ_HEADER_TIMEOUT=2
|
||||
|
||||
# Timeout for writing requests in seconds (default: 10)
|
||||
# HWS_WRITE_TIMEOUT=10
|
||||
|
||||
# Timeout for idle connections in seconds (default: 120)
|
||||
# HWS_IDLE_TIMEOUT=120
|
||||
|
||||
# Delay in seconds before server shutsdown when Shutdown is called (default: 5)
|
||||
# HWS_SHUTDOWN_DELAY=5
|
||||
|
||||
# HWSAuth Configuration
|
||||
######################
|
||||
# Enable SSL secure cookies (default: false)
|
||||
# HWSAUTH_SSL=false
|
||||
|
||||
# Full server address for SSL (required)
|
||||
HWSAUTH_TRUSTED_HOST=http://127.0.0.1:3000
|
||||
|
||||
# Secret key for signing JWT tokens (required)
|
||||
HWSAUTH_SECRET_KEY=/2epovpAmHFwdmlCxHRnihT50ZQtrGF/wK7+wiJdFLI=
|
||||
|
||||
# Access token expiry in minutes (default: 5)
|
||||
# HWSAUTH_ACCESS_TOKEN_EXPIRY=5
|
||||
|
||||
# Refresh token expiry in minutes (default: 1440)
|
||||
# HWSAUTH_REFRESH_TOKEN_EXPIRY=1440
|
||||
|
||||
# Token fresh time in minutes (default: 5)
|
||||
# HWSAUTH_TOKEN_FRESH_TIME=5
|
||||
|
||||
# Redirect destination for authenticated users (default: "/profile")
|
||||
# HWSAUTH_LANDING_PAGE="/profile"
|
||||
|
||||
# Database type (postgres, mysql, sqlite, mariadb) (default: "postgres")
|
||||
# HWSAUTH_DATABASE_TYPE="postgres"
|
||||
|
||||
# Database version string (default: "15")
|
||||
HWSAUTH_DATABASE_VERSION=18
|
||||
|
||||
# Custom JWT blacklist table name (default: "jwtblacklist")
|
||||
# HWSAUTH_JWT_TABLE_NAME="jwtblacklist"
|
||||
|
||||
# DB Configuration
|
||||
#################
|
||||
# Database user for authentication (required)
|
||||
DB_USER=pgdev
|
||||
|
||||
# Database password for authentication (required)
|
||||
DB_PASSWORD=pgdevuser
|
||||
|
||||
# Database host address (required)
|
||||
DB_HOST=10.3.0.60
|
||||
|
||||
# Database port (default: 5432)
|
||||
# DB_PORT=5432
|
||||
|
||||
# Database name to connect to (required)
|
||||
DB_NAME=oslstats_test
|
||||
|
||||
# SSL mode for connection (default: disable)
|
||||
# DB_SSL=disable
|
||||
|
||||
# Number of backups to keep (default: 10)
|
||||
# DB_BACKUP_RETENTION=10
|
||||
|
||||
# Discord Configuration
|
||||
######################
|
||||
# Discord application client ID (required)
|
||||
DISCORD_CLIENT_ID=1463459682235580499
|
||||
|
||||
# Discord application client secret (required)
|
||||
DISCORD_CLIENT_SECRET=pinbGa9IkgYQfeBIfBuosor6ODK-JTON
|
||||
|
||||
# Path for the OAuth redirect handler (required)
|
||||
DISCORD_REDIRECT_PATH=auth/callback
|
||||
|
||||
# Token for the discord bot (required)
|
||||
DISCORD_BOT_TOKEN=MTQ2MzQ1OTY4MjIzNTU4MDQ5OQ.GK-9Q6.Z876_JG7oUIKFwKp5snxUjAzloxVjy7KP37TX4
|
||||
|
||||
# OAuth Configuration
|
||||
####################
|
||||
# Private key for signing OAuth state tokens (required)
|
||||
OAUTH_PRIVATE_KEY=b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZWQyNTUxOQAAACDtDHHkeGp1POc0z6/vDj8SK48lVeuGswu/8UO4oBcYSAAAAJj7edqp+3naqQAAAAtzc2gtZWQyNTUxOQAAACDtDHHkeGp1POc0z6/vDj8SK48lVeuGswu/8UO4oBcYSAAAAEAuqALdQqnaDFb5PvuUN4ng1d191hsirOhnahsT0aJFV+0MceR4anU85zTPr+8OPxIrjyVV64azC7/xQ7igFxhIAAAAEWhhZWxub3JyQGZsYWdzaGlwAQIDBA==
|
||||
|
||||
# RBAC Configuration
|
||||
###################
|
||||
# Discord ID to grant admin role on first login (required)
|
||||
ADMIN_DISCORD_ID=202990104170463241
|
||||
@@ -28,14 +28,15 @@ func (p *Player) DisplayName() string {
|
||||
|
||||
// NewPlayer creates a new player in the database. If there is an existing user with the same
|
||||
// discordID, it will automatically link that user to the player
|
||||
func NewPlayer(ctx context.Context, tx bun.Tx, discordID string, audit *AuditMeta) (*Player, error) {
|
||||
player := &Player{DiscordID: discordID}
|
||||
func NewPlayer(ctx context.Context, tx bun.Tx, name, discordID string, audit *AuditMeta) (*Player, error) {
|
||||
player := &Player{DiscordID: discordID, Name: name}
|
||||
user, err := GetUserByDiscordID(ctx, tx, discordID)
|
||||
if err != nil && !IsBadRequest(err) {
|
||||
return nil, errors.Wrap(err, "GetUserByDiscordID")
|
||||
}
|
||||
if user != nil {
|
||||
player.UserID = &user.ID
|
||||
player.Name = user.Username
|
||||
}
|
||||
err = Insert(tx, player).
|
||||
WithAudit(audit, nil).Exec(ctx)
|
||||
@@ -45,6 +46,16 @@ func NewPlayer(ctx context.Context, tx bun.Tx, discordID string, audit *AuditMet
|
||||
return player, nil
|
||||
}
|
||||
|
||||
func NewPlayerFromLog(ctx context.Context, tx bun.Tx, name string, slapID uint32, audit *AuditMeta) (*Player, error) {
|
||||
player := &Player{Name: name, SlapID: &slapID}
|
||||
err := Insert(tx, player).
|
||||
WithAudit(audit, nil).Exec(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Insert")
|
||||
}
|
||||
return player, nil
|
||||
}
|
||||
|
||||
// ConnectPlayer links the user to an existing player, or creates a new player to link if not found
|
||||
// Populates User.Player on success
|
||||
func (u *User) ConnectPlayer(ctx context.Context, tx bun.Tx, audit *AuditMeta) error {
|
||||
@@ -56,7 +67,7 @@ func (u *User) ConnectPlayer(ctx context.Context, tx bun.Tx, audit *AuditMeta) e
|
||||
return errors.Wrap(err, "GetByField")
|
||||
}
|
||||
// Player doesn't exist, create a new one
|
||||
player, err = NewPlayer(ctx, tx, u.DiscordID, audit)
|
||||
player, err = NewPlayer(ctx, tx, u.Username, u.DiscordID, audit)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "NewPlayer")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user