Began localising the id_must_be_integer and url_id_must_be_integer error pages.

Fixed the punctuation on a couple of registration errors, these will be localised too soon enough.
Removed a bit of boiletplate in groups.go with buildBasePage.
This commit is contained in:
Azareal 2018-09-30 10:42:33 +10:00
parent 322a46bcb5
commit d675b2720f
5 changed files with 30 additions and 32 deletions

View File

@ -83,7 +83,10 @@
"security_error_title":"Security Error", "security_error_title":"Security Error",
"security_error_body":"There was a security issue with your request.", "security_error_body":"There was a security issue with your request.",
"banned_title":"Banned", "banned_title":"Banned",
"banned_body":"You have been banned from this site." "banned_body":"You have been banned from this site.",
"id_must_be_integer": "The ID must be an integer.",
"url_id_must_be_integer": "The ID in the URL needs to be a valid integer."
}, },
"PageTitles": { "PageTitles": {

View File

@ -237,13 +237,13 @@ func AccountRegisterSubmit(w http.ResponseWriter, r *http.Request, user common.U
} }
if r.PostFormValue("tos") != "0" { if r.PostFormValue("tos") != "0" {
regError("You might be a machine", "trap-question") regError("You might be a machine.", "trap-question")
} }
h := sha256.New() h := sha256.New()
h.Write([]byte(common.JSTokenBox.Load().(string))) h.Write([]byte(common.JSTokenBox.Load().(string)))
h.Write([]byte(user.LastIP)) h.Write([]byte(user.LastIP))
if r.PostFormValue("golden-watch") != hex.EncodeToString(h.Sum(nil)) { if r.PostFormValue("golden-watch") != hex.EncodeToString(h.Sum(nil)) {
regError("You might be a machine", "js-antispam") regError("You might be a machine.", "js-antispam")
} }
username := common.SanitiseSingleLine(r.PostFormValue("username")) username := common.SanitiseSingleLine(r.PostFormValue("username"))

View File

@ -19,6 +19,7 @@ func panelSuccessRedirect(dest string, w http.ResponseWriter, r *http.Request, i
} }
return nil return nil
} }
func panelRenderTemplate(tmplName string, w http.ResponseWriter, r *http.Request, user common.User, pi interface{}) common.RouteError { func panelRenderTemplate(tmplName string, w http.ResponseWriter, r *http.Request, user common.User, pi interface{}) common.RouteError {
if common.RunPreRenderHook("pre_render_"+tmplName, w, r, &user, pi) { if common.RunPreRenderHook("pre_render_"+tmplName, w, r, &user, pi) {
return nil return nil

View File

@ -10,15 +10,14 @@ import (
// routePanelGroups // routePanelGroups
func Groups(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { func Groups(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError {
header, stats, ferr := common.PanelUserCheck(w, r, &user) basePage, ferr := buildBasePage(w, r, &user, "groups", "groups")
if ferr != nil { if ferr != nil {
return ferr return ferr
} }
header.Title = common.GetTitlePhrase("panel_groups")
page, _ := strconv.Atoi(r.FormValue("page")) page, _ := strconv.Atoi(r.FormValue("page"))
perPage := 9 perPage := 9
offset, page, lastPage := common.PageOffset(stats.Groups, page, perPage) offset, page, lastPage := common.PageOffset(basePage.Stats.Groups, page, perPage)
// Skip the 'Unknown' group // Skip the 'Unknown' group
offset++ offset++
@ -33,7 +32,6 @@ func Groups(w http.ResponseWriter, r *http.Request, user common.User) common.Rou
var rank string var rank string
var rankClass string var rankClass string
var canEdit bool
var canDelete = false var canDelete = false
// TODO: Use a switch for this // TODO: Use a switch for this
@ -55,37 +53,35 @@ func Groups(w http.ResponseWriter, r *http.Request, user common.User) common.Rou
rankClass = "member" rankClass = "member"
} }
canEdit = user.Perms.EditGroup && (!group.IsAdmin || user.Perms.EditGroupAdmin) && (!group.IsMod || user.Perms.EditGroupSuperMod) canEdit := user.Perms.EditGroup && (!group.IsAdmin || user.Perms.EditGroupAdmin) && (!group.IsMod || user.Perms.EditGroupSuperMod)
groupList = append(groupList, common.GroupAdmin{group.ID, group.Name, rank, rankClass, canEdit, canDelete}) groupList = append(groupList, common.GroupAdmin{group.ID, group.Name, rank, rankClass, canEdit, canDelete})
count++ count++
} }
//log.Printf("groupList: %+v\n", groupList)
pageList := common.Paginate(stats.Groups, perPage, 5) pageList := common.Paginate(basePage.Stats.Groups, perPage, 5)
pi := common.PanelGroupPage{&common.BasePanelPage{header, stats, "groups", common.ReportForumID}, groupList, common.Paginator{pageList, page, lastPage}} pi := common.PanelGroupPage{basePage, groupList, common.Paginator{pageList, page, lastPage}}
return panelRenderTemplate("panel_groups", w, r, user, &pi) return panelRenderTemplate("panel_groups", w, r, user, &pi)
} }
//routePanelGroupsEdit //routePanelGroupsEdit
func GroupsEdit(w http.ResponseWriter, r *http.Request, user common.User, sgid string) common.RouteError { func GroupsEdit(w http.ResponseWriter, r *http.Request, user common.User, sgid string) common.RouteError {
header, stats, ferr := common.PanelUserCheck(w, r, &user) basePage, ferr := buildBasePage(w, r, &user, "edit_group", "groups")
if ferr != nil { if ferr != nil {
return ferr return ferr
} }
if !user.Perms.EditGroup { if !user.Perms.EditGroup {
return common.NoPermissions(w, r, user) return common.NoPermissions(w, r, user)
} }
header.Title = common.GetTitlePhrase("panel_edit_group")
gid, err := strconv.Atoi(sgid) gid, err := strconv.Atoi(sgid)
if err != nil { if err != nil {
return common.LocalError("You need to provide a whole number for the group ID", w, r, user) return common.LocalError(common.GetErrorPhrase("url_id_must_be_integer"), w, r, user)
} }
group, err := common.Groups.Get(gid) group, err := common.Groups.Get(gid)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
//log.Print("aaaaa monsters") //log.Print("aaaaa monsters")
return common.NotFound(w, r, header) return common.NotFound(w, r, basePage.Header)
} else if err != nil { } else if err != nil {
return common.InternalError(err, w, r) return common.InternalError(err, w, r)
} }
@ -110,10 +106,9 @@ func GroupsEdit(w http.ResponseWriter, r *http.Request, user common.User, sgid s
default: default:
rank = "Member" rank = "Member"
} }
disableRank := !user.Perms.EditGroupGlobalPerms || (group.ID == 6) disableRank := !user.Perms.EditGroupGlobalPerms || (group.ID == 6)
pi := common.PanelEditGroupPage{&common.BasePanelPage{header, stats, "groups", common.ReportForumID}, group.ID, group.Name, group.Tag, rank, disableRank} pi := common.PanelEditGroupPage{basePage, group.ID, group.Name, group.Tag, rank, disableRank}
if common.RunPreRenderHook("pre_render_panel_edit_group", w, r, &user, &pi) { if common.RunPreRenderHook("pre_render_panel_edit_group", w, r, &user, &pi) {
return nil return nil
} }
@ -126,24 +121,23 @@ func GroupsEdit(w http.ResponseWriter, r *http.Request, user common.User, sgid s
//routePanelGroupsEditPerms //routePanelGroupsEditPerms
func GroupsEditPerms(w http.ResponseWriter, r *http.Request, user common.User, sgid string) common.RouteError { func GroupsEditPerms(w http.ResponseWriter, r *http.Request, user common.User, sgid string) common.RouteError {
header, stats, ferr := common.PanelUserCheck(w, r, &user) basePage, ferr := buildBasePage(w, r, &user, "edit_group", "groups")
if ferr != nil { if ferr != nil {
return ferr return ferr
} }
if !user.Perms.EditGroup { if !user.Perms.EditGroup {
return common.NoPermissions(w, r, user) return common.NoPermissions(w, r, user)
} }
header.Title = common.GetTitlePhrase("panel_edit_group")
gid, err := strconv.Atoi(sgid) gid, err := strconv.Atoi(sgid)
if err != nil { if err != nil {
return common.LocalError("The Group ID is not a valid integer.", w, r, user) return common.LocalError(common.GetErrorPhrase("url_id_must_be_integer"), w, r, user)
} }
group, err := common.Groups.Get(gid) group, err := common.Groups.Get(gid)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
//log.Print("aaaaa monsters") //log.Print("aaaaa monsters")
return common.NotFound(w, r, header) return common.NotFound(w, r, basePage.Header)
} else if err != nil { } else if err != nil {
return common.InternalError(err, w, r) return common.InternalError(err, w, r)
} }
@ -201,7 +195,7 @@ func GroupsEditPerms(w http.ResponseWriter, r *http.Request, user common.User, s
addGlobalPerm("ViewIPs", group.Perms.ViewIPs) addGlobalPerm("ViewIPs", group.Perms.ViewIPs)
addGlobalPerm("UploadFiles", group.Perms.UploadFiles) addGlobalPerm("UploadFiles", group.Perms.UploadFiles)
pi := common.PanelEditGroupPermsPage{&common.BasePanelPage{header, stats, "groups", common.ReportForumID}, group.ID, group.Name, localPerms, globalPerms} pi := common.PanelEditGroupPermsPage{basePage, group.ID, group.Name, localPerms, globalPerms}
if common.RunPreRenderHook("pre_render_panel_edit_group_perms", w, r, &user, &pi) { if common.RunPreRenderHook("pre_render_panel_edit_group_perms", w, r, &user, &pi) {
return nil return nil
} }
@ -224,7 +218,7 @@ func GroupsEditSubmit(w http.ResponseWriter, r *http.Request, user common.User,
gid, err := strconv.Atoi(sgid) gid, err := strconv.Atoi(sgid)
if err != nil { if err != nil {
return common.LocalError("You need to provide a whole number for the group ID", w, r, user) return common.LocalError(common.GetErrorPhrase("id_must_be_integer"), w, r, user)
} }
group, err := common.Groups.Get(gid) group, err := common.Groups.Get(gid)
@ -314,7 +308,7 @@ func GroupsEditPermsSubmit(w http.ResponseWriter, r *http.Request, user common.U
gid, err := strconv.Atoi(sgid) gid, err := strconv.Atoi(sgid)
if err != nil { if err != nil {
return common.LocalError("The Group ID is not a valid integer.", w, r, user) return common.LocalError(common.GetErrorPhrase("id_must_be_integer"), w, r, user)
} }
group, err := common.Groups.Get(gid) group, err := common.Groups.Get(gid)

View File

@ -48,7 +48,7 @@ func ViewTopic(w http.ResponseWriter, r *http.Request, user common.User, urlBit
tid, err := strconv.Atoi(halves[1]) tid, err := strconv.Atoi(halves[1])
if err != nil { if err != nil {
return common.PreError("The provided TopicID is not a valid number.", w, r) return common.PreError(common.GetErrorPhrase("url_id_must_be_integer"), w, r)
} }
// Get the topic... // Get the topic...
@ -242,7 +242,7 @@ func CreateTopic(w http.ResponseWriter, r *http.Request, user common.User, sfid
if sfid != "" { if sfid != "" {
fid, err = strconv.Atoi(sfid) fid, err = strconv.Atoi(sfid)
if err != nil { if err != nil {
return common.LocalError("You didn't provide a valid number for the forum ID.", w, r, user) return common.LocalError(common.GetErrorPhrase("url_id_must_be_integer"), w, r, user)
} }
} }
if fid == 0 { if fid == 0 {
@ -493,7 +493,7 @@ func EditTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, s
tid, err := strconv.Atoi(stid) tid, err := strconv.Atoi(stid)
if err != nil { if err != nil {
return common.PreErrorJSQ("The provided TopicID is not a valid number.", w, r, isJs) return common.PreErrorJSQ(common.GetErrorPhrase("id_must_be_integer"), w, r, isJs)
} }
topic, err := common.Topics.Get(tid) topic, err := common.Topics.Get(tid)
@ -611,7 +611,7 @@ func DeleteTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User)
func StickTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, stid string) common.RouteError { func StickTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, stid string) common.RouteError {
tid, err := strconv.Atoi(stid) tid, err := strconv.Atoi(stid)
if err != nil { if err != nil {
return common.PreError("The provided TopicID is not a valid number.", w, r) return common.PreError(common.GetErrorPhrase("id_must_be_integer"), w, r)
} }
topic, err := common.Topics.Get(tid) topic, err := common.Topics.Get(tid)
@ -646,7 +646,7 @@ func StickTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User,
func UnstickTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, stid string) common.RouteError { func UnstickTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, stid string) common.RouteError {
tid, err := strconv.Atoi(stid) tid, err := strconv.Atoi(stid)
if err != nil { if err != nil {
return common.PreError("The provided TopicID is not a valid number.", w, r) return common.PreError(common.GetErrorPhrase("id_must_be_integer"), w, r)
} }
topic, err := common.Topics.Get(tid) topic, err := common.Topics.Get(tid)
@ -740,7 +740,7 @@ func LockTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User) c
func UnlockTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, stid string) common.RouteError { func UnlockTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, stid string) common.RouteError {
tid, err := strconv.Atoi(stid) tid, err := strconv.Atoi(stid)
if err != nil { if err != nil {
return common.PreError("The provided TopicID is not a valid number.", w, r) return common.PreError(common.GetErrorPhrase("id_must_be_integer"), w, r)
} }
topic, err := common.Topics.Get(tid) topic, err := common.Topics.Get(tid)
@ -778,7 +778,7 @@ func UnlockTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User,
func MoveTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, sfid string) common.RouteError { func MoveTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, sfid string) common.RouteError {
fid, err := strconv.Atoi(sfid) fid, err := strconv.Atoi(sfid)
if err != nil { if err != nil {
return common.PreErrorJS("The provided Forum ID is not a valid number.", w, r) return common.PreErrorJS(common.GetErrorPhrase("id_must_be_integer"), w, r)
} }
// TODO: Move this to some sort of middleware // TODO: Move this to some sort of middleware
@ -849,7 +849,7 @@ func LikeTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, s
isJs := (r.PostFormValue("isJs") == "1") isJs := (r.PostFormValue("isJs") == "1")
tid, err := strconv.Atoi(stid) tid, err := strconv.Atoi(stid)
if err != nil { if err != nil {
return common.PreErrorJSQ("Topic IDs can only ever be numbers.", w, r, isJs) return common.PreErrorJSQ(common.GetErrorPhrase("id_must_be_integer"), w, r, isJs)
} }
topic, err := common.Topics.Get(tid) topic, err := common.Topics.Get(tid)