a5f5f4af7e
Added the PageStore. Renamed account_own_edit.html to account_own_edit_password.html Renamed custom-page.html to custom_page.html Renamed the pre_render_custom_page hook to pre_render_tmpl_page. Added a new pre_render_custom_page hook, not to be confused with the previous one. Renamed the pre_render_account_own_edit_critical hook to pre_render_account_own_edit_password. Moved the report forum ID into a constant. Renamed todaysReportCount to topicsTopicCountByForum and made it more generic. Renamed panel-menu.html to panel_menu.html Renamed panel-inner-menu.html to panel_inner_menu.html Removed an irrelevant editable_parent in a no results row. Fixed the profile page loading the wrong profile.css Fixed a bug where the last poster avatar would break on the forum page. Added the AddNotice method to *Header. Greatly simplified many of the page struct definitions. Added the ErrorPage page struct and refactored the error pages to use it. Added the BasePanelPage page struct and refactored the panel page structs to use it. Tweaked the DefaultHeader function to set the user on the spot rather than after the fact. Simplified AccountEditAvatarSubmit into a redirect. Add the addElement closure in the control panel dashboard to reduce the amount of complexity. Tweaked LogWarning to better handle nils. Added the account_username phrase. Added the account_avatar phrase. Added the account_email phrase. Added the panel_pages phrase. Added the panel_pages_edit phrase. Added the panel_page_created phrase. Added the panel_page_updated phrase. Added the panel_page_deleted phrase. Added the account_menu_security phrase. Added the panel_menu_pages phrase. Added the panel_pages_head phrase. Added the panel_pages_edit_button_aria phrase. Added the panel_pages_delete_button_aria phrase. Added the panel_pages_no_pages phrase. Added the panel_pages_create_head phrase. Added the panel_pages_create_name phrase. Added the panel_pages_create_name_placeholder phrase. Added the panel_pages_create_title phrase. Added the panel_pages_create_title_placeholder phrase. Added the panel_pages_create_body_placeholder phrase. Added the panel_pages_create_submit_button phrase. Added the panel_pages_edit_head phrase. Added the panel_pages_name phrase. Added the panel_pages_title phrase. Added the panel_pages_edit_update_button phrase. Began work on two-factor authentication. Made more progress with the Nox Theme.
94 lines
2.8 KiB
Go
94 lines
2.8 KiB
Go
package routes
|
|
|
|
import (
|
|
"database/sql"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"../common"
|
|
"../common/counters"
|
|
)
|
|
|
|
func ReportSubmit(w http.ResponseWriter, r *http.Request, user common.User, sitemID string) common.RouteError {
|
|
_, ferr := common.SimpleUserCheck(w, r, &user)
|
|
if ferr != nil {
|
|
return ferr
|
|
}
|
|
isJs := (r.PostFormValue("isJs") == "1")
|
|
|
|
itemID, err := strconv.Atoi(sitemID)
|
|
if err != nil {
|
|
return common.LocalError("Bad ID", w, r, user)
|
|
}
|
|
itemType := r.FormValue("type")
|
|
|
|
// TODO: Localise these titles and bodies
|
|
var title, content string
|
|
if itemType == "reply" {
|
|
reply, err := common.Rstore.Get(itemID)
|
|
if err == sql.ErrNoRows {
|
|
return common.LocalError("We were unable to find the reported post", w, r, user)
|
|
} else if err != nil {
|
|
return common.InternalError(err, w, r)
|
|
}
|
|
|
|
topic, err := common.Topics.Get(reply.ParentID)
|
|
if err == sql.ErrNoRows {
|
|
return common.LocalError("We weren't able to find the topic the reported post is supposed to be in", w, r, user)
|
|
} else if err != nil {
|
|
return common.InternalError(err, w, r)
|
|
}
|
|
|
|
title = "Reply: " + topic.Title
|
|
content = reply.Content + "\n\nOriginal Post: #rid-" + strconv.Itoa(itemID)
|
|
} else if itemType == "user-reply" {
|
|
userReply, err := common.Prstore.Get(itemID)
|
|
if err == sql.ErrNoRows {
|
|
return common.LocalError("We weren't able to find the reported post", w, r, user)
|
|
} else if err != nil {
|
|
return common.InternalError(err, w, r)
|
|
}
|
|
|
|
profileOwner, err := common.Users.Get(userReply.ParentID)
|
|
if err == sql.ErrNoRows {
|
|
return common.LocalError("We weren't able to find the profile the reported post is supposed to be on", w, r, user)
|
|
} else if err != nil {
|
|
return common.InternalError(err, w, r)
|
|
}
|
|
title = "Profile: " + profileOwner.Name
|
|
content = userReply.Content + "\n\nOriginal Post: @" + strconv.Itoa(userReply.ParentID)
|
|
} else if itemType == "topic" {
|
|
topic, err := common.Topics.Get(itemID)
|
|
if err == sql.ErrNoRows {
|
|
return common.NotFound(w, r, nil)
|
|
} else if err != nil {
|
|
return common.InternalError(err, w, r)
|
|
}
|
|
title = "Topic: " + topic.Title
|
|
content = topic.Content + "\n\nOriginal Post: #tid-" + strconv.Itoa(itemID)
|
|
} else {
|
|
_, hasHook := common.RunVhookNeedHook("report_preassign", &itemID, &itemType)
|
|
if hasHook {
|
|
return nil
|
|
}
|
|
|
|
// Don't try to guess the type
|
|
return common.LocalError("Unknown type", w, r, user)
|
|
}
|
|
|
|
// TODO: Repost attachments in the reports forum, so that the mods can see them
|
|
_, err = common.Reports.Create(title, content, &user, itemType, itemID)
|
|
if err == common.ErrAlreadyReported {
|
|
return common.LocalError("Someone has already reported this!", w, r, user)
|
|
}
|
|
counters.PostCounter.Bump()
|
|
|
|
if !isJs {
|
|
// TODO: Redirect back to where we came from
|
|
http.Redirect(w, r, "/", http.StatusSeeOther)
|
|
} else {
|
|
_, _ = w.Write(successJSONBytes)
|
|
}
|
|
return nil
|
|
}
|