-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaboutHandler.go
49 lines (37 loc) · 863 Bytes
/
aboutHandler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"log"
"net/http"
"github.com/thewhitetulip/Tasks/sessions"
"github.com/toferc/rq_web/models"
)
// AboutHandler renders a character in a Web page
func AboutHandler(w http.ResponseWriter, req *http.Request) {
// Get session values or redirect to Login
session, err := sessions.Store.Get(req, "session")
if err != nil {
log.Println("error identifying session")
http.Redirect(w, req, "/login/", http.StatusFound)
return
// in case of error
}
// Prep for user authentication
um := &models.User{}
username := ""
// Get session User
u := session.Values["username"]
// Type assertation
if user, ok := u.(string); !ok {
um.UserName = ""
} else {
fmt.Println(user)
username = user
}
fmt.Println(um)
wc := WebChar{
SessionUser: username,
}
// Render page
Render(w, "templates/about.html", wc)
}