From 368a462bc744d8e9084eacfaddeb9afcaf7f7133 Mon Sep 17 00:00:00 2001 From: Samuel Johnson Date: Mon, 24 Nov 2025 13:53:18 -0500 Subject: Add session management --- cmd/parser/main.go | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) (limited to 'cmd/parser/main.go') diff --git a/cmd/parser/main.go b/cmd/parser/main.go index 6d3c3c4..3d0b132 100644 --- a/cmd/parser/main.go +++ b/cmd/parser/main.go @@ -16,7 +16,7 @@ import ( "github.com/yuin/goldmark/extension" "github.com/yuin/goldmark/parser" "github.com/yuin/goldmark/renderer/html" - "golang.org/x/crypto/bcrypt" + "paterissa.net/mblog/internal" _ "github.com/jackc/pgx/v5/stdlib" ) @@ -121,40 +121,7 @@ func main() { } defer db.Close() - _, table_check := db.Query("SELECT * FROM posts;") - if table_check != nil { - _, err = db.Exec("CREATE TABLE posts (id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, content TEXT NOT NULL);") - if err != nil { - fmt.Fprintf(os.Stderr, "Unable to create posts table: %v\n", err) - os.Exit(1) - } - } - - webmaster := os.Getenv("webmaster") - passOne := os.Getenv("blog_pass1") - passTwo := os.Getenv("blog_pass2") - - _, table_check = db.Query("SELECT * FROM logins;") - if table_check != nil { - _, err = db.Exec("CREATE TABLE logins (id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, time DATE DEFAULT CURRENT_DATE, pass_one TEXT NOT NULL, pass_two TEXT NOT NULL);") - if err != nil { - fmt.Fprintf(os.Stderr, "Unable to create logins table: %v\n", err) - os.Exit(1) - } - - hashOne, errHashOne := bcrypt.GenerateFromPassword([]byte(passOne), 12) - hashTwo, errHashTwo := bcrypt.GenerateFromPassword([]byte(passTwo), 12) - if errHashOne != nil || errHashTwo != nil { - fmt.Fprintf(os.Stderr, "Failed to hash password") - os.Exit(1) - } - - _, err = db.Exec(fmt.Sprintf("INSERT INTO logins (name, pass_one, pass_two) VALUES ('%s', '%s', '%s');", webmaster, hashOne, hashTwo)) - if err != nil { - fmt.Fprintf(os.Stderr, "Unable to add webmaster to logins table: %v\n", err) - os.Exit(1) - } - } + internal.Migrate(db, os.Getenv("webmaster"), os.Getenv("blog_pass1"), os.Getenv("blog_pass2")) router := http.NewServeMux() router.HandleFunc("/", mdServe) -- cgit v1.2.3