minor renaming

This commit is contained in:
Umputun
2018-03-12 03:24:09 -05:00
parent 3d581d388e
commit 42b1577a1f
3 changed files with 7 additions and 13 deletions
+1 -1
View File
@@ -134,7 +134,7 @@ func (s *Rest) createCommentCtrl(w http.ResponseWriter, r *http.Request) {
return
}
comment.Init()
comment.Prepare() // clean all fields user not suppoed to set
comment.User = user
comment.User.IP = strings.Split(r.RemoteAddr, ":")[0]
comment.Text = string(blackfriday.Run([]byte(comment.Text), blackfriday.WithNoExtensions())) // render markdown
+3 -12
View File
@@ -58,8 +58,9 @@ type BlockedUser struct {
Timestamp time.Time `json:"time"`
}
// Init comment skeleton
func (c *Comment) Init() {
// Prepare comment received from untrusted source by clearing all autogen fields and
// reset everyting users not supposed to provide
func (c *Comment) Prepare() {
c.ID = "" // don't allow user to define ID, force auto-gen
c.Timestamp = time.Time{} // reset time, force auto-gen
c.Votes = make(map[string]bool)
@@ -95,13 +96,3 @@ type NotifUser struct {
ID string `json:"id"`
Destination string `json:"destination"`
}
// NotifScope defines "enum" of notification scopes
type NotifScope int
// All NotifScope values
const (
ScopeSite NotifScope = 1
ScopePost NotifScope = 2
ScopeReply NotifScope = 3
)
+3
View File
@@ -30,6 +30,9 @@ func (s *Service) Vote(locator Locator, commentID string, userID string, val boo
return comment, err
}
if comment.Votes == nil {
comment.Votes = make(map[string]bool)
}
v, voted := comment.Votes[userID]
if voted && v == val {