Beispiel #1
0
func init() {
	// beego.InsertFilter("/*", beego.BeforeRouter, checkFilter)
	ns := beego.NewNamespace("/v1",
		beego.NSNamespace("/dev",
			beego.NSInclude(
				&controllers.DevController{},
			),
			// beego.NSRouter("/register", &controllers.RegisterController{}),
		),
		beego.NSNamespace("/user",
			beego.NSBefore(check),
			beego.NSInclude(
				&controllers.UserController{},
			),
		),
		beego.NSNamespace("/character",
			beego.NSBefore(check),
			beego.NSInclude(
				&controllers.CharacterController{},
			),
		),
		beego.NSNamespace("/movie",
			beego.NSBefore(check),
			beego.NSInclude(
				&controllers.MovieController{},
			),
		),
		beego.NSNamespace("/music",
			beego.NSBefore(check),
			beego.NSInclude(
				&controllers.MusicController{},
			),
		),
	)
	//管理员权限
	admin_ns := beego.NewNamespace("/admin",
		beego.NSBefore(auth),
		beego.NSInclude(
			&admin.AdminController{},
		),
	)
	beego.AddNamespace(ns, admin_ns)
}
Beispiel #2
0
func init() {
	ns := beego.NewNamespace("/v1",
		beego.NSAfter(log_info),
		beego.NSRouter("/", &controllers.MainController{}),
		beego.NSRouter("/test", &controllers.TestController{}),
		beego.NSRouter("/status", &controllers.StatusController{}, "get:Any;post:Any"),
		beego.NSRouter("/matrix", &controllers.MatrixController{}),
		beego.NSRouter("/note:key([0-9]+).html", &controllers.TagController{}),
		beego.NSRouter("/article_:key([0-9]+).html", &controllers.BlogController{}, "get:ShowBlog"),
		beego.NSNamespace("/blog",
			beego.NSRouter("/", &controllers.BlogController{}, "get:ShowList;post:Post"),
		),
		beego.NSNamespace("/tag",
			beego.NSRouter("/", &controllers.TagController{}),
			beego.NSRouter("/:key([0-9]+).html", &controllers.TagController{}),
		),
		beego.NSNamespace("/msg",
			beego.NSRouter("/", &controllers.MessageController{}),
			beego.NSRouter("/leave", &controllers.MessageController{}, "post:Leave"),
		),
		beego.NSNamespace("/admin",
			beego.NSRouter("/", &controllers.MainController{}),
			beego.NSNamespace("/blog",
				beego.NSRouter("/new", &controllers.BlogController{}, "post:NewBlog;get:AddBlog"),
				beego.NSRouter("/", &controllers.BlogController{}, "get:ShowEditList"),
				beego.NSRouter("/:key([0-9]+).html", &controllers.BlogController{}, "get:EditBlog"),
			),
		),
	)

	// For API
	ns2 := beego.NewNamespace("v2",
		beego.NSBefore(auth),
		beego.NSRouter("/", &controllers.MainController{}),
	)
	beego.AddNamespace(ns)
	beego.AddNamespace(ns2)
}
Beispiel #3
0
func router() {
	authR := beego.NewNamespace("/auth",
		beego.NSCond(func(ctx *context.Context) bool {
			if ctx.Input.Domain() == "api.beego.me" {
				return true
			}
			commonFilter(ctx)
			return true
		}),
		// beego.NSBefore(func(ctx *context.Context) {
		// beego.Debug("path=>", ctx.Request.URL.Path)
		// services.etInstance().AuthService.WithContext(ctx, func() {
		// if services.GetInstance().AuthService.HasLogin() {
		// ctx.Redirect(200, "/admin/index")
		// }
		// })
		// }),
		beego.NSRouter("/login", &controllers.AuthController{}, "*:Login"),
		beego.NSRouter("/logout", &controllers.AuthController{}, "*:Logout"),
	)

	adminR := beego.NewNamespace("/admin",
		beego.NSBefore(func(ctx *context.Context) {
			commonFilter(ctx)
			services.GetInstance().AuthService.WithContext(ctx, func() {
				if !services.GetInstance().AuthService.HasLogin() {
					ctx.Redirect(302, "/auth/login")
				}
			})
		}),
		beego.NSRouter("/index", &controllers.AdminController{}, "*:Index"),
		beego.NSNamespace("/user",
			beego.NSGet("/info/:id", func(ctx *context.Context) {
				ctx.Output.Body([]byte("shopinfo"))
			}),
			beego.NSRouter("/list", &controllers.AdminController{}, "Get:UserList"),
			beego.NSRouter("/operate/?:userId", &controllers.AdminController{}, "*:UserOperate"),
			beego.NSRouter("/delete/:userId", &controllers.AdminController{}, "Get:UserDelete"),
		),
		beego.NSNamespace("/agent",
			beego.NSRouter("/list", &controllers.AdminController{}, "Get:AgentList"),
			beego.NSRouter("/operate/?:agentId", &controllers.AdminController{}, "*:AgentOperate"),
			beego.NSRouter("/delete/:agentId", &controllers.AdminController{}, "Get:AgentDelete"),
			beego.NSRouter("/:agentId/cmd/list", &controllers.AdminController{}, "Get:CmdList"),
			beego.NSRouter("/:agentId/cmd/operate", &controllers.AdminController{}, "*:CmdOperate"),
			beego.NSRouter("/:agentId/cmd/operate/?:cmdId", &controllers.AdminController{}, "*:CmdOperate"),
			beego.NSRouter("/cmd/delete/:cmdId", &controllers.AdminController{}, "Get:CmdDelete"),
		),
		beego.NSNamespace("/ssh",
			beego.NSRouter("/:agentId", &controllers.AdminController{}, "Get:SshIndex"),
			beego.NSRouter("/join/:agentId", &controllers.AdminController{}, "*:SshJoin"),
			beego.NSRouter("/list", &controllers.AdminController{}, "*:SshList"),
		),
		beego.NSNamespace("/server",
			beego.NSRouter("/index/?:serverId", &controllers.ServerController{}, "Get:Index"),
			beego.NSRouter("/operate/?:serverId", &controllers.ServerController{}, "*:Operate"),
			beego.NSRouter("/delete/:serverId", &controllers.ServerController{}, "Get:Delete"),
		),
	)

	guestR := beego.NewNamespace("/guest",
		beego.NSBefore(func(ctx *context.Context) {
			commonFilter(ctx)
		}),
		beego.NSNamespace("/server",
			beego.NSRouter("/share/:serverId", &controllers.ServerController{}, "Get:Share"),
			beego.NSRouter("/:serverId/active/:apiParamId", &controllers.ServerController{}, "*:Active"),
			beego.NSRouter("/:serverId/encode/:apiParamId", &controllers.ServerController{}, "Post:Encode"),
			beego.NSRouter("/info", &controllers.ServerController{}, "Get:Info"),
		),
	)

	//注册namespace
	beego.AddNamespace(authR, adminR, guestR)

}
Beispiel #4
0
func ConfigRoutes() {

	beego.Router("/root", &UserController{}, "get:CreateRoot")

	beego.Router("/auth/login", &AuthController{}, "get:LoginGet;post:LoginPost")
	beego.Router("/auth/register", &AuthController{}, "get:RegisterGet;post:RegisterPost")

	beego.Router("/sso/sig", &SsoController{}, "get:Sig")
	beego.Router("/sso/user/:sig:string", &SsoController{}, "get:User")
	beego.Router("/sso/logout/:sig:string", &SsoController{}, "get:Logout")

	beego.Router("/user/query", &UserController{}, "get:Query")
	beego.Router("/user/in", &UserController{}, "get:In")
	beego.Router("/user/qrcode/:id:int", &UserController{}, "get:QrCode")
	beego.Router("/about/:name:string", &UserController{}, "get:About")

	beego.Router("/team/users", &TeamController{}, "get:Users")
	beego.Router("/team/query", &TeamController{}, "get:Query")
	beego.Router("/team/all", &TeamController{}, "get:All")

	loginRequired :=
		beego.NewNamespace("/me",
			beego.NSCond(func(ctx *context.Context) bool {
				return true
			}),
			beego.NSBefore(base.FilterLoginUser),
			beego.NSRouter("/logout", &AuthController{}, "*:Logout"),
			beego.NSRouter("/info", &UserController{}, "get:Info"),
			beego.NSRouter("/profile", &UserController{}, "get:ProfileGet;post:ProfilePost"),
			beego.NSRouter("/chpwd", &UserController{}, "*:ChangePassword"),
			beego.NSRouter("/users", &UserController{}, "get:Users"),
			beego.NSRouter("/user/c", &UserController{}, "get:CreateUserGet;post:CreateUserPost"),
			beego.NSRouter("/teams", &TeamController{}, "get:Teams"),
			beego.NSRouter("/team/c", &TeamController{}, "get:CreateTeamGet;post:CreateTeamPost"),
		)

	beego.AddNamespace(loginRequired)

	targetUserRequired :=
		beego.NewNamespace("/target-user",
			beego.NSCond(func(ctx *context.Context) bool {
				return true
			}),
			beego.NSBefore(base.FilterLoginUser, base.FilterTargetUser),
			beego.NSRouter("/delete", &UserController{}, "*:DeleteUser"),
			beego.NSRouter("/edit", &UserController{}, "get:EditGet;post:EditPost"),
			beego.NSRouter("/chpwd", &UserController{}, "post:ResetPassword"),
			beego.NSRouter("/role", &UserController{}, "*:Role"),
		)

	beego.AddNamespace(targetUserRequired)

	targetTeamRequired :=
		beego.NewNamespace("/target-team",
			beego.NSCond(func(ctx *context.Context) bool {
				return true
			}),
			beego.NSBefore(base.FilterLoginUser, base.FilterTargetTeam),
			beego.NSRouter("/delete", &TeamController{}, "*:DeleteTeam"),
			beego.NSRouter("/edit", &TeamController{}, "get:EditGet;post:EditPost"),
		)

	beego.AddNamespace(targetTeamRequired)

}
Beispiel #5
0
func init() {

	beego.Router("/", &ctrls.Cand{}, "get:Index")
	beego.InsertFilter("/", beego.BeforeRouter, FilterUser)

	beego.Router("/login", &ctrls.Main{})
	beego.Router("/logout", &ctrls.Main{}, "get:Logout")

	ns :=
		beego.NewNamespace("/adm",
			beego.NSBefore(func(ctx *context.Context) {

				_, ok := ctx.Input.Session("uid").(int)

				if !ok {
					ctx.Redirect(302, "/login")
				}

			}),
			beego.NSNamespace("/users",
				beego.NSCond(FilterAdmin),
				beego.NSRouter("/list", &ctrls.User{}, "get:Index"),
				beego.NSRouter("/add", &ctrls.User{}, "get:Add;post:Post"),
				beego.NSRouter("/:id:int", &ctrls.User{}),
				beego.NSRouter("/:id:int/remove", &ctrls.User{}, "get:Remove"),
			),
			beego.NSNamespace("/dep",
				beego.NSRouter("/list", &ctrls.Dep{}, "get:Index"),
				beego.NSRouter("/add", &ctrls.Dep{}, "get:Add;post:Post"),
				beego.NSRouter("/:id:int", &ctrls.Dep{}),
				beego.NSRouter("/:id:int/remove", &ctrls.Dep{}, "get:Remove"),
			),
			beego.NSNamespace("/crit",
				beego.NSRouter("/list", &ctrls.Crit{}, "get:Index"),
				beego.NSRouter("/:id:int", &ctrls.Crit{}),
				beego.NSRouter("/add", &ctrls.Crit{}, "get:Add;post:Post"),
				beego.NSRouter("/:id:int/remove", &ctrls.Crit{}, "get:Remove"),
			),
			beego.NSNamespace("/candidates",
				beego.NSRouter("/list", &ctrls.Cand{}, "get:Index"),
				beego.NSRouter("/add", &ctrls.Cand{}, "get:Add;post:Post"),
				beego.NSRouter("/:id:int", &ctrls.Cand{}),
				beego.NSRouter("/:id:int/files", &ctrls.Download{}, "get:Index"),
				beego.NSRouter("/:id:int/contacts", &ctrls.Contact{}, "get:Index"),
				beego.NSRouter("/:id:int/contacts/add", &ctrls.Contact{}, "post:Add"),
				beego.NSRouter("/:id:int/contacts/:cid/remove", &ctrls.Contact{}, "get:Remove"),
				beego.NSRouter("/:id:int/edit", &ctrls.Cand{}, "get:Edit"),
				beego.NSRouter("/:id:int/remove", &ctrls.Cand{}, "get:Remove"),
			),
			beego.NSNamespace("/ratings",
				beego.NSRouter("/:id:int", &ctrls.Rat{}),
				beego.NSRouter("/detailed/:id:int", &ctrls.Rat{}, "get:GetDetailed"),
				beego.NSRouter("/my/:id:int", &ctrls.Rat{}, "get:GetUserRatings"),
				beego.NSRouter("/:id:int/remove", &ctrls.Rat{}, "get:Remove"),
			),
			beego.NSNamespace("/trash",
				beego.NSCond(FilterAdmin),
				beego.NSRouter("/list", &ctrls.Trash{}),
				beego.NSRouter("/restore/:type/:id", &ctrls.Trash{}, "get:Restore"),
			),

			beego.NSNamespace("/langs",
				beego.NSRouter("/list", &ctrls.Lang{}, "get:Index"),
				beego.NSRouter("/:id:int/set_default", &ctrls.Lang{}, "get:Default"),
				beego.NSRouter("/:id:int/remove", &ctrls.Lang{}, "get:Remove"),
				beego.NSRouter("/:id:int/upload", &ctrls.Lang{}, "post:Upload"),
				beego.NSRouter("/:id:int/download", &ctrls.Lang{}, "get:Download"),
				beego.NSRouter("/add", &ctrls.Lang{}, "post:Add"),
			),
			beego.NSNamespace("/issues",
				beego.NSRouter("/labels", &ctrls.Issue{}, "get:GetLabels"),
				beego.NSRouter("/report", &ctrls.Issue{}, "post:ReportIssue"),
			),

			beego.NSNamespace("/comments",
				beego.NSRouter("/:id:int", &ctrls.Comments{}),
				beego.NSRouter("/:id:int/edit", &ctrls.Comments{}, "post:Edit"),
				beego.NSRouter("/:id:int/remove", &ctrls.Comments{}, "get:Remove"),
			),
			beego.NSRouter("/search", &ctrls.Cand{}, "get:Search"),
			beego.NSRouter("/profile", &ctrls.Prof{}),

			beego.NSRouter("/upload/:id:int", &ctrls.Upload{}, "post:Index"),
			beego.NSRouter("/upload/img/:id:int", &ctrls.Upload{}, "post:Img"),
			beego.NSRouter("/download/:id:int", &ctrls.Download{}, "get:Get"),
			beego.NSRouter("/download/:id:int/remove", &ctrls.Download{}, "post:Remove"),
			beego.NSRouter("/ratings/:id:int", &ctrls.Rat{}),
			beego.NSRouter("/ratings/detailed/:id:int", &ctrls.Rat{}, "get:GetDetailed"),
			beego.NSRouter("/ratings/my/:id:int", &ctrls.Rat{}, "get:GetUserRatings"),
			beego.NSRouter("/ratings/:id:int/remove", &ctrls.Rat{}, "get:Remove"),
			beego.NSNamespace("/debug",
				beego.NSRouter("/lastlog", &ctrls.Debug{}, "get:LastLog"),
			),
		)

	beego.AddNamespace(ns)
}
Beispiel #6
0
func ConfigRoutes() {

	//open-falcon's routes
	beego.Router("/root", &UserController{}, "get:CreateRoot")
	beego.Router("/auth/login", &AuthController{}, "get:LoginGet;post:LoginPost")
	beego.Router("/auth/login/:token", &AuthController{}, "get:LoginWithToken")
	beego.Router("/auth/third-party", &AuthController{}, "post:LoginThirdParty")
	beego.Router("/auth/register", &AuthController{}, "get:RegisterGet;post:RegisterPost")

	beego.Router("/sso/sig", &SsoController{}, "get:Sig")
	beego.Router("/sso/user/:sig:string", &SsoController{}, "get:User")
	beego.Router("/sso/logout/:sig:string", &SsoController{}, "get:Logout")

	beego.Router("/user/query", &UserController{}, "get:Query")
	beego.Router("/user/in", &UserController{}, "get:In")
	beego.Router("/user/qrcode/:id:int", &UserController{}, "get:QrCode")
	beego.Router("/about/:name:string", &UserController{}, "get:About")

	beego.Router("/team/users", &TeamController{}, "get:Users")
	beego.Router("/team/query", &TeamController{}, "get:Query")
	beego.Router("/team/all", &TeamController{}, "get:All")

	//owl-protal-routes
	apins := beego.NewNamespace("/api/v1/auth",
		beego.NSGet("/notallowed", func(ctx *context.Context) {
			ctx.Output.Body([]byte("notAllowed"))
		}),
		beego.NSRouter("/register", &AuthApiController{}, "post:Register"),
		beego.NSRouter("/login", &AuthApiController{}, "post:Login"),
		beego.NSRouter("/sessioncheck", &AuthApiController{}, "get:AuthSession;post:AuthSession"),
		beego.NSRouter("/logout", &AuthApiController{}, "get:Logout;post:Logout"),
		beego.NSRouter("/user", &AuthApiController{}, "post:GetUser"),
		beego.NSRouter("/user/update", &AuthApiController{}, "put:UpdateUser;post:UpdateUser"),
		beego.NSRouter("/team/count", &AuthApiController{}, "get:CountNumOfTeam;post:CountNumOfTeam"),
	)
	beego.AddNamespace(apins)

	loginRequired :=
		beego.NewNamespace("/me",
			beego.NSCond(func(ctx *context.Context) bool {
				return true
			}),
			beego.NSBefore(base.FilterLoginUser),
			beego.NSRouter("/logout", &AuthController{}, "*:Logout"),
			beego.NSRouter("/info", &UserController{}, "get:Info"),
			beego.NSRouter("/profile", &UserController{}, "get:ProfileGet;post:ProfilePost"),
			beego.NSRouter("/chpwd", &UserController{}, "*:ChangePassword"),
			beego.NSRouter("/users", &UserController{}, "get:Users"),
			beego.NSRouter("/user/c", &UserController{}, "get:CreateUserGet;post:CreateUserPost"),
			beego.NSRouter("/teams", &TeamController{}, "get:Teams"),
			beego.NSRouter("/team/c", &TeamController{}, "get:CreateTeamGet;post:CreateTeamPost"),
		)

	beego.AddNamespace(loginRequired)

	targetUserRequired :=
		beego.NewNamespace("/target-user",
			beego.NSCond(func(ctx *context.Context) bool {
				return true
			}),
			beego.NSBefore(base.FilterLoginUser, base.FilterTargetUser),
			beego.NSRouter("/delete", &UserController{}, "*:DeleteUser"),
			beego.NSRouter("/edit", &UserController{}, "get:EditGet;post:EditPost"),
			beego.NSRouter("/chpwd", &UserController{}, "post:ResetPassword"),
			beego.NSRouter("/role", &UserController{}, "*:Role"),
		)

	beego.AddNamespace(targetUserRequired)

	targetTeamRequired :=
		beego.NewNamespace("/target-team",
			beego.NSCond(func(ctx *context.Context) bool {
				return true
			}),
			beego.NSBefore(base.FilterLoginUser, base.FilterTargetTeam),
			beego.NSRouter("/delete", &TeamController{}, "*:DeleteTeam"),
			beego.NSRouter("/edit", &TeamController{}, "get:EditGet;post:EditPost"),
		)

	beego.AddNamespace(targetTeamRequired)

}