Add admin-route & dropdown-menu. Add clear-cache & create-code. Adjustments for activation-code and user models. Add sweet-alert for admin-tools.

This commit is contained in:
MaxJa4
2024-01-20 16:47:22 +01:00
parent f2ab72ba1e
commit e5d13f2270
15 changed files with 281 additions and 55 deletions

View File

@@ -1,6 +1,8 @@
package models
type ActivationCode struct {
Code string
Used bool
Code string `gorm:"primary_key"`
UserRole Role
UsedForUsername string
UsedFor User `gorm:"foreignKey:UsedForUsername"`
}

View File

@@ -44,8 +44,8 @@ func ConnectDatabase() {
var code ActivationCode
if err := database.First(&code).Error; err != nil {
firstCode := utils.GenerateActivationCode()
database.Create(&ActivationCode{Code: firstCode, Used: false})
log.Println("Created first activation code: " + firstCode)
database.Create(&ActivationCode{Code: firstCode, UserRole: AdminRole})
log.Println("Created first activation code with ADMIN role:\n" + firstCode)
}
}
err = database.AutoMigrate(&Game{})

View File

@@ -4,4 +4,13 @@ type User struct {
Username string `json:"username" gorm:"primary_key"`
Password string `json:"password"`
Enabled bool `json:"enabled" default:"1"`
UserRole Role `json:"user_role" default:"READER"`
}
type Role string
const (
AdminRole Role = "ADMIN"
AuthorRole Role = "AUTHOR"
ReaderRole Role = "READER"
)