-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtextSummaryHandler.go
84 lines (62 loc) · 1.66 KB
/
textSummaryHandler.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"log"
"net/http"
"strconv"
"github.com/gorilla/mux"
"github.com/thewhitetulip/Tasks/sessions"
"github.com/toferc/rq_web/database"
"github.com/toferc/rq_web/models"
)
// TextSummaryHandler renders a character in a Web page
func TextSummaryHandler(w http.ResponseWriter, req *http.Request) {
session, err := sessions.Store.Get(req, "session")
if err != nil {
log.Println("error identifying session")
// in case of error
}
// Prep for user authentication
sessionMap := getUserSessionValues(session)
username := sessionMap["username"]
loggedIn := sessionMap["loggedin"]
isAdmin := sessionMap["isAdmin"]
session.Save(req, w)
vars := mux.Vars(req)
pk := vars["id"]
if len(pk) == 0 {
http.Redirect(w, req, "/", http.StatusSeeOther)
}
id, err := strconv.Atoi(pk)
if err != nil {
http.Redirect(w, req, "/", http.StatusSeeOther)
}
cm, err := database.PKLoadCharacterModel(db, int64(id))
if err != nil {
fmt.Println("Unable to load CharacterModel")
http.Redirect(w, req, "/notfound", http.StatusSeeOther)
return
}
stringArray := []string{}
stringArray = append(stringArray, cm.Character.String())
stringArray = append(stringArray, cm.Character.StatBlock())
IsAuthor := false
if username == cm.Author.UserName {
IsAuthor = true
}
if cm.Image == nil {
cm.Image = new(models.Image)
cm.Image.Path = DefaultCharacterPortrait
}
//c.DetermineSkillCategoryValues()
wc := WebChar{
CharacterModel: cm,
IsAuthor: IsAuthor,
StringArray: stringArray,
IsLoggedIn: loggedIn,
SessionUser: username,
IsAdmin: isAdmin,
}
// Render page
Render(w, "templates/text_summary.html", wc)
}