2017-09-13 15:40:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
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-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
|
|
|
}
|
|
|
|
|
2018-05-16 10:46:14 +00:00
|
|
|
profileOwner, err := common.Users.Get(userReply.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 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
|
|
|
}
|
2018-05-16 10:46:14 +00:00
|
|
|
title = "Profile: " + profileOwner.Name
|
2017-09-13 15:40:49 +00:00
|
|
|
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 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)
|
|
|
|
}
|
2018-05-15 05:59:52 +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-05-15 05:59:52 +00:00
|
|
|
if r.FormValue("verified") == "1" {
|
|
|
|
headerVars.NoticeList = append(headerVars.NoticeList, common.GetNoticePhrase("account_mail_verify_success"))
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
2018-05-15 05:59:52 +00:00
|
|
|
http.Redirect(w, r, "/user/edit/email/?verified=1", http.StatusSeeOther)
|
2017-09-13 15:40:49 +00:00
|
|
|
|
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
|
|
|
}
|