-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.go
59 lines (45 loc) · 1.22 KB
/
search.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
package main
import (
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/thewhitetulip/Tasks/sessions"
"github.com/toferc/rq_web/database"
"github.com/toferc/rq_web/models"
)
// CharacterSearchHandler renders the basic character roster page
func CharacterSearchHandler(w http.ResponseWriter, req *http.Request) {
session, err := sessions.Store.Get(req, "session")
if err != nil {
log.Println("error identifying session")
Render(w, "templates/login.html", nil)
return
// in case of error
}
// Prep for user authentication
sessionMap := getUserSessionValues(session)
username := sessionMap["username"]
loggedIn := sessionMap["loggedin"]
isAdmin := sessionMap["isAdmin"]
values := mux.Vars(req)
query := values["query"]
characters, err := database.SearchCharacterModels(db, query)
if err != nil {
log.Println(err)
}
for _, cm := range characters {
if cm.Image == nil {
cm.Image = new(models.Image)
cm.Image.Path = DefaultCharacterPortrait
}
}
wc := WebChar{
SessionUser: username,
IsLoggedIn: loggedIn,
IsAdmin: isAdmin,
CharacterModels: characters,
Query: query,
Index: "true",
}
Render(w, "templates/character_search_results.html", wc)
}