Exemple #1
0
func main() {
	beego.SessionOn = true
	beego.InsertFilter("/appadmin/*", beego.BeforeRouter, auth.Basic("youradminname", "YourAdminPassword"))
	beego.InsertFilter("/hosts", beego.BeforeRouter, controllers.FilterLogin)
	beego.InsertFilter("/hosts/*", beego.BeforeRouter, controllers.FilterLogin)
	beego.Run()
}
Exemple #2
0
func Init() {
	beego.InsertFilter("*", beego.BeforeRouter, filterPostMethods)

	beego.InsertFilter("/steps/*", beego.BeforeExec, filterUser)
	beego.InsertFilter("/sites/*", beego.BeforeExec, filterUser)
	beego.InsertFilter("/sites/*", beego.BeforeExec, filterSiteOwner)
}
Exemple #3
0
// create a instance and create filter
func NewWithFilter(urlPrefix string, socialAuther SocialAuther) *SocialAuth {
	social := NewSocial(urlPrefix, socialAuther)

	beego.InsertFilter(social.URLPrefix+"*/access", beego.BeforeRouter, social.handleAccess)
	beego.InsertFilter(social.URLPrefix+"*", beego.BeforeRouter, social.handleRedirect)

	return social
}
Exemple #4
0
func main() {
	beego.InsertFilter("/gui/*", beego.BeforeRouter, identity.FilterUser)
	beego.InsertFilter("/api/v1/*", beego.BeforeRouter, restapiidentity.FilterToken)
	beego.InsertFilter("/guirestapi/v1/*", beego.BeforeRouter, identity.FilterUser)

	beego.AppConfigPath = "/etc/cloudone_gui/app.conf"

	beego.Run()
}
Exemple #5
0
func init() {
	beego.Router("/", &controllers.IndexController{})
	beego.Router("/channels", &controllers.ChatController{}, "get:Index")
	beego.Router("/channels/new", &controllers.ChatController{}, "get,post:New")
	beego.Router("/channels/:id:int", &controllers.ChatController{}, "get:View")
	beego.Router("/users/login", &controllers.UserController{}, "get,post:Login")
	beego.Router("/users/logout", &controllers.UserController{}, "get,post:Logout")
	beego.Router("/users/register", &controllers.UserController{}, "get,post:Register")

	beego.InsertFilter("/*", beego.BeforeRouter, FilterUser)
	beego.InsertFilter("/channels/*", beego.BeforeRouter, FilterAuth)
}
Exemple #6
0
func main() {
	beego.InsertFilter("*", beego.BeforeRouter, func(ctx *context.Context) {
		startTime := time.Now()
		ctx.Input.SetData("stats_timer", startTime)
	})
	beego.InsertFilter("*", beego.FinishRouter, func(ctx *context.Context) {
		Stats.EndWithStatus(ctx.Input.GetData("stats_timer").(time.Time), ctx.Output.Status)
	})

	beego.Router("/stats", &StatsController{})

	beego.Run()
}
Exemple #7
0
func SocialAuthInit() {
	var clientId, secret string
	var err error
	appURL := beego.AppConfig.String("social_auth_url")
	if len(appURL) > 0 {
		social.DefaultAppUrl = appURL
	}

	clientId = beego.AppConfig.String("github_client_id")
	secret = beego.AppConfig.String("github_client_secret")
	err = social.RegisterProvider(apps.NewGithub(clientId, secret))
	if err != nil {
		beego.Error(err)
	}

	clientId = beego.AppConfig.String("google_client_id")
	secret = beego.AppConfig.String("google_client_secret")
	err = social.RegisterProvider(apps.NewGoogle(clientId, secret))
	if err != nil {
		beego.Error(err)
	}

	clientId = beego.AppConfig.String("weibo_client_id")
	secret = beego.AppConfig.String("weibo_client_secret")
	err = social.RegisterProvider(apps.NewWeibo(clientId, secret))
	if err != nil {
		beego.Error(err)
	}

	clientId = beego.AppConfig.String("qq_client_id")
	secret = beego.AppConfig.String("qq_client_secret")
	err = social.RegisterProvider(apps.NewQQ(clientId, secret))
	if err != nil {
		beego.Error(err)
	}

	clientId = beego.AppConfig.String("renren_client_id")
	secret = beego.AppConfig.String("renren_client_secret")
	err = social.RegisterProvider(apps.NewRenren(clientId, secret))
	if err != nil {
		beego.Error(err)
	}

	socialAuth.SocialAuth = social.NewSocial("/register/connect", new(socialAuth.SocialAuther))
	socialAuth.SocialAuth.ConnectSuccessURL = "/register/connect"
	beego.InsertFilter("/login", beego.BeforeRouter, filter.HandleAccess)
	beego.InsertFilter("/", beego.BeforeRouter, filter.HandleAccess)
	beego.InsertFilter("/login/*/access", beego.BeforeRouter, socialAuth.HandleAccess)
	beego.InsertFilter("/login/*", beego.BeforeRouter, socialAuth.HandleRedirect)
}
Exemple #8
0
func main() {
	// Database alias.
	name := "default"

	// Drop table and re-create.
	force := true

	// Print log.
	verbose := true

	// Error.
	err := orm.RunSyncdb(name, force, verbose)
	if err != nil {
		fmt.Println(err)
	}
	o := orm.NewOrm()
	o.Using("default")
	seed(o)

	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowAllOrigins: true,
	}))

	beego.Run()
}
Exemple #9
0
func main() {

	initialize()

	beego.Info(beego.AppName, APP_VER)

	beego.InsertFilter("/docs/images/:all", beego.BeforeRouter, routers.DocsStatic)

	if !routers.IsPro {
		beego.SetStaticPath("/static_source", "static_source")
		beego.DirectoryIndex = true
	}

	beego.SetStaticPath("/products/images", "products/images/")

	// Register routers.
	beego.Router("/", &routers.HomeRouter{})
	beego.Router("/community", &routers.CommunityRouter{})
	beego.Router("/quickstart", &routers.QuickStartRouter{})
	beego.Router("/video", &routers.VideoRouter{})
	beego.Router("/products", &routers.ProductsRouter{})
	beego.Router("/team", &routers.PageRouter{})
	beego.Router("/about", &routers.AboutRouter{})
	beego.Router("/donate", &routers.DonateRouter{})
	beego.Router("/docs/", &routers.DocsRouter{})
	beego.Router("/docs/:all", &routers.DocsRouter{})
	beego.Router("/blog", &routers.BlogRouter{})
	beego.Router("/blog/:all", &routers.BlogRouter{})

	// Register template functions.
	beego.AddFuncMap("i18n", i18n.Tr)

	beego.Run()
}
Exemple #10
0
func init() {
	/*ns := beego.NewNamespace("/v1",
		beego.NSNamespace("/object",
			beego.NSInclude(
				&controllers.ObjectController{},
			),
		),
		beego.NSNamespace("/user",
			beego.NSInclude(
				&controllers.UserController{},
			),
		),

		beego.NSNamespace("/worker",
			//beego.NSNamespace("/querybagreq",
				beego.NSInclude(
					&controllers.WorkerController{},
				),
			//),
		),
	)
	beego.AddNamespace(ns)*/

	beego.Router("/v1/user", &controllers.UserController{})
	beego.Router("/v1/worker/querybagreq/:workerid/:token", &controllers.WorkerController{}, "get:Querybagreq")
	beego.Router("/v1/worker/getbagreq/:workerid/:token", &controllers.WorkerController{}, "get:Getbagreq")
	beego.Router("/v1/worker/getbagreqlist/:workerid/:token", &controllers.WorkerController{}, "get:GetbagreqList")
	beego.Router("/v1/worker/getworkerid", &controllers.WorkerController{}, "get:GetWorkerId")

	beego.Router("/v1/worker/postworkerinfo", &controllers.WorkerController{}, "*:PostWorkerInfo")
	beego.Router("/v1/worker/postworkerinfo1/:workerid/:token", &controllers.WorkerController{}, "post:PostWorkerInfo1")

	beego.InsertFilter("/v1/worker/getworkerid", beego.BeforeRouter, FilterUser)
}
func init() {
	beego.Router("/", &controllers.RootController{})
	beego.Router("/login/?:dest", &controllers.LoginController{})
	beego.Router("/logout/?:dest", &controllers.LogoutController{})
	beego.Router("/signup/?:dest", &controllers.SignupController{})
	beego.Router("/live-editor/", &controllers.LiveEditorController{})
	beego.Router("/graphics-animation/", &controllers.GraphicsController{})
	beego.Router("/external/:file", &controllers.LiveEditorController{})

	beego.SetStaticPath("/build", "bootstrap/live-editor/build")

	var FilterUser = func(ctx *context.Context) {
		_, ok := ctx.Input.Session("uid").(int)
		if !ok {
			ctx.Redirect(302, "/login")
		}
	}

	beego.InsertFilter("/user/:id([0-9]+)", beego.BeforeRouter, FilterUser)

	beego.ErrorController(&controllers.ErrorController{})
	beego.SetLogger("file", `{"filename":"log/spielplatz.log"}`)

	loadLanguages()
}
Exemple #12
0
func RegisterControllers() {
	//register maincontroller
	mc := new(MainController)
	beego.Router("/", mc, "get:Index")
	beego.Router("/index", mc, "get:Index")
	beego.Router("/extractor", mc, "get:Index") //react-router history route

	// "robot.txt"
	beego.Router("/robot.txt", &RobotRouter{})

	// Add Filters
	//todo:enable image filter later
	//  beego.InsertFilter("/img/*", beego.BeforeRouter, attachment.ImageFilter)

	beego.InsertFilter("/captcha/*", beego.BeforeRouter, setting.Captcha.Handler)
	//register user related controllers
	user.RegisterRoutes()
	userApi.RegisterRoutes()

	extractor := &magic.ExtractorController{}
	beego.Router("/api/extractor/parse", extractor, "get:Parse")

	//experiment
	exp := new(experiment.ExperimentController)
	beego.Router("/experiment", exp, "get:Index;post:Post")
}
Exemple #13
0
func main() {
	core.Router_register()
	sso.Router_register()
	im.Router_register()
	schedule.Router_register()
	pay.Router_register()

	fmt.Println(beego.AppConfig.String("mysqluser"))
	fmt.Println(beego.AppConfig.String("mysqlpass"))
	fmt.Println(beego.AppConfig.String("mysqlurls"))
	fmt.Println(beego.AppConfig.String("mysqldb"))

	var FilterUser = func(ctx *context.Context) {
		if v := ctx.Input.Query("access_token"); v != "" {
			//data := "ok"
			fmt.Println(v)
			//ctx.Output.Json(data, false, true)
		} else {
			data := `{"error","err"}`
			ctx.Output.Json(data, false, true)
		}
	}

	beego.InsertFilter("*", beego.BeforeRouter, FilterUser)

	beego.Run()
}
func CheckAccessAndRegisterRes() {
	var Check = func(ctx *context.Context) {
		user_auth_type, _ := strconv.Atoi(beego.AppConfig.String("user_auth_type"))
		auth_gateway := beego.AppConfig.String("auth_gateway")
		var accessList map[string]bool
		if user_auth_type > 0 {
			params := strings.Split(strings.ToLower(ctx.Request.RequestURI), "/")
			if CheckAccess(params) {
				// 获取session value
				uinfo := ctx.Input.Session("userinfo")
				if uinfo == nil {
					ctx.Redirect(302, auth_gateway)
				}
				adminUser := beego.AppConfig.String("admin_user")
				//直接通过认证
				if uinfo.(User).Uname == adminUser {
					return
				}
				if user_auth_type == 1 {
					sessions := ctx.Input.Session("accesss")
					if sessions != nil {
						accessList = sessions.(map[string]bool)
					}
				} else if user_auth_type == 2 {
					accessList, _ = GetAccessList(uinfo.(User).Id)
				}
				ret := AccessDecision(params, accessList)
				if !ret {
					ctx.Output.Json(&map[string]interface{}{"status": false, "info": "权限不足"}, true, false)
				}
			}
		}
	}
	beego.InsertFilter("/", beego.BeforeRouter, Check)
}
Exemple #15
0
func init() {
	// config
	beego.BConfig.WebConfig.Session.SessionOn = true
	beego.BConfig.WebConfig.Session.SessionName = "SESSIONID"
	beego.BConfig.WebConfig.Session.SessionCookieLifeTime = ONE_DAYS
	beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = 3600

	beego.Router("/", &controllers.HomeController{})
	beego.Router("/p/:page([0-9]+)", &controllers.HomeController{})
	beego.Router("/cat/:cat([a-zA-Z]+)", &controllers.CategoryController{})
	beego.Router("/cat/:cat([a-zA-Z]+)/p/:page([0-9]+)", &controllers.CategoryController{})
	beego.Router("/tag/:tag([a-zA-Z0-9\u4e00-\u9fa5]+)", &controllers.TagController{})
	beego.Router("/tag/:tag([a-zA-Z0-9\u4e00-\u9fa5]+)/p/:page([0-9]+)", &controllers.TagController{})
	beego.Router("/:year([0-9]{4})/:month([0-9]{2})/:day([0-9]{2})/:id([0-9]+).html", &controllers.TopicController{})
	beego.Router("/archives/:year([0-9]{4})/:month([0-9]{2})", &controllers.ArchivesController{})
	beego.Router("/message", &controllers.MessageController{})
	beego.Router("/about", &controllers.AboutController{})
	beego.Router("/search", &controllers.SearchController{})
	// admin
	beego.Router("/login", &background.AuthController{})
	beego.InsertFilter("/admin/*", beego.BeforeRouter, FilterUser)
	beego.Router("/admin/user", &background.UserController{})
	beego.Router("/admin/data", &background.DataController{})
	beego.Router("/admin/topics", &background.TopicsController{})
	beego.Router("/admin/category", &background.CategoryController{})
	beego.Router("/admin/message", &background.MessageController{})
	beego.Router("/admin/social", &background.SocialController{})
	beego.Router("/admin/blogroll", &background.BlogrollController{})
	beego.Router("/admin/ad", &background.ADController{})
	beego.Router("/admin/sysconfig", &background.SysconfigController{})
	beego.Router("/admin/databackup", &background.DataBackupRecover{})
	beego.Router("/admin/datarecover", &background.DataBackupRecover{})
	beego.Router("/admin/syslog", &background.SyslogController{})
	beego.Router("/admin/trash", &background.TrashController{})
	// proxy
	beego.Router("/proxy/:url(.*)", &proxy.ProxyController{})
	// rss
	beego.Get("/feed", feed.Feed)
	beego.Get("/sitemap", feed.SiteMap)
	beego.Get("/robots.txt", feed.Robots)
	// 404
	beego.ErrorHandler("404", HTTPNotFound)
	// redirect https
	beego.InsertFilter("*", beego.BeforeRouter, RedirectHttps)
	// plugin
	beego.Router("/plugin/useragent.html", &plugin.UserAgent{})
}
Exemple #16
0
func main() {
	initDb()
	beego.InsertFilter("/*", beego.BeforeRouter, FilterUser)
	wbconf.LoadCategory()
	beego.SetLogger("file", `{"filename":"logs/running.log", "level":6 }`)
	beego.Run()

}
Exemple #17
0
func testOnly() {
	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowAllOrigins: true,
		AllowMethods:    []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowHeaders:    []string{"Origin", "Authorization", "Access-Control-Allow-Origin"},
		ExposeHeaders:   []string{"Content-Length", "Access-Control-Allow-Origin"},
	}))
}
Exemple #18
0
func AddFiltertOne() {
	var FilterLog = func(ctx *context.Context) {
		var name string
		ctx.Input.Bind(&name, "name")
		log.Println("FilterLog name:", name)
	}
	beego.InsertFilter("/annotation/*", beego.BeforeRouter, FilterLog)
}
Exemple #19
0
func init() {
	beego.InsertFilter("/main", beego.BeforeRouter, FilterUser)
	//beego.Router("/", &controllers.MainController{})
	beego.Router("/", &controllers.LoginController{})
	beego.Router("/login", &controllers.LoginController{})
	beego.AutoRouter(&controllers.LoginController{})
	beego.Router("/main", &controllers.MainController{})
	beego.AutoRouter(&controllers.MainController{})
}
Exemple #20
0
func init() {
	// 注册模型
	orm.Debug = true
	orm.RegisterModel(new(models.User), new(models.Tenant), new(models.Org))
	RegisterDB()
	InitSession()
	beego.InsertFilter("/index", beego.BeforeExec, models.IsUserLogin)

}
Exemple #21
0
func init() {
	// 添加控制器拦截器
	var FilterLog = func(ctx *context.Context) {
		var name string
		ctx.Input.Bind(&name, "name")
		log.Println("controllers FilterLog name:", name)
	}
	beego.InsertFilter("/annotation/*", beego.BeforeRouter, FilterLog)
}
Exemple #22
0
func init() {

	//Filter
	beego.InsertFilter("/", beego.BeforeRouter, FilterHome)
	beego.InsertFilter("/*", beego.BeforeRouter, FilterHome)

	beego.InsertFilter("/incident-manager/admin/*", beego.BeforeRouter, FilterAdmin)
	beego.InsertFilter("/incident-manager/admin/", beego.BeforeRouter, FilterAdmin)

	beego.InsertFilter("/incident-manager/user/*", beego.BeforeRouter, FilterUser)
	beego.InsertFilter("/incident-manager/user/", beego.BeforeRouter, FilterUser)
	beego.InsertFilter("/incident-manager/", beego.BeforeRouter, FilterUser)

	beego.InsertFilter("/incident-manager/user/*", beego.BeforeRouter, FilterLogin)
	beego.InsertFilter("/incident-manager/admin/*", beego.BeforeRouter, FilterLogin)

	//User Router
	beego.Router("/incident-manager/", &user.IndexController{}, "post,get:Get")
	beego.Router("/incident-manager/login", &auth.LoginController{}, "post,get:Login")
	beego.Router("/incident-manager/register", &auth.RegisterController{}, "post,get:Register")
	beego.Router("/mail/confirmation/:mail([-0-9a-z]+)", &auth.RegisterController{}, "post,get:Password")
	beego.Router("/incident-manager/logout", &auth.LogoutController{}, "post,get:Logout")
	beego.Router("/incident-manager/user/declaration", &user.IndexController{}, "get,post:Add")
	beego.Router("/incident-manager/user/myincident", &user.IndexController{}, "get,post:ByMail")
	beego.Router("/incident-manager/user/incident/:id([0-9]+)", &user.IndexController{}, "get:GetOne")
	beego.Router("/incident-manager/user/incident/update/:id([0-9]+)", &user.IndexController{}, "post,get:Edit")

	// admin Router
	beego.Router("/incident-manager/admin", &admin.AdminController{}, "post,get:GetIncident")
	beego.Router("/incident-manager/admin/user", &admin.AdminController{}, "post,get:GetUser")
	beego.Router("/incident-manager/admin/user/add", &admin.AdminController{}, "post,get:AddUser")
	beego.Router("/incident-manager/admin/user/update/:id([0-9]+)", &admin.AdminController{}, "post,get:EditUser")
	beego.Router("/incident-manager/admin/user/delete/:id([0-9]+)", &admin.AdminController{}, "post,get:DeleteUser")
	beego.Router("/incident-manager/admin/declaration", &admin.AdminController{}, "post,get:AddIncident")
	beego.Router("/incident-manager/admin/myincident", &admin.AdminController{}, "post,get:ByMailIncident")
	beego.Router("/incident-manager/admin/incident/:id([0-9]+)", &admin.AdminController{}, "get:GetOneIncident")
	beego.Router("/incident-manager/admin/incident/update/:id([0-9]+)", &admin.AdminController{}, "post,get:EditIncident")
	beego.Router("/incident-manager/admin/incident/delete/:id([0-9]+)", &admin.AdminController{}, "post,get:DeleteIncident")
	beego.Router("/incident-manager/admin/register", &admin.AdminController{}, "post,get:RegisterDemand")
	beego.Router("/incident-manager/admin/register/delete/:id([0-9]+)", &admin.AdminController{}, "post,get:DeleteDemand")
	// beego.Router("/admin/incident/:id([0-9]+)", &admin.AdminController{}, "get:GetOne")

	//Static Router
	beego.SetStaticPath("/static", "static")

	//Erreurs
	beego.ErrorController(&controllers.ErrorController{})
}
func init() {
	beego.InsertFilter("/*", beego.BeforeRouter, loginFilter)
	beego.Router("/", &controllers.MainController{})
	beego.Router("/register", &controllers.RegisterController{})
	beego.Router("/login", &controllers.LoginController{})
	beego.Router("/category", &controllers.CategoryController{})
	beego.Router("/view", &controllers.ViewController{})
	beego.Router("/view/document", &controllers.ViewController{}, "get:Document")
	beego.Router("/logout", &controllers.LogoutController{})
}
Exemple #24
0
func main() {

	beego.Router("/", &controllers.MainController{})
	beego.Router("/:name", &controllers.MainController{})
	beego.Router("/:name/:id", &controllers.DocsController{})
	beego.InsertFilter("/images/:all", beego.BeforeRouter, controllers.DocsStatic)
	controllers.InitLocales()
	models.InitModels()
	beego.AddFuncMap("i18n", i18n.Tr)
	beego.Run()
}
Exemple #25
0
// NewWithFilter create a new captcha.Captcha and auto AddFilter for serve captacha image
// and add a template func for output html
func NewWithFilter(urlPrefix string, store cache.Cache) *Captcha {
	cpt := NewCaptcha(urlPrefix, store)

	// create filter for serve captcha image
	beego.InsertFilter(cpt.URLPrefix+"*", beego.BeforeRouter, cpt.Handler)

	// add to template func map
	beego.AddFuncMap("create_captcha", cpt.CreateCaptchaHTML())

	return cpt
}
Exemple #26
0
func init() {

	beego.InsertFilter("/*", beego.BeforeRouter, profileFilter)

	if ACL {
		// web
		beego.InsertFilter("/settings/*", beego.BeforeRouter, authFilter)
		// api
		beego.InsertFilter("/v1.0/((user)|(ugroup))/*", beego.BeforeRouter, adminFiler)
	}

	ac := &controllers.AuthController{}
	mc := &controllers.MainController{}

	beego.Router("/", mc, "get:Get")
	beego.Router("/login", ac, "get:LoginGet;post:LoginPost")
	beego.Router("/logout", ac, "get:Logout")

	beego.Router("/settings/profile", mc, "get:GetProfile")
	beego.Router("/settings/about", mc, "get:GetAbout")

	beego.Router("/user", mc, "get:GetUser")
	beego.Router("/user/edit/:id([0-9]+)", mc, "get:EditUser")
	beego.Router("/user/add", mc, "get:AddUser")

	beego.Router("/host", mc, "get:GetHost")
	beego.Router("/host/edit/:id([0-9]+)", mc, "get:EditHost")
	beego.Router("/host/add", mc, "get:AddHost")

	beego.Router("/tag", mc, "get:GetTag")
	beego.Router("/tag/edit/:id([0-9]+)", mc, "get:EditTag")
	beego.Router("/tag/add", mc, "get:AddTag")

	beego.Router("/role", mc, "get:GetRole")
	beego.Router("/role/edit/:id([0-9]+)", mc, "get:EditRole")
	beego.Router("/role/add", mc, "get:AddRole")

	beego.Router("/system", mc, "get:GetSystem")
	beego.Router("/system/edit/:id([0-9]+)", mc, "get:EditSystem")
	beego.Router("/system/add", mc, "get:AddSystem")
}
Exemple #27
0
func main() {
	//Enable Cors
	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowOrigins:     []string{"*"},
		AllowMethods:     []string{"GET", "POST"},
		AllowHeaders:     []string{"Origin"},
		ExposeHeaders:    []string{"Content-Length"},
		AllowCredentials: true,
	}))

	beego.Run()
}
Exemple #28
0
func init() {
	beego.Errorhandler("404", controllers.Error404)
	beego.Errorhandler("403", controllers.Error403)
	beego.Errorhandler("500", controllers.Error500)
	beego.Errorhandler("Once", controllers.ErrorOnce)
	beego.Errorhandler("IPBan", controllers.ErrorIPBan)

	beego.Router("/", &controllers.MainController{})

	//登录
	authController := new(controllers.AuthController)
	beego.Router("/login", authController, "get:Login;post:DoLogin")
	beego.Router("/login/:returnurl(.+)", authController, "get:Login")
	beego.Router("/forget-password", authController, "get:ForgetPassword;post:ForgetPassword")
	beego.Router("/reset-password/:code([0-9a-zA-Z]+)", authController, "get:ResetPassword;post:ResetPassword")
	beego.Router("/logout", authController, "get:Logout")
	beego.Router("/register", authController, "get:Register;post:DoRegister")
	beego.Router("/register/validate-username", authController, "get:ValidateUsername")
	beego.Router("/register/validate-email", authController, "get:ValidateEmail")
	beego.Router("/register/validate-captcha", authController, "get:ValidateCaptcha")
	beego.Router("/activate/:code([0-9a-zA-Z]+)", authController, "get:Activate")
	//社交帐号登录
	beego.InsertFilter("/login/*:/access", beego.BeforeRouter, controllers.OAuthAccess)
	beego.InsertFilter("/login/*:", beego.BeforeRouter, controllers.OAuthRedirect)
	socialAuthController := new(controllers.SocialAuthController)
	beego.Router("/register/connect", socialAuthController, "get:Connect;post:Connect")

	userController := new(controllers.UserController)
	beego.Router("/user/:username(.+)/edit", userController, "get:Edit;post:Edit")
	beego.Router("/user/:username(.+)/resend-validation", userController, "get:ResendValidation")
	beego.Router("/user/:username(.+)", userController, "get:Profile")
	beego.Router("/user-followunfollow", userController, "post:FollowUnfollow")
	beego.Router("/users", userController, "get:ListById")
	beego.Router("/users/by-rep", userController, "get:ListByRep")
	beego.Router("/users/by-digests", userController, "get:ListByDigests")
	beego.Router("/users/by-topics", userController, "get:ListByTopics")
	beego.Router("/users/by-comments", userController, "get:ListByComments")
	beego.Router("/users/by-followers", userController, "get:ListByFollowers")
}
Exemple #29
0
func InitNewrelicAgent() {

	license := beego.AppConfig.String("NewrelicLicense")
	if license == "" {
		beego.Warn("Please specify NewRelic license in the application config: NewrelicLicense=7bceac019c7dcafae1ef95be3e3a3ff8866de245")
		return
	}

	agent = gorelic.NewAgent()
	agent.NewrelicLicense = license

	agent.HTTPTimer = metrics.NewTimer()
	agent.CollectHTTPStat = true

	if beego.RunMode == "dev" {
		agent.Verbose = true
	}
	if verbose, err := beego.AppConfig.Bool("NewrelicVerbose"); err == nil {
		agent.Verbose = verbose
	}

	nameParts := []string{beego.AppConfig.String("appname")}
	switch strings.ToLower(beego.AppConfig.String("NewrelicAppnameRunmode")) {
	case "append":
		nameParts = append(nameParts, beego.RunMode)

	case "prepend":
		nameParts = append([]string{beego.RunMode}, nameParts...)
	}
	agent.NewrelicName = strings.Join(nameParts, SEPARATOR)
	agent.Run()

	beego.InsertFilter("*", beego.BeforeRouter, InitNewRelicTimer, false)
	beego.InsertFilter("*", beego.FinishRouter, ReportMetricsToNewrelic, false)

	beego.Info("NewRelic agent started")
}
Exemple #30
0
func init() {
	beego.Router("", &controllers.IndexController{}, "get:Index")
	beego.Router("/images", &controllers.IndexController{}, "get:Images")

	beego.Router("/users/login", &controllers.UserController{}, "get:Login")
	beego.Router("/users/oauth_login", &controllers.UserController{}, "get:OauthLogin")
	beego.Router("/users/logout", &controllers.UserController{}, "get:Logout")
	beego.Router("/users/session", &controllers.UserController{}, "post:Session")
	beego.Router("/users/oauth_session", &controllers.UserController{}, "post:OauthSession")
	beego.Router("/users/register", &controllers.UserController{}, "get:Register")
	beego.Router("/users/oauth_register", &controllers.UserController{}, "get:OauthRegister")
	beego.Router("/users/register_captcha", &controllers.UserController{}, "post:CreateRegisterCaptcha")
	beego.Router("/users/get_test", &controllers.UserController{}, "get:GetTest")
	beego.Router("/users/post_test", &controllers.UserController{}, "post:PostTest")

	beego.Router("/users", &controllers.UserController{}, "post:CreateUser")
	beego.Router("/users/:name", &controllers.UserController{}, "get:UserHome")

	beego.Router("/users/check_user_name", &controllers.UserController{}, "post:CheckUserName")
	beego.Router("/users/check_user_mail", &controllers.UserController{}, "post:CheckUserMail")

	beego.Router("/articles", &controllers.ArticleController{}, "get:Articles")
	beego.Router("/articles", &controllers.ArticleController{}, "post:CreateArticle")
	beego.Router("/articles/new", &controllers.ArticleController{}, "get:New")
	beego.Router("/articles/:id/edit", &controllers.ArticleController{}, "get:EditArticle")
	/*beego.Router("/articles/:id([0-9]+)", &controllers.ArticleController{}, "get:ArticleDetail")*/
	beego.Router("/users/:userId([0-9]+)/articles/:id([0-9]+)", &controllers.ArticleController{}, "get:ArticleDetail")
	beego.Router("/articles", &controllers.ArticleController{}, "put:UpdateArticle")
	beego.Router("/articles/:id([0-9]+)/likes", &controllers.ArticleController{}, "post:Like")

	beego.Router("/categories/:category", &controllers.ArticleController{}, "get:ArticlesGyCategory")
	beego.Router("/users/:userId([0-9]+)/categories/:category", &controllers.ArticleController{}, "get:ArticlesGyUserIdAndCategory")

	beego.Router("/sponsors/new", &controllers.SponsorController{}, "post:New")

	beego.Router("/open_users/:type/auth", &controllers.OpenUserController{}, "get:QqAuth")
	beego.Router("/open_users/:type/token", &controllers.OpenUserController{}, "get:QqToken")

	var FilterMethod = func(ctx *context.Context) {
		if ctx.Input.Query("_method") != "" && ctx.Input.IsPost() {
			ctx.Request.Method = ctx.Input.Query("_method")
		}
		ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
		ctx.ResponseWriter.Header().Add("Access-Control-Allow-Headers", "Content-Type")
		ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
	}

	beego.InsertFilter("*", beego.BeforeRouter, FilterMethod)
}