diff --git a/model/torrent.go b/model/torrent.go index d3fca060..94cc27cd 100644 --- a/model/torrent.go +++ b/model/torrent.go @@ -85,7 +85,7 @@ type CommentJSON struct { Username string `json:"username"` UserID int `json:"user_id"` Content template.HTML `json:"content"` - Date time.Time `json:"date"` + Date string `json:"date"` } type TorrentJSON struct { @@ -117,10 +117,10 @@ func (t *Torrent) ToJSON() TorrentJSON { magnet := util.InfoHashToMagnet(strings.TrimSpace(t.Hash), t.Name, config.Trackers...) commentsJSON := make([]CommentJSON, 0, len(t.OldComments)+len(t.Comments)) for _, c := range t.OldComments { - commentsJSON = append(commentsJSON, CommentJSON{Username: c.Username, UserID: -1, Content: template.HTML(c.Content), Date: c.Date}) + commentsJSON = append(commentsJSON, CommentJSON{Username: c.Username, UserID: -1, Content: template.HTML(c.Content), Date: c.Date.Format(time.RFC3339)}) } for _, c := range t.Comments { - commentsJSON = append(commentsJSON, CommentJSON{Username: c.User.Username, UserID: int(c.User.ID), Content: util.MarkdownToHTML(c.Content), Date: c.CreatedAt}) + commentsJSON = append(commentsJSON, CommentJSON{Username: c.User.Username, UserID: int(c.User.ID), Content: util.MarkdownToHTML(c.Content), Date: c.CreatedAt.Format(time.RFC3339)}) } uploader := "" if t.Uploader != nil { @@ -130,7 +130,8 @@ func (t *Torrent) ToJSON() TorrentJSON { if t.ID <= config.LastOldTorrentID && len(config.TorrentCacheLink) > 0 { torrentlink = fmt.Sprintf(config.TorrentCacheLink, t.Hash) } else if t.ID > config.LastOldTorrentID && len(config.TorrentStorageLink) > 0 { - torrentlink = fmt.Sprintf(config.TorrentStorageLink, t.Hash) // TODO: Fix as part of configuration changes + // TODO: Fix as part of configuration changes (fix what?) + torrentlink = fmt.Sprintf(config.TorrentStorageLink, t.Hash) } res := TorrentJSON{ ID: strconv.FormatUint(uint64(t.ID), 10), diff --git a/public/css/style.css b/public/css/style.css index e66e1a65..db605fde 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -377,4 +377,9 @@ footer { position: relative; top: -0.5rem; float: right; -} \ No newline at end of file +} + +.comment-date { + font-size: smaller; + width: auto; /* Undo bootstrap's fixed width */ +} diff --git a/router/userHandler.go b/router/userHandler.go index e90ca472..e534edb4 100755 --- a/router/userHandler.go +++ b/router/userHandler.go @@ -157,6 +157,11 @@ func UserProfileFormHandler(w http.ResponseWriter, r *http.Request) { modelHelper.BindValueForm(&b, r) if !userPermission.HasAdmin(currentUser) { b.Username = currentUser.Username + b.Status = currentUser.Status + } else { + if b.Status == 2 { + err["errors"] = append(err["errors"], "Elevating status to moderator is prohibited") + } } err = modelHelper.ValidateForm(&b, err) if len(err) == 0 { diff --git a/service/user/cookieHelper.go b/service/user/cookieHelper.go index cd32b7b6..b28e5a98 100644 --- a/service/user/cookieHelper.go +++ b/service/user/cookieHelper.go @@ -16,24 +16,6 @@ var cookieHandler = securecookie.New( securecookie.GenerateRandomKey(64), securecookie.GenerateRandomKey(32)) -// TODO: Figure out what this is about before I delete it -// // UserName get username from a cookie. -// func UserName(c *gin.Context) (string, error) { -// var userName string -// request := c.Request -// cookie, err := request.Cookie("session") -// if err != nil { -// return userName, err -// } -// cookieValue := make(map[string]string) -// err = cookieHandler.Decode("session", cookie.Value, &cookieValue) -// if err != nil { -// return userName, err -// } -// userName = cookieValue["name"] -// return userName, nil -// } - func Token(r *http.Request) (string, error) { var token string cookie, err := r.Cookie("session") @@ -90,17 +72,20 @@ func SetCookieHandler(w http.ResponseWriter, email string, pass string) (int, er if isValidEmail { log.Debug("User entered valid email.") if db.ORM.Where("email = ?", email).First(&user).RecordNotFound() { - return http.StatusNotFound, errors.New("user not found") + return http.StatusNotFound, errors.New("User not found") } } else { log.Debug("User entered username.") if db.ORM.Where("username = ?", email).First(&user).RecordNotFound() { - return http.StatusNotFound, errors.New("user not found") + return http.StatusNotFound, errors.New("User not found") } } err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(pass)) if err != nil { - return http.StatusUnauthorized, errors.New("password incorrect") + return http.StatusUnauthorized, errors.New("Password incorrect") + } + if user.Status == -1 { + return http.StatusUnauthorized, errors.New("Account banned") } status, err := SetCookie(w, user.Token) if err != nil { diff --git a/templates/_profile_edit.html b/templates/_profile_edit.html index c5198f00..d549fd80 100644 --- a/templates/_profile_edit.html +++ b/templates/_profile_edit.html @@ -34,7 +34,7 @@ {{end}} - {{ if not (HasAdmin .)}} + {{ if not (HasAdmin $.User)}}
@@ -63,7 +63,7 @@ {{end}}
- {{ if HasAdmin .}} + {{ if HasAdmin $.User}}

{{ T "moderation"}}

@@ -82,7 +82,7 @@ - +
{{ range (index $.FormErrors "status")}} diff --git a/templates/view.html b/templates/view.html index 6de44deb..be3cc185 100644 --- a/templates/view.html +++ b/templates/view.html @@ -93,8 +93,8 @@ {{.Username}} {{end}} -
- {{.Date.Year}}/{{.Date.Month}}/{{.Date.Day}} +
+ {{.Date}}
{{.Content}}