dev mode integrated with rest
This commit is contained in:
+12
-8
@@ -93,8 +93,19 @@ func (s *Server) createCommentCtrl(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
user, err := GetUserInfo(r)
|
||||
if err != nil {
|
||||
httpError(w, r, http.StatusUnauthorized, err, "can't get user info")
|
||||
return
|
||||
}
|
||||
|
||||
comment.User.IP = strings.Split(r.RemoteAddr, ":")[0]
|
||||
comment.User.Name = template.HTMLEscapeString(comment.User.Name)
|
||||
comment.User.ID = template.HTMLEscapeString(user.ID)
|
||||
comment.User.Name = template.HTMLEscapeString(user.Name)
|
||||
comment.User.Picture = template.HTMLEscapeString(user.Picture)
|
||||
comment.User.Profile = template.HTMLEscapeString(user.Profile)
|
||||
comment.User.Admin = user.Admin
|
||||
|
||||
comment.Text = template.HTMLEscapeString(comment.Text)
|
||||
|
||||
log.Printf("[INFO] create comment %+v", comment)
|
||||
@@ -156,13 +167,6 @@ func (s *Server) getLastComments(w http.ResponseWriter, r *http.Request) {
|
||||
max = 0
|
||||
}
|
||||
|
||||
uinfoData, err := GetUserInfo(r)
|
||||
if err != nil {
|
||||
http.Error(w, "login required", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
log.Printf("[DEBUG] user: %+v", uinfoData)
|
||||
|
||||
comments, err := s.Store.Last(store.Locator{}, max)
|
||||
if err != nil {
|
||||
log.Printf("[WARN] can't get last comments, %s", err)
|
||||
|
||||
+4
-4
@@ -10,13 +10,13 @@ type Comment struct {
|
||||
User User `json:"user"`
|
||||
Locator Locator `json:"locator"`
|
||||
Score int `json:"score"`
|
||||
Votes map[string]bool `json:"votes"`
|
||||
Timestamp time.Time `json:"time"`
|
||||
Votes map[string]bool `json:"votes,omitempty"`
|
||||
Timestamp time.Time `json:"time,omitempty"`
|
||||
}
|
||||
|
||||
// Locator keeps site and url of the post
|
||||
type Locator struct {
|
||||
SiteID string `json:"site"`
|
||||
SiteID string `json:"site,omitempty"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ type User struct {
|
||||
ID string `json:"id"`
|
||||
Picture string `json:"picture"`
|
||||
Profile string `json:"profile"`
|
||||
Admin bool `json:"admin"`
|
||||
Admin bool `json:"admin,omitempty"`
|
||||
IP string `json:"-"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user