2017-09-13 15:40:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"html"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
"path/filepath"
|
2017-09-13 15:40:49 +00:00
|
|
|
"regexp"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
2017-11-11 04:06:16 +00:00
|
|
|
|
|
|
|
"./common"
|
2018-02-19 04:26:01 +00:00
|
|
|
"./common/counters"
|
2017-09-13 15:40:49 +00:00
|
|
|
)
|
|
|
|
|
2017-10-12 03:24:14 +00:00
|
|
|
// TODO: Refactor this
|
2018-01-14 12:03:20 +00:00
|
|
|
func routeLikeTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, stid string) common.RouteError {
|
2018-03-31 05:25:27 +00:00
|
|
|
isJs := (r.PostFormValue("isJs") == "1")
|
2018-01-14 12:03:20 +00:00
|
|
|
tid, err := strconv.Atoi(stid)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.PreErrorJSQ("Topic IDs can only ever be numbers.", w, r, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
topic, err := common.Topics.Get(tid)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err == ErrNoRows {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.PreErrorJSQ("The requested topic doesn't exist.", w, r, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
} else if err != nil {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.InternalErrorJSQ(err, w, r, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Add hooks to make use of headerLite
|
2017-11-11 04:06:16 +00:00
|
|
|
_, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
|
2017-10-30 09:57:08 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
if !user.Perms.ViewTopic || !user.Perms.LikeItem {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.NoPermissionsJSQ(w, r, user, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
if topic.CreatedBy == user.ID {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.LocalErrorJSQ("You can't like your own topics", w, r, user, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
_, err = common.Users.Get(topic.CreatedBy)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil && err == ErrNoRows {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.LocalErrorJSQ("The target user doesn't exist", w, r, user, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
} else if err != nil {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.InternalErrorJSQ(err, w, r, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
score := 1
|
2017-11-08 07:28:33 +00:00
|
|
|
err = topic.Like(score, user.ID)
|
2018-03-31 05:25:27 +00:00
|
|
|
//log.Print("likeErr: ", err)
|
2017-11-11 04:06:16 +00:00
|
|
|
if err == common.ErrAlreadyLiked {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.LocalErrorJSQ("You already liked this", w, r, user, isJs)
|
2017-11-08 07:28:33 +00:00
|
|
|
} else if err != nil {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.InternalErrorJSQ(err, w, r, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 03:59:47 +00:00
|
|
|
err = common.AddActivityAndNotifyTarget(user.ID, topic.CreatedBy, "like", "topic", tid)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.InternalErrorJSQ(err, w, r, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-31 05:25:27 +00:00
|
|
|
if !isJs {
|
|
|
|
http.Redirect(w, r, "/topic/"+strconv.Itoa(tid), http.StatusSeeOther)
|
|
|
|
} else {
|
|
|
|
_, _ = w.Write(successJSONBytes)
|
|
|
|
}
|
2017-10-30 09:57:08 +00:00
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2018-01-14 12:03:20 +00:00
|
|
|
func routeReplyLikeSubmit(w http.ResponseWriter, r *http.Request, user common.User, srid string) common.RouteError {
|
2018-03-31 05:25:27 +00:00
|
|
|
isJs := (r.PostFormValue("isJs") == "1")
|
|
|
|
|
2018-01-14 12:03:20 +00:00
|
|
|
rid, err := strconv.Atoi(srid)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.PreErrorJSQ("The provided Reply ID is not a valid number.", w, r, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
reply, err := common.Rstore.Get(rid)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err == ErrNoRows {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.PreErrorJSQ("You can't like something which doesn't exist!", w, r, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
} else if err != nil {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.InternalErrorJSQ(err, w, r, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var fid int
|
2017-11-05 09:55:34 +00:00
|
|
|
err = stmts.getTopicFID.QueryRow(reply.ParentID).Scan(&fid)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err == ErrNoRows {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.PreErrorJSQ("The parent topic doesn't exist.", w, r, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
} else if err != nil {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.InternalErrorJSQ(err, w, r, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Add hooks to make use of headerLite
|
2017-11-11 04:06:16 +00:00
|
|
|
_, ferr := common.SimpleForumUserCheck(w, r, &user, fid)
|
2017-10-30 09:57:08 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
if !user.Perms.ViewTopic || !user.Perms.LikeItem {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.NoPermissionsJSQ(w, r, user, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
if reply.CreatedBy == user.ID {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.LocalErrorJSQ("You can't like your own replies", w, r, user, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
_, err = common.Users.Get(reply.CreatedBy)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil && err != ErrNoRows {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.LocalErrorJSQ("The target user doesn't exist", w, r, user, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
} else if err != nil {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.InternalErrorJSQ(err, w, r, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 03:24:14 +00:00
|
|
|
err = reply.Like(user.ID)
|
2017-11-11 04:06:16 +00:00
|
|
|
if err == common.ErrAlreadyLiked {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.LocalErrorJSQ("You've already liked this!", w, r, user, isJs)
|
2017-10-12 03:24:14 +00:00
|
|
|
} else if err != nil {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.InternalErrorJSQ(err, w, r, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 03:59:47 +00:00
|
|
|
err = common.AddActivityAndNotifyTarget(user.ID, reply.CreatedBy, "like", "post", rid)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil {
|
2018-03-31 05:25:27 +00:00
|
|
|
return common.InternalErrorJSQ(err, w, r, isJs)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-31 05:25:27 +00:00
|
|
|
if !isJs {
|
|
|
|
http.Redirect(w, r, "/topic/"+strconv.Itoa(reply.ParentID), http.StatusSeeOther)
|
|
|
|
} else {
|
|
|
|
_, _ = w.Write(successJSONBytes)
|
|
|
|
}
|
2017-10-30 09:57:08 +00:00
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2018-01-14 14:27:10 +00:00
|
|
|
func routeProfileReplyCreateSubmit(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError {
|
2017-09-15 22:20:01 +00:00
|
|
|
if !user.Perms.ViewTopic || !user.Perms.CreateReply {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.NoPermissions(w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uid, err := strconv.Atoi(r.PostFormValue("uid"))
|
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("Invalid UID", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
2018-03-21 05:56:33 +00:00
|
|
|
|
2018-03-08 03:59:47 +00:00
|
|
|
profileOwner, err := common.Users.Get(uid)
|
|
|
|
if err == ErrNoRows {
|
2018-01-14 12:03:20 +00:00
|
|
|
return common.LocalError("The profile you're trying to post on doesn't exist.", w, r, user)
|
2018-03-08 03:59:47 +00:00
|
|
|
} else if err != nil {
|
2018-03-21 05:56:33 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2018-01-14 12:03:20 +00:00
|
|
|
}
|
2017-09-13 15:40:49 +00:00
|
|
|
|
2017-12-30 05:47:46 +00:00
|
|
|
content := common.PreparseMessage(r.PostFormValue("reply-content"))
|
|
|
|
// TODO: Fully parse the post and store it in the parsed column
|
2018-03-08 03:59:47 +00:00
|
|
|
_, err = common.Prstore.Create(profileOwner.ID, content, user.ID, user.LastIP)
|
|
|
|
if err != nil {
|
|
|
|
return common.InternalError(err, w, r)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = common.AddActivityAndNotifyTarget(user.ID, profileOwner.ID, "reply", "user", profileOwner.ID)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-19 04:26:01 +00:00
|
|
|
counters.PostCounter.Bump()
|
2017-09-13 15:40:49 +00:00
|
|
|
http.Redirect(w, r, "/user/"+strconv.Itoa(uid), http.StatusSeeOther)
|
2017-10-30 09:57:08 +00:00
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
func routeReportSubmit(w http.ResponseWriter, r *http.Request, user common.User, sitemID string) common.RouteError {
|
2017-09-13 15:40:49 +00:00
|
|
|
itemID, err := strconv.Atoi(sitemID)
|
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("Bad ID", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
itemType := r.FormValue("type")
|
|
|
|
|
|
|
|
var fid = 1
|
|
|
|
var title, content string
|
|
|
|
if itemType == "reply" {
|
2017-11-11 04:06:16 +00:00
|
|
|
reply, err := common.Rstore.Get(itemID)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err == ErrNoRows {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("We were unable to find the reported post", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
} else if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
topic, err := common.Topics.Get(reply.ParentID)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err == ErrNoRows {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("We weren't able to find the topic the reported post is supposed to be in", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
} else if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
title = "Reply: " + topic.Title
|
|
|
|
content = reply.Content + "\n\nOriginal Post: #rid-" + strconv.Itoa(itemID)
|
|
|
|
} else if itemType == "user-reply" {
|
2017-11-11 04:06:16 +00:00
|
|
|
userReply, err := common.Prstore.Get(itemID)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err == ErrNoRows {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("We weren't able to find the reported post", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
} else if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 09:55:34 +00:00
|
|
|
err = stmts.getUserName.QueryRow(userReply.ParentID).Scan(&title)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err == ErrNoRows {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("We weren't able to find the profile the reported post is supposed to be on", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
} else if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
title = "Profile: " + title
|
|
|
|
content = userReply.Content + "\n\nOriginal Post: @" + strconv.Itoa(userReply.ParentID)
|
|
|
|
} else if itemType == "topic" {
|
2017-11-05 09:55:34 +00:00
|
|
|
err = stmts.getTopicBasic.QueryRow(itemID).Scan(&title, &content)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err == ErrNoRows {
|
2018-02-19 04:26:01 +00:00
|
|
|
return common.NotFound(w, r, nil)
|
2017-09-13 15:40:49 +00:00
|
|
|
} else if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
title = "Topic: " + title
|
|
|
|
content = content + "\n\nOriginal Post: #tid-" + strconv.Itoa(itemID)
|
|
|
|
} else {
|
2018-02-15 13:15:27 +00:00
|
|
|
_, hasHook := common.RunVhookNeedHook("report_preassign", &itemID, &itemType)
|
|
|
|
if hasHook {
|
2017-10-30 09:57:08 +00:00
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
2018-02-15 13:15:27 +00:00
|
|
|
|
2017-09-13 15:40:49 +00:00
|
|
|
// Don't try to guess the type
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("Unknown type", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var count int
|
2017-11-08 07:28:33 +00:00
|
|
|
err = stmts.reportExists.QueryRow(itemType + "_" + strconv.Itoa(itemID)).Scan(&count)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil && err != ErrNoRows {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
if count != 0 {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("Someone has already reported this!", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
// TODO: Repost attachments in the reports forum, so that the mods can see them
|
2017-11-08 07:28:33 +00:00
|
|
|
// ? - Can we do this via the TopicStore? Should we do a ReportStore?
|
2017-11-11 04:06:16 +00:00
|
|
|
res, err := stmts.createReport.Exec(title, content, common.ParseMessage(content, 0, ""), user.ID, user.ID, itemType+"_"+strconv.Itoa(itemID))
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lastID, err := res.LastInsertId()
|
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 05:37:08 +00:00
|
|
|
err = common.Forums.AddTopic(int(lastID), user.ID, fid)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil && err != ErrNoRows {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
2018-02-19 04:26:01 +00:00
|
|
|
counters.PostCounter.Bump()
|
2017-09-13 15:40:49 +00:00
|
|
|
|
|
|
|
http.Redirect(w, r, "/topic/"+strconv.FormatInt(lastID, 10), http.StatusSeeOther)
|
2017-10-30 09:57:08 +00:00
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
func routeAccountEditCriticalSubmit(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError {
|
2018-05-11 06:53:31 +00:00
|
|
|
_, ferr := common.SimpleUserCheck(w, r, &user)
|
2017-10-30 09:57:08 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var realPassword, salt string
|
|
|
|
currentPassword := r.PostFormValue("account-current-password")
|
|
|
|
newPassword := r.PostFormValue("account-new-password")
|
|
|
|
confirmPassword := r.PostFormValue("account-confirm-password")
|
|
|
|
|
2017-11-10 03:33:11 +00:00
|
|
|
err := stmts.getPassword.QueryRow(user.ID).Scan(&realPassword, &salt)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err == ErrNoRows {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("Your account no longer exists.", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
} else if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
err = common.CheckPassword(realPassword, currentPassword, salt)
|
|
|
|
if err == common.ErrMismatchedHashAndPassword {
|
|
|
|
return common.LocalError("That's not the correct password.", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
} else if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
if newPassword != confirmPassword {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("The two passwords don't match.", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
2017-11-11 04:06:16 +00:00
|
|
|
common.SetPassword(user.ID, newPassword)
|
2017-09-13 15:40:49 +00:00
|
|
|
|
|
|
|
// Log the user out as a safety precaution
|
2017-11-11 04:06:16 +00:00
|
|
|
common.Auth.ForceLogout(user.ID)
|
2018-05-11 06:53:31 +00:00
|
|
|
http.Redirect(w, r, "/", http.StatusSeeOther)
|
2017-10-30 09:57:08 +00:00
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
func routeAccountEditAvatar(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError {
|
|
|
|
headerVars, ferr := common.UserCheck(w, r, &user)
|
2017-10-30 09:57:08 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
2017-11-05 09:55:34 +00:00
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
pi := common.Page{"Edit Avatar", user, headerVars, tList, nil}
|
2018-02-19 04:26:01 +00:00
|
|
|
if common.RunPreRenderHook("pre_render_account_own_edit_avatar", w, r, &user, &pi) {
|
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
2018-01-10 03:32:48 +00:00
|
|
|
err := common.Templates.ExecuteTemplate(w, "account_own_edit_avatar.html", pi)
|
2017-10-30 09:57:08 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-10-30 09:57:08 +00:00
|
|
|
}
|
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
func routeAccountEditAvatarSubmit(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError {
|
|
|
|
headerVars, ferr := common.UserCheck(w, r, &user)
|
2017-10-30 09:57:08 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
var filename, ext string
|
2017-09-13 15:40:49 +00:00
|
|
|
for _, fheaders := range r.MultipartForm.File {
|
|
|
|
for _, hdr := range fheaders {
|
|
|
|
infile, err := hdr.Open()
|
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("Upload failed", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
defer infile.Close()
|
|
|
|
|
|
|
|
// We don't want multiple files
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
// TODO: Check the length of r.MultipartForm.File and error rather than doing this x.x
|
2017-09-13 15:40:49 +00:00
|
|
|
if filename != "" {
|
|
|
|
if filename != hdr.Filename {
|
|
|
|
os.Remove("./uploads/avatar_" + strconv.Itoa(user.ID) + "." + ext)
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("You may only upload one avatar", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
filename = hdr.Filename
|
|
|
|
}
|
|
|
|
|
|
|
|
if ext == "" {
|
|
|
|
extarr := strings.Split(hdr.Filename, ".")
|
|
|
|
if len(extarr) < 2 {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("Bad file", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
ext = extarr[len(extarr)-1]
|
|
|
|
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
// TODO: Can we do this without a regex?
|
2017-09-13 15:40:49 +00:00
|
|
|
reg, err := regexp.Compile("[^A-Za-z0-9]+")
|
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("Bad file extension", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
ext = reg.ReplaceAllString(ext, "")
|
|
|
|
ext = strings.ToLower(ext)
|
|
|
|
}
|
|
|
|
|
|
|
|
outfile, err := os.Create("./uploads/avatar_" + strconv.Itoa(user.ID) + "." + ext)
|
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("Upload failed [File Creation Failed]", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
defer outfile.Close()
|
|
|
|
|
|
|
|
_, err = io.Copy(outfile, infile)
|
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("Upload failed [Copy Failed]", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-14 12:03:20 +00:00
|
|
|
err := user.ChangeAvatar("." + ext)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
user.Avatar = "/uploads/avatar_" + strconv.Itoa(user.ID) + "." + ext
|
2018-03-21 05:56:33 +00:00
|
|
|
headerVars.NoticeList = append(headerVars.NoticeList, common.GetNoticePhrase("account_avatar_updated"))
|
2017-12-30 05:47:46 +00:00
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
pi := common.Page{"Edit Avatar", user, headerVars, tList, nil}
|
2018-02-19 04:26:01 +00:00
|
|
|
if common.RunPreRenderHook("pre_render_account_own_edit_avatar", w, r, &user, &pi) {
|
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
2018-01-10 03:32:48 +00:00
|
|
|
err = common.Templates.ExecuteTemplate(w, "account_own_edit_avatar.html", pi)
|
2017-10-30 09:57:08 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-10-30 09:57:08 +00:00
|
|
|
}
|
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
func routeAccountEditUsername(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError {
|
|
|
|
headerVars, ferr := common.UserCheck(w, r, &user)
|
2017-10-30 09:57:08 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
2017-11-05 09:55:34 +00:00
|
|
|
|
2017-12-30 05:47:46 +00:00
|
|
|
pi := common.Page{"Edit Username", user, headerVars, tList, user.Name}
|
2018-02-19 04:26:01 +00:00
|
|
|
if common.RunPreRenderHook("pre_render_account_own_edit_username", w, r, &user, &pi) {
|
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
2018-01-10 03:32:48 +00:00
|
|
|
err := common.Templates.ExecuteTemplate(w, "account_own_edit_username.html", pi)
|
2017-10-30 09:57:08 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-10-30 09:57:08 +00:00
|
|
|
}
|
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
func routeAccountEditUsernameSubmit(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError {
|
|
|
|
headerVars, ferr := common.UserCheck(w, r, &user)
|
2017-10-30 09:57:08 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-31 07:01:44 +00:00
|
|
|
newUsername := html.EscapeString(strings.Replace(r.PostFormValue("account-new-username"), "\n", "", -1))
|
2017-11-10 03:33:11 +00:00
|
|
|
err := user.ChangeName(newUsername)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("Unable to change the username. Does someone else already have this name?", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
user.Name = newUsername
|
|
|
|
|
2018-03-21 05:56:33 +00:00
|
|
|
headerVars.NoticeList = append(headerVars.NoticeList, common.GetNoticePhrase("account_username_updated"))
|
2017-12-30 05:47:46 +00:00
|
|
|
pi := common.Page{"Edit Username", user, headerVars, tList, nil}
|
2018-02-19 04:26:01 +00:00
|
|
|
if common.RunPreRenderHook("pre_render_account_own_edit_username", w, r, &user, &pi) {
|
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
2018-01-10 03:32:48 +00:00
|
|
|
err = common.Templates.ExecuteTemplate(w, "account_own_edit_username.html", pi)
|
2017-10-30 09:57:08 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-10-30 09:57:08 +00:00
|
|
|
}
|
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
func routeAccountEditEmail(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError {
|
|
|
|
headerVars, ferr := common.UserCheck(w, r, &user)
|
2017-10-30 09:57:08 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
email := common.Email{UserID: user.ID}
|
2017-09-13 15:40:49 +00:00
|
|
|
var emailList []interface{}
|
2017-11-05 09:55:34 +00:00
|
|
|
rows, err := stmts.getEmailsByUser.Query(user.ID)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
err := rows.Scan(&email.Email, &email.Validated, &email.Token)
|
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if email.Email == user.Email {
|
|
|
|
email.Primary = true
|
|
|
|
}
|
|
|
|
emailList = append(emailList, email)
|
|
|
|
}
|
|
|
|
err = rows.Err()
|
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Was this site migrated from another forum software? Most of them don't have multiple emails for a single user.
|
|
|
|
// This also applies when the admin switches site.EnableEmails on after having it off for a while.
|
|
|
|
if len(emailList) == 0 {
|
|
|
|
email.Email = user.Email
|
|
|
|
email.Validated = false
|
|
|
|
email.Primary = true
|
|
|
|
emailList = append(emailList, email)
|
|
|
|
}
|
2017-11-11 04:06:16 +00:00
|
|
|
if !common.Site.EnableEmails {
|
2018-03-21 05:56:33 +00:00
|
|
|
headerVars.NoticeList = append(headerVars.NoticeList, common.GetNoticePhrase("account_mail_disabled"))
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
2017-12-30 05:47:46 +00:00
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
pi := common.Page{"Email Manager", user, headerVars, emailList, nil}
|
2018-02-19 04:26:01 +00:00
|
|
|
if common.RunPreRenderHook("pre_render_account_own_edit_email", w, r, &user, &pi) {
|
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
2018-01-10 03:32:48 +00:00
|
|
|
err = common.Templates.ExecuteTemplate(w, "account_own_edit_email.html", pi)
|
2017-10-30 09:57:08 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-10-30 09:57:08 +00:00
|
|
|
}
|
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-10 03:33:11 +00:00
|
|
|
// TODO: Do a session check on this?
|
2017-11-11 04:06:16 +00:00
|
|
|
func routeAccountEditEmailTokenSubmit(w http.ResponseWriter, r *http.Request, user common.User, token string) common.RouteError {
|
|
|
|
headerVars, ferr := common.UserCheck(w, r, &user)
|
2017-10-30 09:57:08 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
email := common.Email{UserID: user.ID}
|
|
|
|
targetEmail := common.Email{UserID: user.ID}
|
2017-09-13 15:40:49 +00:00
|
|
|
var emailList []interface{}
|
2017-11-05 09:55:34 +00:00
|
|
|
rows, err := stmts.getEmailsByUser.Query(user.ID)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
err := rows.Scan(&email.Email, &email.Validated, &email.Token)
|
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if email.Email == user.Email {
|
|
|
|
email.Primary = true
|
|
|
|
}
|
|
|
|
if email.Token == token {
|
|
|
|
targetEmail = email
|
|
|
|
}
|
|
|
|
emailList = append(emailList, email)
|
|
|
|
}
|
|
|
|
err = rows.Err()
|
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(emailList) == 0 {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("A verification email was never sent for you!", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
if targetEmail.Token == "" {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("That's not a valid token!", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 09:55:34 +00:00
|
|
|
_, err = stmts.verifyEmail.Exec(user.Email)
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If Email Activation is on, then activate the account while we're here
|
|
|
|
if headerVars.Settings["activation_type"] == 2 {
|
2017-11-11 04:06:16 +00:00
|
|
|
err = user.Activate()
|
2017-09-13 15:40:49 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
if !common.Site.EnableEmails {
|
2018-03-21 05:56:33 +00:00
|
|
|
headerVars.NoticeList = append(headerVars.NoticeList, common.GetNoticePhrase("account_mail_disabled"))
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
2018-03-21 05:56:33 +00:00
|
|
|
headerVars.NoticeList = append(headerVars.NoticeList, common.GetNoticePhrase("account_mail_verify_success"))
|
2017-11-11 04:06:16 +00:00
|
|
|
pi := common.Page{"Email Manager", user, headerVars, emailList, nil}
|
2018-02-19 04:26:01 +00:00
|
|
|
if common.RunPreRenderHook("pre_render_account_own_edit_email", w, r, &user, &pi) {
|
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
2018-01-10 03:32:48 +00:00
|
|
|
err = common.Templates.ExecuteTemplate(w, "account_own_edit_email.html", pi)
|
2017-10-30 09:57:08 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
2017-10-30 09:57:08 +00:00
|
|
|
}
|
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
func routeLogout(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError {
|
2017-09-13 15:40:49 +00:00
|
|
|
if !user.Loggedin {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("You can't logout without logging in first.", w, r, user)
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
2017-11-11 04:06:16 +00:00
|
|
|
common.Auth.Logout(w, user.ID)
|
2017-09-13 15:40:49 +00:00
|
|
|
http.Redirect(w, r, "/", http.StatusSeeOther)
|
2017-10-30 09:57:08 +00:00
|
|
|
return nil
|
2017-09-13 15:40:49 +00:00
|
|
|
}
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
func routeShowAttachment(w http.ResponseWriter, r *http.Request, user common.User, filename string) common.RouteError {
|
|
|
|
filename = common.Stripslashes(filename)
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
var ext = filepath.Ext("./attachs/" + filename)
|
|
|
|
//log.Print("ext ", ext)
|
|
|
|
//log.Print("filename ", filename)
|
2017-11-11 04:06:16 +00:00
|
|
|
if !common.AllowedFileExts.Contains(strings.TrimPrefix(ext, ".")) {
|
|
|
|
return common.LocalError("Bad extension", w, r, user)
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sectionID, err := strconv.Atoi(r.FormValue("sectionID"))
|
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("The sectionID is not an integer", w, r, user)
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
}
|
|
|
|
var sectionTable = r.FormValue("sectionType")
|
|
|
|
|
|
|
|
var originTable string
|
|
|
|
var originID, uploadedBy int
|
2017-11-05 09:55:34 +00:00
|
|
|
err = stmts.getAttachment.QueryRow(filename, sectionID, sectionTable).Scan(§ionID, §ionTable, &originID, &originTable, &uploadedBy, &filename)
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
if err == ErrNoRows {
|
2018-02-19 04:26:01 +00:00
|
|
|
return common.NotFound(w, r, nil)
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
} else if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.InternalError(err, w, r)
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if sectionTable == "forums" {
|
2017-11-11 04:06:16 +00:00
|
|
|
_, ferr := common.SimpleForumUserCheck(w, r, &user, sectionID)
|
2017-10-30 09:57:08 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
}
|
|
|
|
if !user.Perms.ViewTopic {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.NoPermissions(w, r, user)
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("Unknown section", w, r, user)
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if originTable != "topics" && originTable != "replies" {
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.LocalError("Unknown origin", w, r, user)
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Fix the problem where non-existent files aren't greeted with custom 404s on ServeFile()'s side
|
|
|
|
http.ServeFile(w, r, "./attachs/"+filename)
|
2017-10-30 09:57:08 +00:00
|
|
|
return nil
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
}
|