replace email with username
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@ JWT_SECRET=your-super-secret-jwt-key-here
|
|||||||
SYNC_INTERVAL_MINUTES=1
|
SYNC_INTERVAL_MINUTES=1
|
||||||
|
|
||||||
# Default Admin User Configuration
|
# Default Admin User Configuration
|
||||||
ADMIN_EMAIL=admin@admin.com
|
ADMIN_USERNAME=admin
|
||||||
ADMIN_PASSWORD=sheetless
|
ADMIN_PASSWORD=sheetless
|
||||||
|
|
||||||
# Directories containing permanent data
|
# Directories containing permanent data
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ go build -o sheetless-server main.go
|
|||||||
```bash
|
```bash
|
||||||
curl -X POST http://localhost:8080/auth/register \
|
curl -X POST http://localhost:8080/auth/register \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"username":"testuser","email":"test@example.com","password":"password123"}'
|
-d '{"username":"testuser","password":"password123"}'
|
||||||
```
|
```
|
||||||
|
|
||||||
### Login:
|
### Login:
|
||||||
@@ -71,4 +71,4 @@ curl -X POST http://localhost:8080/api/sheets/upload \
|
|||||||
### List sheets:
|
### List sheets:
|
||||||
```bash
|
```bash
|
||||||
curl -H "Authorization: Bearer TOKEN" http://localhost:8080/api/sheets
|
curl -H "Authorization: Bearer TOKEN" http://localhost:8080/api/sheets
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ type Config struct {
|
|||||||
Interval time.Duration
|
Interval time.Duration
|
||||||
}
|
}
|
||||||
Admin struct {
|
Admin struct {
|
||||||
Email string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
}
|
}
|
||||||
SheetsDirectory string
|
SheetsDirectory string
|
||||||
@@ -44,7 +44,7 @@ func Load() {
|
|||||||
cfg.Sync.Interval = time.Duration(syncMinutes) * time.Minute
|
cfg.Sync.Interval = time.Duration(syncMinutes) * time.Minute
|
||||||
|
|
||||||
// Admin configuration
|
// 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.Admin.Password = getEnv("ADMIN_PASSWORD", "sheetless")
|
||||||
|
|
||||||
cfg.SheetsDirectory = getEnv("SHEETS_DIRECTORY", "./sheets_directory")
|
cfg.SheetsDirectory = getEnv("SHEETS_DIRECTORY", "./sheets_directory")
|
||||||
|
|||||||
@@ -44,10 +44,10 @@ func InitDatabase() {
|
|||||||
func createDefaultAdminUser() {
|
func createDefaultAdminUser() {
|
||||||
// Check if admin user already exists
|
// Check if admin user already exists
|
||||||
var existingUser models.User
|
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 {
|
if err == nil {
|
||||||
// Admin user already exists, don't recreate
|
// 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,9 +60,8 @@ func createDefaultAdminUser() {
|
|||||||
|
|
||||||
// Create admin user
|
// Create admin user
|
||||||
adminUser := models.User{
|
adminUser := models.User{
|
||||||
Username: "admin",
|
Username: "admin",
|
||||||
Email: config.AppConfig.Admin.Email,
|
HashedPassword: string(hashedPassword),
|
||||||
Password: string(hashedPassword),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := DB.Create(&adminUser).Error; err != nil {
|
if err := DB.Create(&adminUser).Error; err != nil {
|
||||||
@@ -70,5 +69,5 @@ func createDefaultAdminUser() {
|
|||||||
return
|
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
@@ -3,15 +3,15 @@ package models
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID uint `json:"id" gorm:"primaryKey"`
|
Uuid uuid.UUID `json:"uuid" gorm:"type:uuid;primaryKey"`
|
||||||
Username string `json:"username" gorm:"unique;not null"`
|
Username string `json:"username" gorm:"unique;not null"`
|
||||||
Email string `json:"email" gorm:"unique;not null"`
|
HashedPassword string `json:"-" gorm:"column:password;not null"` // Don't include in JSON responses
|
||||||
Password string `json:"-" gorm:"not null"` // Don't include in JSON responses
|
CreatedAt time.Time `json:"created_at"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
|
||||||
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
|
}
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user