Convert backend from submodule to regular directory
Some checks failed
Deploy to NAS / deploy (push) Failing after 4s
Some checks failed
Deploy to NAS / deploy (push) Failing after 4s
Remove submodule tracking; backend is now a plain directory in the repo. Also update deploy workflow: remove --recurse-submodules. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
55
backend/cmd/createuser/main.go
Normal file
55
backend/cmd/createuser/main.go
Normal file
@@ -0,0 +1,55 @@
|
||||
// cmd/createuser creates a new user in the database.
|
||||
// Usage: DATABASE_URL=... go run ./cmd/createuser <username> <password>
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
"github.com/jacek/pamietnik/backend/internal/auth"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 3 {
|
||||
fmt.Fprintln(os.Stderr, "usage: createuser <username> <password>")
|
||||
os.Exit(1)
|
||||
}
|
||||
username := os.Args[1]
|
||||
password := os.Args[2]
|
||||
|
||||
if len(password) < 8 {
|
||||
fmt.Fprintln(os.Stderr, "password must be at least 8 characters")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
dsn := os.Getenv("DATABASE_URL")
|
||||
if dsn == "" {
|
||||
dsn = "postgres://pamietnik:pamietnik@localhost:5432/pamietnik?sslmode=disable"
|
||||
}
|
||||
|
||||
conn, err := pgx.Connect(context.Background(), dsn)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "db error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer conn.Close(context.Background())
|
||||
|
||||
hash, err := auth.HashPassword(password)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "hash error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
_, err = conn.Exec(context.Background(),
|
||||
`INSERT INTO users (username, password_hash) VALUES ($1, $2)`,
|
||||
username, hash,
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "insert error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("user '%s' created\n", username)
|
||||
}
|
||||
Reference in New Issue
Block a user