From 40b26c2e1b6957ce1a61bf258772af80d6176c03 Mon Sep 17 00:00:00 2001 From: Stephanie Gredell Date: Wed, 16 Jul 2025 13:10:35 -0700 Subject: [PATCH] displaying username on welcome page, creating git ignore --- .gitignore | 6 ++++++ handlers/welcome.go | 22 +++++++++++++++++++++- templates/welcome.html | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..40cac82 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +tmp/ +.env +server.key +server.crt +server.rsa.key +server.rsa.crt diff --git a/handlers/welcome.go b/handlers/welcome.go index 9b728a0..400c4c6 100644 --- a/handlers/welcome.go +++ b/handlers/welcome.go @@ -1,11 +1,31 @@ package handlers import ( + "fmt" "net/http" + + "github.com/markbates/goth/gothic" ) +type PageData struct { + Username string +} + func (h *Handler) Welcome(w http.ResponseWriter, r *http.Request) { - err := h.Template.ExecuteTemplate(w, "welcome.html", nil) + session, err := gothic.Store.Get(r, "user-session") + if err != nil { + http.Error(w, "Error retrieving session for welcome page", http.StatusInternalServerError) + } + username, ok := session.Values["user_name"].(string) + if !ok { + http.Error(w, "Not authenticated", http.StatusUnauthorized) + return + } + + fmt.Printf("username: %s", username) + err = h.Template.ExecuteTemplate(w, "welcome.html", &PageData{ + Username: username, + }) if err != nil { http.Error(w, "Template rendering error", http.StatusInternalServerError) } diff --git a/templates/welcome.html b/templates/welcome.html index f68c5ee..9e87fc9 100644 --- a/templates/welcome.html +++ b/templates/welcome.html @@ -13,7 +13,7 @@
-

Host and Participate in Amazing Hackathons

+

Welcome {{ .Username }}!

A platform for developers to showcase their skills, collaborate, and win prizes.

Join a hackathon today!