2017-04-12 10:10:36 +00:00
|
|
|
package main
|
|
|
|
|
2017-10-31 07:26:44 +00:00
|
|
|
type RouteImpl struct {
|
2017-11-05 09:55:34 +00:00
|
|
|
Name string
|
|
|
|
Path string
|
|
|
|
Vars []string
|
|
|
|
RunBefore []Runnable
|
2017-04-12 10:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type RouteGroup struct {
|
2017-10-30 09:57:08 +00:00
|
|
|
Path string
|
2017-10-31 07:26:44 +00:00
|
|
|
RouteList []*RouteImpl
|
2017-11-05 09:55:34 +00:00
|
|
|
RunBefore []Runnable
|
|
|
|
}
|
|
|
|
|
|
|
|
type Runnable struct {
|
|
|
|
Contents string
|
|
|
|
Literal bool
|
2017-04-12 10:10:36 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 09:55:34 +00:00
|
|
|
func addRoute(route *RouteImpl) {
|
|
|
|
routeList = append(routeList, route)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (route *RouteImpl) Before(item string, literal ...bool) *RouteImpl {
|
|
|
|
var litItem bool
|
|
|
|
if len(literal) > 0 {
|
|
|
|
litItem = literal[0]
|
|
|
|
}
|
|
|
|
route.RunBefore = append(route.RunBefore, Runnable{item, litItem})
|
|
|
|
return route
|
2017-04-12 10:10:36 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 07:26:44 +00:00
|
|
|
func newRouteGroup(path string, routes ...*RouteImpl) *RouteGroup {
|
2017-11-05 09:55:34 +00:00
|
|
|
return &RouteGroup{path, routes, []Runnable{}}
|
2017-10-30 09:57:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func addRouteGroup(routeGroup *RouteGroup) {
|
|
|
|
routeGroups = append(routeGroups, routeGroup)
|
|
|
|
}
|
|
|
|
|
2017-11-05 09:55:34 +00:00
|
|
|
func (group *RouteGroup) Before(line string, literal ...bool) *RouteGroup {
|
|
|
|
var litItem bool
|
|
|
|
if len(literal) > 0 {
|
|
|
|
litItem = literal[0]
|
|
|
|
}
|
|
|
|
group.RunBefore = append(group.RunBefore, Runnable{line, litItem})
|
|
|
|
return group
|
2017-10-30 09:57:08 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 07:26:44 +00:00
|
|
|
func (group *RouteGroup) Routes(routes ...*RouteImpl) {
|
2017-10-30 09:57:08 +00:00
|
|
|
group.RouteList = append(group.RouteList, routes...)
|
2017-04-12 10:10:36 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 07:26:44 +00:00
|
|
|
func blankRoute() *RouteImpl {
|
2017-11-05 09:55:34 +00:00
|
|
|
return &RouteImpl{"", "", []string{}, []Runnable{}}
|
2017-10-31 07:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Route(fname string, path string, args ...string) *RouteImpl {
|
2017-11-05 09:55:34 +00:00
|
|
|
return &RouteImpl{fname, path, args, []Runnable{}}
|
2017-10-31 07:26:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 10:10:36 +00:00
|
|
|
func routes() {
|
2017-04-13 09:26:40 +00:00
|
|
|
//addRoute("default_route","","")
|
2017-11-05 09:55:34 +00:00
|
|
|
addRoute(Route("routeAPI", "/api/"))
|
2017-09-11 10:24:03 +00:00
|
|
|
///addRoute("routeStatic","/static/","req.URL.Path += extra_data")
|
2017-11-05 09:55:34 +00:00
|
|
|
addRoute(Route("routeOverview", "/overview/"))
|
2017-09-11 10:24:03 +00:00
|
|
|
//addRoute("routeCustomPage","/pages/",""/*,"&extra_data"*/)
|
2017-11-05 09:55:34 +00:00
|
|
|
addRoute(Route("routeForums", "/forums/" /*,"&forums"*/))
|
|
|
|
addRoute(Route("routeForum", "/forum/", "extra_data"))
|
2017-09-11 10:24:03 +00:00
|
|
|
//addRoute("routeTopicCreate","/topics/create/","","extra_data")
|
|
|
|
//addRoute("routeTopics","/topics/",""/*,"&groups","&forums"*/)
|
2017-11-05 09:55:34 +00:00
|
|
|
addRoute(Route("routeChangeTheme", "/theme/"))
|
|
|
|
addRoute(Route("routeShowAttachment", "/attachs/", "extra_data"))
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-10-30 09:57:08 +00:00
|
|
|
reportGroup := newRouteGroup("/report/",
|
2017-11-05 09:55:34 +00:00
|
|
|
Route("routeReportSubmit", "/report/submit/", "extra_data"),
|
|
|
|
).Before("MemberOnly")
|
2017-10-30 09:57:08 +00:00
|
|
|
addRouteGroup(reportGroup)
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-10-30 09:57:08 +00:00
|
|
|
topicGroup := newRouteGroup("/topics/",
|
2017-10-31 07:26:44 +00:00
|
|
|
Route("routeTopics", "/topics/"),
|
2017-11-05 09:55:34 +00:00
|
|
|
Route("routeTopicCreate", "/topics/create/", "extra_data").Before("MemberOnly"),
|
2017-04-13 09:26:40 +00:00
|
|
|
)
|
2017-10-30 09:57:08 +00:00
|
|
|
addRouteGroup(topicGroup)
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-10-31 07:26:44 +00:00
|
|
|
buildPanelRoutes()
|
2017-11-05 09:55:34 +00:00
|
|
|
buildUserRoutes()
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Test the email token route
|
|
|
|
// TODO: Add a BeforeExcept method?
|
|
|
|
func buildUserRoutes() {
|
|
|
|
userGroup := newRouteGroup("/user/") //.Before("MemberOnly")
|
|
|
|
userGroup.Routes(
|
|
|
|
Route("routeProfile", "/user/").Before("req.URL.Path += extra_data", true),
|
|
|
|
Route("routeAccountOwnEditCritical", "/user/edit/critical/").Before("MemberOnly"),
|
|
|
|
Route("routeAccountOwnEditCriticalSubmit", "/user/edit/critical/submit/").Before("MemberOnly"),
|
|
|
|
Route("routeAccountOwnEditAvatar", "/user/edit/avatar/").Before("MemberOnly"),
|
|
|
|
Route("routeAccountOwnEditAvatarSubmit", "/user/edit/avatar/submit/").Before("MemberOnly"),
|
|
|
|
Route("routeAccountOwnEditUsername", "/user/edit/username/").Before("MemberOnly"),
|
|
|
|
Route("routeAccountOwnEditUsernameSubmit", "/user/edit/username/submit/").Before("MemberOnly"),
|
|
|
|
Route("routeAccountOwnEditEmail", "/user/edit/email/").Before("MemberOnly"),
|
|
|
|
Route("routeAccountOwnEditEmailTokenSubmit", "/user/edit/token/", "extra_data").Before("MemberOnly"),
|
|
|
|
)
|
|
|
|
addRouteGroup(userGroup)
|
2017-10-31 07:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func buildPanelRoutes() {
|
2017-11-05 09:55:34 +00:00
|
|
|
panelGroup := newRouteGroup("/panel/").Before("SuperModOnly")
|
2017-10-30 09:57:08 +00:00
|
|
|
panelGroup.Routes(
|
2017-10-31 07:26:44 +00:00
|
|
|
Route("routePanel", "/panel/"),
|
|
|
|
Route("routePanelForums", "/panel/forums/"),
|
|
|
|
Route("routePanelForumsCreateSubmit", "/panel/forums/create/"),
|
2017-11-05 09:55:34 +00:00
|
|
|
Route("routePanelForumsDelete", "/panel/forums/delete/", "extra_data"),
|
|
|
|
Route("routePanelForumsDeleteSubmit", "/panel/forums/delete/submit/", "extra_data"),
|
|
|
|
Route("routePanelForumsEdit", "/panel/forums/edit/", "extra_data"),
|
|
|
|
Route("routePanelForumsEditSubmit", "/panel/forums/edit/submit/", "extra_data"),
|
|
|
|
Route("routePanelForumsEditPermsSubmit", "/panel/forums/edit/perms/submit/", "extra_data"),
|
2017-10-31 07:26:44 +00:00
|
|
|
|
|
|
|
Route("routePanelSettings", "/panel/settings/"),
|
2017-11-05 09:55:34 +00:00
|
|
|
Route("routePanelSetting", "/panel/settings/edit/", "extra_data"),
|
|
|
|
Route("routePanelSettingEdit", "/panel/settings/edit/submit/", "extra_data"),
|
2017-10-31 07:26:44 +00:00
|
|
|
|
|
|
|
Route("routePanelWordFilters", "/panel/settings/word-filters/"),
|
|
|
|
Route("routePanelWordFiltersCreate", "/panel/settings/word-filters/create/"),
|
2017-11-05 09:55:34 +00:00
|
|
|
Route("routePanelWordFiltersEdit", "/panel/settings/word-filters/edit/", "extra_data"),
|
|
|
|
Route("routePanelWordFiltersEditSubmit", "/panel/settings/word-filters/edit/submit/", "extra_data"),
|
|
|
|
Route("routePanelWordFiltersDeleteSubmit", "/panel/settings/word-filters/delete/submit/", "extra_data"),
|
2017-10-31 07:26:44 +00:00
|
|
|
|
|
|
|
Route("routePanelThemes", "/panel/themes/"),
|
2017-11-05 09:55:34 +00:00
|
|
|
Route("routePanelThemesSetDefault", "/panel/themes/default/", "extra_data"),
|
2017-10-31 07:26:44 +00:00
|
|
|
|
|
|
|
Route("routePanelPlugins", "/panel/plugins/"),
|
2017-11-05 09:55:34 +00:00
|
|
|
Route("routePanelPluginsActivate", "/panel/plugins/activate/", "extra_data"),
|
|
|
|
Route("routePanelPluginsDeactivate", "/panel/plugins/deactivate/", "extra_data"),
|
|
|
|
Route("routePanelPluginsInstall", "/panel/plugins/install/", "extra_data"),
|
2017-10-31 07:26:44 +00:00
|
|
|
|
|
|
|
Route("routePanelUsers", "/panel/users/"),
|
2017-11-05 09:55:34 +00:00
|
|
|
Route("routePanelUsersEdit", "/panel/users/edit/", "extra_data"),
|
|
|
|
Route("routePanelUsersEditSubmit", "/panel/users/edit/submit/", "extra_data"),
|
2017-10-31 07:26:44 +00:00
|
|
|
|
|
|
|
Route("routePanelGroups", "/panel/groups/"),
|
2017-11-05 09:55:34 +00:00
|
|
|
Route("routePanelGroupsEdit", "/panel/groups/edit/", "extra_data"),
|
|
|
|
Route("routePanelGroupsEditPerms", "/panel/groups/edit/perms/", "extra_data"),
|
|
|
|
Route("routePanelGroupsEditSubmit", "/panel/groups/edit/submit/", "extra_data"),
|
|
|
|
Route("routePanelGroupsEditPermsSubmit", "/panel/groups/edit/perms/submit/", "extra_data"),
|
2017-10-31 07:26:44 +00:00
|
|
|
Route("routePanelGroupsCreateSubmit", "/panel/groups/create/"),
|
|
|
|
|
2017-11-05 09:55:34 +00:00
|
|
|
Route("routePanelBackups", "/panel/backups/", "extra_data"),
|
2017-10-31 07:26:44 +00:00
|
|
|
Route("routePanelLogsMod", "/panel/logs/mod/"),
|
|
|
|
Route("routePanelDebug", "/panel/debug/"),
|
2017-04-13 10:55:51 +00:00
|
|
|
)
|
2017-10-30 09:57:08 +00:00
|
|
|
addRouteGroup(panelGroup)
|
2017-04-12 10:10:36 +00:00
|
|
|
}
|