Browse Source

displaying username on welcome page, creating git ignore

main
Stephanie Gredell 6 months ago
parent
commit
40b26c2e1b
  1. 6
      .gitignore
  2. 22
      handlers/welcome.go
  3. 2
      templates/welcome.html

6
.gitignore vendored

@ -0,0 +1,6 @@
tmp/
.env
server.key
server.crt
server.rsa.key
server.rsa.crt

22
handlers/welcome.go

@ -1,11 +1,31 @@
package handlers package handlers
import ( import (
"fmt"
"net/http" "net/http"
"github.com/markbates/goth/gothic"
) )
type PageData struct {
Username string
}
func (h *Handler) Welcome(w http.ResponseWriter, r *http.Request) { 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 { if err != nil {
http.Error(w, "Template rendering error", http.StatusInternalServerError) http.Error(w, "Template rendering error", http.StatusInternalServerError)
} }

2
templates/welcome.html

@ -13,7 +13,7 @@
<section id="home" class="hero"> <section id="home" class="hero">
<div class="container"> <div class="container">
<h1>Host and Participate in Amazing Hackathons</h1> <h1>Welcome {{ .Username }}!</h1>
<p>A platform for developers to showcase their skills, collaborate, and win prizes.</p> <p>A platform for developers to showcase their skills, collaborate, and win prizes.</p>
<a href="#submit" class="btn">Join a hackathon today!</a> <a href="#submit" class="btn">Join a hackathon today!</a>
</div> </div>

Loading…
Cancel
Save