Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Merge remote-tracking branch 'origin/master'

Cette révision appartient à :
Jeff Becker 2017-05-11 06:50:53 -04:00
révision 7d98ebd7fe
6 fichiers modifiés avec 30 ajouts et 31 suppressions

Voir le fichier

@ -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),

Voir le fichier

@ -378,3 +378,8 @@ footer {
top: -0.5rem;
float: right;
}
.comment-date {
font-size: smaller;
width: auto; /* Undo bootstrap's fixed width */
}

Voir le fichier

@ -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 {

Voir le fichier

@ -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 {

Voir le fichier

@ -34,7 +34,7 @@
{{end}}
</div>
</div>
{{ if not (HasAdmin .)}}
{{ if not (HasAdmin $.User)}}
<div class="form-group">
<label class="col-md-3 control-label">{{ T "current_password"}}:</label>
<div class="col-md-8">
@ -63,7 +63,7 @@
{{end}}
</div>
</div>
{{ if HasAdmin .}}
{{ if HasAdmin $.User}}
<h3>{{ T "moderation"}}</h3>
<div class="form-group">
<label class="col-md-3 control-label">{{ T "username"}}:</label>
@ -82,7 +82,7 @@
<option value="-1" {{ if eq .Status -1 }}selected{{end}}>{{ T "banned"}}</option>
<option value="0" {{ if eq .Status 0 }}selected{{end}}>{{ T "member"}} ({{ T "default" }})</option>
<option value="1" {{ if eq .Status 1 }}selected{{end}}>{{ T "trusted_member"}} </option>
<option value="2" {{ if eq .Status 2 }}selected{{end}}>{{ T "moderator"}} </option>
<!-- <option value="2" {{ if eq .Status 2 }}selected{{end}}>{{ T "moderator"}} </option> -->
</select>
</div>
{{ range (index $.FormErrors "status")}}

Voir le fichier

@ -93,8 +93,11 @@
<a href="{{$.URL.Parse (printf "/user/%d/-" .UserID ) }}">{{.Username}}</a>
{{end}}
</div>
<div class="col-md-2">
{{.Date.Year}}/{{.Date.Month}}/{{.Date.Day}}
<div class="col-md-1 date-short comment-date">
{{printf "%d-%02d-%02d %02d:%02d" .Date.Year .Date.Month .Date.Day .Date.Hour .Date.Minute }}
{{/* output: "2017-05-01 15:30"
Went with "Year-Month-Day" because it's the most unambiguous.
If you want it to be determined by where you're from, be my guest. */}}
</div>
<div class="col-md-8">
{{.Content}}