From d675b2720f1e1dbf0a0ecc9c5938ffea1c854143 Mon Sep 17 00:00:00 2001 From: Azareal Date: Sun, 30 Sep 2018 10:42:33 +1000 Subject: [PATCH] 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. --- langs/english.json | 5 ++++- routes/account.go | 4 ++-- routes/panel/common.go | 1 + routes/panel/groups.go | 36 +++++++++++++++--------------------- routes/topic.go | 16 ++++++++-------- 5 files changed, 30 insertions(+), 32 deletions(-) diff --git a/langs/english.json b/langs/english.json index 6175820b..9894a073 100644 --- a/langs/english.json +++ b/langs/english.json @@ -83,7 +83,10 @@ "security_error_title":"Security Error", "security_error_body":"There was a security issue with your request.", "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": { diff --git a/routes/account.go b/routes/account.go index 648364d9..344cc232 100644 --- a/routes/account.go +++ b/routes/account.go @@ -237,13 +237,13 @@ func AccountRegisterSubmit(w http.ResponseWriter, r *http.Request, user common.U } 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.Write([]byte(common.JSTokenBox.Load().(string))) h.Write([]byte(user.LastIP)) 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")) diff --git a/routes/panel/common.go b/routes/panel/common.go index 4c41ebac..571bcfdc 100644 --- a/routes/panel/common.go +++ b/routes/panel/common.go @@ -19,6 +19,7 @@ func panelSuccessRedirect(dest string, w http.ResponseWriter, r *http.Request, i } return nil } + 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) { return nil diff --git a/routes/panel/groups.go b/routes/panel/groups.go index d358adfd..dc5d03ca 100644 --- a/routes/panel/groups.go +++ b/routes/panel/groups.go @@ -10,15 +10,14 @@ import ( // routePanelGroups 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 { return ferr } - header.Title = common.GetTitlePhrase("panel_groups") page, _ := strconv.Atoi(r.FormValue("page")) 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 offset++ @@ -33,7 +32,6 @@ func Groups(w http.ResponseWriter, r *http.Request, user common.User) common.Rou var rank string var rankClass string - var canEdit bool var canDelete = false // 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" } - 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}) count++ } - //log.Printf("groupList: %+v\n", groupList) - pageList := common.Paginate(stats.Groups, perPage, 5) - pi := common.PanelGroupPage{&common.BasePanelPage{header, stats, "groups", common.ReportForumID}, groupList, common.Paginator{pageList, page, lastPage}} + pageList := common.Paginate(basePage.Stats.Groups, perPage, 5) + pi := common.PanelGroupPage{basePage, groupList, common.Paginator{pageList, page, lastPage}} return panelRenderTemplate("panel_groups", w, r, user, &pi) } //routePanelGroupsEdit 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 { return ferr } if !user.Perms.EditGroup { return common.NoPermissions(w, r, user) } - header.Title = common.GetTitlePhrase("panel_edit_group") gid, err := strconv.Atoi(sgid) 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) if err == sql.ErrNoRows { //log.Print("aaaaa monsters") - return common.NotFound(w, r, header) + return common.NotFound(w, r, basePage.Header) } else if err != nil { return common.InternalError(err, w, r) } @@ -110,10 +106,9 @@ func GroupsEdit(w http.ResponseWriter, r *http.Request, user common.User, sgid s default: rank = "Member" } - 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) { return nil } @@ -126,24 +121,23 @@ func GroupsEdit(w http.ResponseWriter, r *http.Request, user common.User, sgid s //routePanelGroupsEditPerms 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 { return ferr } if !user.Perms.EditGroup { return common.NoPermissions(w, r, user) } - header.Title = common.GetTitlePhrase("panel_edit_group") gid, err := strconv.Atoi(sgid) 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) if err == sql.ErrNoRows { //log.Print("aaaaa monsters") - return common.NotFound(w, r, header) + return common.NotFound(w, r, basePage.Header) } else if err != nil { 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("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) { return nil } @@ -224,7 +218,7 @@ func GroupsEditSubmit(w http.ResponseWriter, r *http.Request, user common.User, gid, err := strconv.Atoi(sgid) 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) @@ -314,7 +308,7 @@ func GroupsEditPermsSubmit(w http.ResponseWriter, r *http.Request, user common.U gid, err := strconv.Atoi(sgid) 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) diff --git a/routes/topic.go b/routes/topic.go index 97f1a4a9..44b8f02f 100644 --- a/routes/topic.go +++ b/routes/topic.go @@ -48,7 +48,7 @@ func ViewTopic(w http.ResponseWriter, r *http.Request, user common.User, urlBit tid, err := strconv.Atoi(halves[1]) 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... @@ -242,7 +242,7 @@ func CreateTopic(w http.ResponseWriter, r *http.Request, user common.User, sfid if sfid != "" { fid, err = strconv.Atoi(sfid) 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 { @@ -493,7 +493,7 @@ func EditTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, s tid, err := strconv.Atoi(stid) 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) @@ -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 { tid, err := strconv.Atoi(stid) 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) @@ -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 { tid, err := strconv.Atoi(stid) 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) @@ -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 { tid, err := strconv.Atoi(stid) 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) @@ -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 { fid, err := strconv.Atoi(sfid) 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 @@ -849,7 +849,7 @@ func LikeTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, s isJs := (r.PostFormValue("isJs") == "1") tid, err := strconv.Atoi(stid) 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)