replace email with username

This commit is contained in:
2026-07-02 22:40:23 +02:00
parent 532f3f5faa
commit f56196e115
5 changed files with 18 additions and 19 deletions
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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
```
```
+2 -2
View File
@@ -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")
+5 -6
View File
@@ -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)
}
+8 -8
View File
@@ -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"`
}
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"`
}