From f56196e115851059d9537d5601a323102df13f3a Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Thu, 2 Jul 2026 22:40:23 +0200 Subject: [PATCH] replace email with username --- .env.example | 2 +- README.md | 4 ++-- src/config/config.go | 4 ++-- src/database/connection.go | 11 +++++------ src/models/user.go | 16 ++++++++-------- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.env.example b/.env.example index 88af67d..4b9f170 100644 --- a/.env.example +++ b/.env.example @@ -10,7 +10,7 @@ JWT_SECRET=your-super-secret-jwt-key-here SYNC_INTERVAL_MINUTES=1 # Default Admin User Configuration -ADMIN_EMAIL=admin@admin.com +ADMIN_USERNAME=admin ADMIN_PASSWORD=sheetless # Directories containing permanent data diff --git a/README.md b/README.md index 5de8998..70098d7 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ go build -o sheetless-server main.go ```bash curl -X POST http://localhost:8080/auth/register \ -H "Content-Type: application/json" \ - -d '{"username":"testuser","email":"test@example.com","password":"password123"}' + -d '{"username":"testuser","password":"password123"}' ``` ### Login: @@ -71,4 +71,4 @@ curl -X POST http://localhost:8080/api/sheets/upload \ ### List sheets: ```bash curl -H "Authorization: Bearer TOKEN" http://localhost:8080/api/sheets -``` \ No newline at end of file +``` diff --git a/src/config/config.go b/src/config/config.go index 4ea9dec..fe36f32 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -19,7 +19,7 @@ type Config struct { Interval time.Duration } Admin struct { - Email string + Username string Password string } SheetsDirectory string @@ -44,7 +44,7 @@ func Load() { cfg.Sync.Interval = time.Duration(syncMinutes) * time.Minute // Admin configuration - cfg.Admin.Email = getEnv("ADMIN_EMAIL", "admin@admin.com") + cfg.Admin.Username = getEnv("ADMIN_USERNAME", "admin") cfg.Admin.Password = getEnv("ADMIN_PASSWORD", "sheetless") cfg.SheetsDirectory = getEnv("SHEETS_DIRECTORY", "./sheets_directory") diff --git a/src/database/connection.go b/src/database/connection.go index 6a15743..db63935 100644 --- a/src/database/connection.go +++ b/src/database/connection.go @@ -44,10 +44,10 @@ func InitDatabase() { func createDefaultAdminUser() { // Check if admin user already exists var existingUser models.User - err := DB.Where("email = ?", config.AppConfig.Admin.Email).First(&existingUser).Error + err := DB.Where("username = ?", config.AppConfig.Admin.Username).First(&existingUser).Error if err == nil { // Admin user already exists, don't recreate - log.Printf("Admin user already exists: %s", config.AppConfig.Admin.Email) + log.Printf("Admin user already exists: %s", config.AppConfig.Admin.Username) return } @@ -60,9 +60,8 @@ func createDefaultAdminUser() { // Create admin user adminUser := models.User{ - Username: "admin", - Email: config.AppConfig.Admin.Email, - Password: string(hashedPassword), + Username: "admin", + HashedPassword: string(hashedPassword), } if err := DB.Create(&adminUser).Error; err != nil { @@ -70,5 +69,5 @@ func createDefaultAdminUser() { return } - log.Printf("Default admin user created with email: %s", config.AppConfig.Admin.Email) + log.Printf("Default admin user created with username: %s", config.AppConfig.Admin.Username) } diff --git a/src/models/user.go b/src/models/user.go index 344ddec..7afdec0 100644 --- a/src/models/user.go +++ b/src/models/user.go @@ -3,15 +3,15 @@ package models import ( "time" + "github.com/google/uuid" "gorm.io/gorm" ) type User struct { - ID uint `json:"id" gorm:"primaryKey"` - Username string `json:"username" gorm:"unique;not null"` - Email string `json:"email" gorm:"unique;not null"` - Password string `json:"-" gorm:"not null"` // Don't include in JSON responses - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` -} \ No newline at end of file + Uuid uuid.UUID `json:"uuid" gorm:"type:uuid;primaryKey"` + Username string `json:"username" gorm:"unique;not null"` + HashedPassword string `json:"-" gorm:"column:password;not null"` // Don't include in JSON responses + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` +}