github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/router_gen/routes.go (about) 1 package main 2 3 // TODO: How should we handle *HeaderLite and *Header? 4 func routes(r *Router) { 5 r.Add(View("routes.Overview", "/overview/")) 6 r.Add(View("routes.CustomPage", "/pages/", "extraData")) 7 r.Add(View("routes.ForumList", "/forums/" /*,"&forums"*/)) 8 r.Add(View("routes.ViewForum", "/forum/", "extraData")) 9 r.Add(AnonAction("routes.ChangeTheme", "/theme/")) 10 r.Add( 11 View("routes.ShowAttachment", "/attachs/", "extraData").Before("ParseForm").NoGzip().NoHeader(), 12 ) 13 14 apiGroup := newRouteGroup("/api/", 15 View("routeAPI", "/api/"), 16 View("routeAPIPhrases", "/api/phrases/"), // TODO: Be careful with exposing the panel phrases here 17 View("routes.APIMe", "/api/me/"), 18 View("routeJSAntispam", "/api/watches/"), 19 ).NoHeader() 20 r.AddGroup(apiGroup) 21 22 // TODO: Reduce the number of Befores. With a new method, perhaps? 23 reportGroup := newRouteGroup("/report/", 24 Action("routes.ReportSubmit", "/report/submit/", "extraData"), 25 ).Before("NoBanned") 26 r.AddGroup(reportGroup) 27 28 topicGroup := newRouteGroup("/topics/", 29 View("routes.TopicList", "/topics/"), 30 View("routes.TopicListMostViewed", "/topics/most-viewed/"), 31 View("routes.TopicListWeekViews", "/topics/week-views/"), 32 MView("routes.CreateTopic", "/topics/create/", "extraData"), 33 ) 34 r.AddGroup(topicGroup) 35 36 r.AddGroup(panelRoutes()) 37 r.AddGroup(userRoutes()) 38 r.AddGroup(usersRoutes()) 39 r.AddGroup(topicRoutes()) 40 r.AddGroup(replyRoutes()) 41 r.AddGroup(profileReplyRoutes()) 42 r.AddGroup(pollRoutes()) 43 r.AddGroup(accountRoutes()) 44 45 r.Add(Special("common.RouteWebsockets", "/ws/")) 46 } 47 48 // TODO: Test the email token route 49 func userRoutes() *RouteGroup { 50 return newRouteGroup("/user/").Routes( 51 View("routes.ViewProfile", "/user/").LitBefore("req.URL.Path += extraData"), 52 53 Set("routes.AccountEdit", "/user/edit/", 54 MView("", "/"), 55 MView("Password", "/password/"), 56 Action("PasswordSubmit", "/password/submit/"), // TODO: Full test this 57 UploadAction("AvatarSubmit", "/avatar/submit/").MaxSizeVar("int(c.Config.MaxRequestSize)"), 58 Action("RevokeAvatarSubmit", "/avatar/revoke/submit/"), 59 Action("UsernameSubmit", "/username/submit/"), // TODO: Full test this 60 MView("Privacy", "/privacy/"), 61 Action("PrivacySubmit", "/privacy/submit/"), 62 MView("MFA", "/mfa/"), 63 MView("MFASetup", "/mfa/setup/"), 64 Action("MFASetupSubmit", "/mfa/setup/submit/"), 65 Action("MFADisableSubmit", "/mfa/disable/submit/"), 66 MView("Email", "/email/"), 67 View("EmailTokenSubmit", "/token/", "extraData").NoHeader(), 68 //Action("EmailAddSubmit", "/user/edit/email/add/submit/"), 69 //Action("EmailRemoveSubmit", "/user/edit/email/remove/submit/"), 70 ), 71 72 /*MView("routes.AccountEdit", "/user/edit/"), 73 MView("routes.AccountEditPassword", "/user/edit/password/"), 74 Action("routes.AccountEditPasswordSubmit", "/user/edit/password/submit/"), // TODO: Full test this 75 UploadAction("routes.AccountEditAvatarSubmit", "/user/edit/avatar/submit/").MaxSizeVar("int(c.Config.MaxRequestSize)"), 76 Action("routes.AccountEditRevokeAvatarSubmit", "/user/edit/avatar/revoke/submit/"), 77 Action("routes.AccountEditUsernameSubmit", "/user/edit/username/submit/"), // TODO: Full test this 78 MView("routes.AccountEditMFA", "/user/edit/mfa/"), 79 MView("routes.AccountEditMFASetup", "/user/edit/mfa/setup/"), 80 Action("routes.AccountEditMFASetupSubmit", "/user/edit/mfa/setup/submit/"), 81 Action("routes.AccountEditMFADisableSubmit", "/user/edit/mfa/disable/submit/"), 82 MView("routes.AccountEditEmail", "/user/edit/email/"), 83 View("routes.AccountEditEmailTokenSubmit", "/user/edit/token/", "extraData").NoHeader(),*/ 84 85 MView("routes.AccountLogins", "/user/edit/logins/"), 86 MView("routes.AccountBlocked", "/user/edit/blocked/"), 87 88 MView("routes.LevelList", "/user/levels/"), 89 //MView("routes.LevelRankings", "/user/rankings/"), 90 //MView("routes.Alerts", "/user/alerts/"), 91 92 MView("routes.Convos", "/user/convos/"), 93 MView("routes.ConvosCreate", "/user/convos/create/"), 94 MView("routes.Convo", "/user/convo/", "extraData"), 95 Action("routes.ConvosCreateSubmit", "/user/convos/create/submit/"), 96 //Action("routes.ConvosDeleteSubmit", "/user/convos/delete/submit/", "extraData"), 97 Action("routes.ConvosCreateReplySubmit", "/user/convo/create/submit/", "extraData"), 98 Action("routes.ConvosDeleteReplySubmit", "/user/convo/delete/submit/", "extraData"), 99 Action("routes.ConvosEditReplySubmit", "/user/convo/edit/submit/", "extraData"), 100 101 MView("routes.RelationsBlockCreate", "/user/block/create/", "extraData"), 102 Action("routes.RelationsBlockCreateSubmit", "/user/block/create/submit/", "extraData"), 103 MView("routes.RelationsBlockRemove", "/user/block/remove/", "extraData"), 104 Action("routes.RelationsBlockRemoveSubmit", "/user/block/remove/submit/", "extraData"), 105 ) 106 } 107 108 func usersRoutes() *RouteGroup { 109 // TODO: Auto test and manual test these routes 110 return newRouteGroup("/users/").Routes( 111 Action("routes.BanUserSubmit", "/users/ban/submit/", "extraData"), 112 Action("routes.UnbanUser", "/users/unban/", "extraData"), 113 Action("routes.ActivateUser", "/users/activate/", "extraData"), 114 MView("routes.IPSearch", "/users/ips/"), // TODO: .Perms("ViewIPs")? 115 Action("routes.DeletePostsSubmit", "/users/delete-posts/submit/", "extraData"), 116 ) 117 } 118 119 func topicRoutes() *RouteGroup { 120 return newRouteGroup("/topic/").Routes( 121 View("routes.ViewTopic", "/topic/", "extraData"), 122 UploadAction("routes.CreateTopicSubmit", "/topic/create/submit/").MaxSizeVar("int(c.Config.MaxRequestSize)"), 123 Action("routes.EditTopicSubmit", "/topic/edit/submit/", "extraData"), 124 Action("routes.DeleteTopicSubmit", "/topic/delete/submit/").LitBefore("req.URL.Path += extraData"), 125 Action("routes.StickTopicSubmit", "/topic/stick/submit/", "extraData"), 126 Action("routes.UnstickTopicSubmit", "/topic/unstick/submit/", "extraData"), 127 Action("routes.LockTopicSubmit", "/topic/lock/submit/").LitBefore("req.URL.Path += extraData"), 128 Action("routes.UnlockTopicSubmit", "/topic/unlock/submit/", "extraData"), 129 Action("routes.MoveTopicSubmit", "/topic/move/submit/", "extraData"), 130 Action("routes.LikeTopicSubmit", "/topic/like/submit/", "extraData"), 131 Action("routes.UnlikeTopicSubmit", "/topic/unlike/submit/", "extraData"), 132 UploadAction("routes.AddAttachToTopicSubmit", "/topic/attach/add/submit/", "extraData").MaxSizeVar("int(c.Config.MaxRequestSize)"), 133 Action("routes.RemoveAttachFromTopicSubmit", "/topic/attach/remove/submit/", "extraData"), 134 ) 135 } 136 137 func replyRoutes() *RouteGroup { 138 return newRouteGroup("/reply/").Routes( 139 // TODO: Reduce this to 1MB for attachments for each file? 140 UploadAction("routes.CreateReplySubmit", "/reply/create/").MaxSizeVar("int(c.Config.MaxRequestSize)"), // TODO: Rename the route so it's /reply/create/submit/ 141 Action("routes.ReplyEditSubmit", "/reply/edit/submit/", "extraData"), 142 Action("routes.ReplyDeleteSubmit", "/reply/delete/submit/", "extraData"), 143 Action("routes.ReplyLikeSubmit", "/reply/like/submit/", "extraData"), 144 Action("routes.ReplyUnlikeSubmit", "/reply/unlike/submit/", "extraData"), 145 //MemberView("routes.ReplyEdit","/reply/edit/","extraData"), // No js fallback 146 //MemberView("routes.ReplyDelete","/reply/delete/","extraData"), // No js confirmation page? We could have a confirmation modal for the JS case 147 UploadAction("routes.AddAttachToReplySubmit", "/reply/attach/add/submit/", "extraData").MaxSizeVar("int(c.Config.MaxRequestSize)"), 148 Action("routes.RemoveAttachFromReplySubmit", "/reply/attach/remove/submit/", "extraData"), 149 ) 150 } 151 152 // TODO: Move these into /user/? 153 func profileReplyRoutes() *RouteGroup { 154 return newRouteGroup("/profile/").Routes( 155 Action("routes.ProfileReplyCreateSubmit", "/profile/reply/create/"), // TODO: Add /submit/ to the end 156 Action("routes.ProfileReplyEditSubmit", "/profile/reply/edit/submit/", "extraData"), 157 Action("routes.ProfileReplyDeleteSubmit", "/profile/reply/delete/submit/", "extraData"), 158 ) 159 } 160 161 func pollRoutes() *RouteGroup { 162 return newRouteGroup("/poll/").Routes( 163 Action("routes.PollVote", "/poll/vote/", "extraData"), 164 View("routes.PollResults", "/poll/results/", "extraData").NoHeader(), 165 ) 166 } 167 168 func accountRoutes() *RouteGroup { 169 //router.HandleFunc("/accounts/list/", routeLogin) // Redirect /accounts/ and /user/ to here.. // Get a list of all of the accounts on the forum 170 return newRouteGroup("/accounts/").Routes( 171 View("routes.AccountLogin", "/accounts/login/"), 172 View("routes.AccountRegister", "/accounts/create/"), 173 Action("routes.AccountLogout", "/accounts/logout/"), 174 AnonAction("routes.AccountLoginSubmit", "/accounts/login/submit/"), // TODO: Guard this with a token, maybe the IP hashed with a rotated key? 175 View("routes.AccountLoginMFAVerify", "/accounts/mfa_verify/"), 176 AnonAction("routes.AccountLoginMFAVerifySubmit", "/accounts/mfa_verify/submit/"), // We have logic in here which filters out regular guests 177 AnonAction("routes.AccountRegisterSubmit", "/accounts/create/submit/"), 178 179 View("routes.AccountPasswordReset", "/accounts/password-reset/"), 180 AnonAction("routes.AccountPasswordResetSubmit", "/accounts/password-reset/submit/"), 181 View("routes.AccountPasswordResetToken", "/accounts/password-reset/token/"), 182 AnonAction("routes.AccountPasswordResetTokenSubmit", "/accounts/password-reset/token/submit/"), 183 ) 184 } 185 186 func panelRoutes() *RouteGroup { 187 // TODO: Implement subgroups 188 return newRouteGroup("/panel/").Before("SuperModOnly").NoHeader().Routes( 189 View("panel.Dashboard", "/panel/"), 190 //View("panel.StatsDisk", "/panel/stats/disk/"), 191 192 View("panel.Forums", "/panel/forums/"), 193 Action("panel.ForumsCreateSubmit", "/panel/forums/create/"), 194 Action("panel.ForumsDelete", "/panel/forums/delete/", "extraData"), 195 Action("panel.ForumsDeleteSubmit", "/panel/forums/delete/submit/", "extraData"), 196 Action("panel.ForumsOrderSubmit", "/panel/forums/order/edit/submit/"), 197 View("panel.ForumsEdit", "/panel/forums/edit/", "extraData"), 198 Action("panel.ForumsEditSubmit", "/panel/forums/edit/submit/", "extraData"), 199 Action("panel.ForumsEditPermsSubmit", "/panel/forums/edit/perms/submit/", "extraData"), 200 View("panel.ForumsEditPermsAdvance", "/panel/forums/edit/perms/", "extraData"), 201 Action("panel.ForumsEditPermsAdvanceSubmit", "/panel/forums/edit/perms/adv/submit/", "extraData"), 202 Action("panel.ForumsEditActionCreateSubmit", "/panel/forums/action/create/submit/", "extraData"), 203 Action("panel.ForumsEditActionDeleteSubmit", "/panel/forums/action/delete/submit/", "extraData"), 204 205 View("panel.Settings", "/panel/settings/"), 206 View("panel.SettingEdit", "/panel/settings/edit/", "extraData"), 207 Action("panel.SettingEditSubmit", "/panel/settings/edit/submit/", "extraData"), 208 209 View("panel.WordFilters", "/panel/settings/word-filters/"), 210 Action("panel.WordFiltersCreateSubmit", "/panel/settings/word-filters/create/"), 211 View("panel.WordFiltersEdit", "/panel/settings/word-filters/edit/", "extraData"), 212 Action("panel.WordFiltersEditSubmit", "/panel/settings/word-filters/edit/submit/", "extraData"), 213 Action("panel.WordFiltersDeleteSubmit", "/panel/settings/word-filters/delete/submit/", "extraData"), 214 215 View("panel.Pages", "/panel/pages/").Before("AdminOnly"), 216 Action("panel.PagesCreateSubmit", "/panel/pages/create/submit/").Before("AdminOnly"), 217 View("panel.PagesEdit", "/panel/pages/edit/", "extraData").Before("AdminOnly"), 218 Action("panel.PagesEditSubmit", "/panel/pages/edit/submit/", "extraData").Before("AdminOnly"), 219 Action("panel.PagesDeleteSubmit", "/panel/pages/delete/submit/", "extraData").Before("AdminOnly"), 220 221 View("panel.Themes", "/panel/themes/"), 222 Action("panel.ThemesSetDefault", "/panel/themes/default/", "extraData"), 223 View("panel.ThemesMenus", "/panel/themes/menus/"), 224 View("panel.ThemesMenusEdit", "/panel/themes/menus/edit/", "extraData"), 225 View("panel.ThemesMenuItemEdit", "/panel/themes/menus/item/edit/", "extraData"), 226 Action("panel.ThemesMenuItemEditSubmit", "/panel/themes/menus/item/edit/submit/", "extraData"), 227 Action("panel.ThemesMenuItemCreateSubmit", "/panel/themes/menus/item/create/submit/"), 228 Action("panel.ThemesMenuItemDeleteSubmit", "/panel/themes/menus/item/delete/submit/", "extraData"), 229 Action("panel.ThemesMenuItemOrderSubmit", "/panel/themes/menus/item/order/edit/submit/", "extraData"), 230 231 View("panel.ThemesWidgets", "/panel/themes/widgets/"), 232 //View("panel.ThemesWidgetsEdit", "/panel/themes/widgets/edit/", "extraData"), 233 Action("panel.ThemesWidgetsEditSubmit", "/panel/themes/widgets/edit/submit/", "extraData"), 234 Action("panel.ThemesWidgetsCreateSubmit", "/panel/themes/widgets/create/submit/"), 235 Action("panel.ThemesWidgetsDeleteSubmit", "/panel/themes/widgets/delete/submit/", "extraData"), 236 237 View("panel.Plugins", "/panel/plugins/"), 238 Action("panel.PluginsActivate", "/panel/plugins/activate/", "extraData"), 239 Action("panel.PluginsDeactivate", "/panel/plugins/deactivate/", "extraData"), 240 Action("panel.PluginsInstall", "/panel/plugins/install/", "extraData"), 241 242 View("panel.Users", "/panel/users/"), 243 View("panel.UsersEdit", "/panel/users/edit/", "extraData"), 244 Action("panel.UsersEditSubmit", "/panel/users/edit/submit/", "extraData"), 245 UploadAction("panel.UsersAvatarSubmit", "/panel/users/avatar/submit/", "extraData").MaxSizeVar("int(c.Config.MaxRequestSize)"), 246 Action("panel.UsersAvatarRemoveSubmit", "/panel/users/avatar/remove/submit/", "extraData"), 247 248 View("panel.AnalyticsViews", "/panel/analytics/views/").Before("ParseForm"), 249 View("panel.AnalyticsRoutes", "/panel/analytics/routes/").Before("ParseForm"), 250 View("panel.AnalyticsRoutesPerf", "/panel/analytics/routes-perf/").Before("ParseForm"), 251 View("panel.AnalyticsAgents", "/panel/analytics/agents/").Before("ParseForm"), 252 View("panel.AnalyticsSystems", "/panel/analytics/systems/").Before("ParseForm"), 253 View("panel.AnalyticsLanguages", "/panel/analytics/langs/").Before("ParseForm"), 254 View("panel.AnalyticsReferrers", "/panel/analytics/referrers/").Before("ParseForm"), 255 View("panel.AnalyticsRouteViews", "/panel/analytics/route/", "extraData"), 256 View("panel.AnalyticsAgentViews", "/panel/analytics/agent/", "extraData"), 257 View("panel.AnalyticsForumViews", "/panel/analytics/forum/", "extraData"), 258 View("panel.AnalyticsSystemViews", "/panel/analytics/system/", "extraData"), 259 View("panel.AnalyticsLanguageViews", "/panel/analytics/lang/", "extraData"), 260 View("panel.AnalyticsReferrerViews", "/panel/analytics/referrer/", "extraData"), 261 View("panel.AnalyticsPosts", "/panel/analytics/posts/").Before("ParseForm"), 262 View("panel.AnalyticsMemory", "/panel/analytics/memory/").Before("ParseForm"), 263 View("panel.AnalyticsActiveMemory", "/panel/analytics/active-memory/").Before("ParseForm"), 264 View("panel.AnalyticsTopics", "/panel/analytics/topics/").Before("ParseForm"), 265 View("panel.AnalyticsForums", "/panel/analytics/forums/").Before("ParseForm"), 266 View("panel.AnalyticsPerf", "/panel/analytics/perf/").Before("ParseForm"), 267 268 View("panel.Groups", "/panel/groups/"), 269 View("panel.GroupsEdit", "/panel/groups/edit/", "extraData"), 270 View("panel.GroupsEditPromotions", "/panel/groups/edit/promotions/", "extraData"), 271 Action("panel.GroupsPromotionsCreateSubmit", "/panel/groups/promotions/create/submit/", "extraData"), 272 Action("panel.GroupsPromotionsDeleteSubmit", "/panel/groups/promotions/delete/submit/", "extraData"), 273 View("panel.GroupsEditPerms", "/panel/groups/edit/perms/", "extraData"), 274 Action("panel.GroupsEditSubmit", "/panel/groups/edit/submit/", "extraData"), 275 Action("panel.GroupsEditPermsSubmit", "/panel/groups/edit/perms/submit/", "extraData"), 276 Action("panel.GroupsCreateSubmit", "/panel/groups/create/"), 277 278 View("panel.Backups", "/panel/backups/", "extraData").Before("SuperAdminOnly").NoGzip(), // TODO: Tests for this 279 View("panel.LogsRegs", "/panel/logs/regs/"), 280 View("panel.LogsMod", "/panel/logs/mod/"), 281 View("panel.LogsAdmin", "/panel/logs/admin/"), 282 View("panel.Debug", "/panel/debug/").Before("AdminOnly"), 283 View("panel.DebugTasks", "/panel/debug/tasks/").Before("AdminOnly"), 284 ) 285 }