aboutsummaryrefslogtreecommitdiff
path: root/cmd/parser/main.go
diff options
context:
space:
mode:
authorSamuel Johnson <[email protected]>2025-11-24 13:53:18 -0500
committerSamuel Johnson <[email protected]>2025-11-24 13:53:18 -0500
commit368a462bc744d8e9084eacfaddeb9afcaf7f7133 (patch)
treec6e8f665d6cb9713b9226b10c4a341e60b8e91c2 /cmd/parser/main.go
parent4d4419f51557bef6b64dca8635ed61616d262a9b (diff)
Add session management
Diffstat (limited to 'cmd/parser/main.go')
-rw-r--r--cmd/parser/main.go37
1 files changed, 2 insertions, 35 deletions
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)