redirect to profile on root, login if logged out, create account if no accounts. move pfp location

This commit is contained in:
2026-02-12 23:43:47 -08:00
parent 1478410d0c
commit 332460b90d
3 changed files with 29 additions and 1 deletions

View File

@@ -95,7 +95,7 @@ func CreateUsersTable() error {
username TEXT NOT NULL UNIQUE,
password TEXT NOT NULL,
bio TEXT DEFAULT 'This profile has no bio.',
pfp TEXT DEFAULT '/files/assets/default.png',
pfp TEXT DEFAULT '/files/assets/pfps/default.png',
allow_duplicate_edits BOOLEAN DEFAULT FALSE,
pk SERIAL PRIMARY KEY
);`)

View File

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

@@ -681,11 +681,39 @@ func importSpotifyProgressHandler(w http.ResponseWriter, r *http.Request) {
}
}
func hasUsers(ctx context.Context) bool {
var count int
err := db.Pool.QueryRow(ctx, "SELECT COUNT(*) FROM users;").Scan(&count)
if err != nil {
fmt.Fprintf(os.Stderr, "Error checking for users: %v\n", err)
return false
}
return count > 0
}
func rootHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if !hasUsers(r.Context()) {
http.Redirect(w, r, "/createaccount", http.StatusSeeOther)
return
}
username := getLoggedInUsername(r)
if username == "" {
http.Redirect(w, r, "/login", http.StatusSeeOther)
return
}
http.Redirect(w, r, "/profile/"+username, http.StatusSeeOther)
}
}
func Start() {
addr := ":1234"
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Handle("/files/*", http.StripPrefix("/files", http.FileServer(http.Dir("./static"))))
r.Get("/", rootHandler())
r.Get("/login", loginPageHandler())
r.Get("/createaccount", createAccountPageHandler())
r.Get("/profile/{username}", profilePageHandler())