-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
47 lines (37 loc) · 1.05 KB
/
user.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
package main
import (
"encoding/json"
"log"
"net/http"
"github.com/goincremental/negroni-sessions"
"github.com/unrolled/render"
)
func userIndex(w http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
session := sessions.GetSession(req)
user := session.Get("user").([]byte)
renderOpts.Layout = "admin"
rnd = render.New(renderOpts)
response := NewResponse()
response.Title = "Index"
var u User
if err := json.Unmarshal(user, &u); err != nil {
log.Println(err)
}
response.Data = u
rnd.HTML(w, http.StatusOK, "user/index", response)
}
func userUpdate(w http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
}
func userDelete(w http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
}
func userView(w http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
}
func userMiddleware(w http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
session := sessions.GetSession(req)
id := session.Get("user_id")
if id == nil {
http.Redirect(w, req, "/site/unauthorized", 301)
} else {
next(w, req)
}
}