Пример #1
0
// create a instance and create filter
func NewWithFilter(urlPrefix string, socialAuther SocialAuther) *SocialAuth {
	social := NewSocial(urlPrefix, socialAuther)

	beego.AddFilter(social.URLPrefix+":/access", "AfterStatic", social.handleAccess)
	beego.AddFilter(social.URLPrefix+":", "AfterStatic", social.handleRedirect)

	return social
}
Пример #2
0
func main() {

	initialize()

	beego.Info(beego.AppName, APP_VER)

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

	// Register routers.
	beego.Router("/", &routers.HomeRouter{})
	beego.Router("/community", &routers.CommunityRouter{})
	beego.Router("/quickstart", &routers.QuickStartRouter{})
	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{})
	// beego.Router("/samples", &routers.SamplesRouter{})
	// beego.Router("/samples/:all", &routers.SamplesRouter{})

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

	beego.Run()
}
Пример #3
0
func main() {

	initialize()

	beego.Info(beego.AppName, APP_VER)

	beego.AddFilter("/docs/images/:all", "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()
}
Пример #4
0
func main() {
	beego.SessionOn = true
	beego.AddFuncMap("Index", Index)
	beego.AddFuncMap("Count", GetCount)
	beego.AddFuncMap("ResCount", GetResCount)
	beego.AddFilter("/admin/:all", "AfterStatic", FilterUser)
	beego.Run()
}
Пример #5
0
func Access() {
	var Check = func(ctx *context.Context) {

		ret := CheckAccess(ctx.Request.RequestURI)
		fmt.Println(ret)
	}
	beego.AddFilter("*", "BeforRouter", Check)
}
Пример #6
0
// create a new captcha.Captcha and auto AddFilter for serve captacha image
// and add a tempalte func for output html
func NewWithFilter(urlPrefix string, store cache.Cache) *Captcha {
	cpt := NewCaptcha(urlPrefix, store)

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

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

	return cpt
}
Пример #7
0
func main() {
	initialize()

	// must enable session engine, default use memory as engine
	beego.SessionOn = true
	beego.SessionProvider = "file"
	beego.SessionSavePath = filepath.Join(os.TempDir(), "social_auth_sess")

	beego.AddFilter("*", "BeforeRouter", func(ctx *context.Context) {
		beego.Info(ctx.Request.Method, ctx.Request.RequestURI)
	})

	mainR := new(MainRouter)
	beego.Router("/", mainR, "get:Home")
	beego.Router("/login", mainR, "get:Login")
	beego.Router("/register/connect", mainR, "get:Connect")
	beego.Run()
}
Пример #8
0
func main() {
	//初始化
	initialize()

	beego.Info(beego.AppName, APP_VER)

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

	beego.AddFilter("*", "AfterStatic", UrlManager)

	beego.Router("/", &controllers.MainController{}, "*:Index")
	beego.Router("/home", &controllers.MainController{}, "*:Home")
	beego.Router("/about", &controllers.MainController{}, "*:About")
	beego.Router("/contact", &controllers.MainController{}, "*:Contact")
	beego.Router("/login", &controllers.MainController{}, "*:Login")
	beego.Router("/doLogin", &controllers.UserController{}, "post:Login")
	beego.Router("/upload", &controllers.UploadController{}, "*:Upload")
	// uns := beego.NewNamespace("/user").
	// 	Router("/reg", &controllers.UserController{}, "post:Reg").
	// 	Router("/checkEmail", &controllers.UserController{}, "post:CheckEmail").
	// 	Router("/logout", &controllers.UserController{}, "*:Logout")

	// bns := beego.NewNamespace("/blog").
	// 	Router("/posting", &controllers.BlogController{}, "*:Posting").
	// 	Router("/post", &controllers.BlogController{}, "*:Post")

	beego.Router("/user/reg", &controllers.UserController{}, "post:Reg")
	beego.Router("/user/checkEmail", &controllers.UserController{}, "post:CheckEmail")
	beego.Router("/user/logout", &controllers.UserController{}, "*:Logout")

	beego.Router("/blog/posting", &controllers.BlogController{}, "*:Posting")
	beego.Router("/blog/post", &controllers.BlogController{}, "*:Post")

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

	// beego.AddNamespace(uns, bns)
	beego.Run()
}
Пример #9
0
//check access and register user's nodes
func AccessRegister() {
	var Check = func(ctx *context.Context) {
		user_auth_type, _ := strconv.Atoi(beego.AppConfig.String("user_auth_type"))
		rbac_auth_gateway := beego.AppConfig.String("rbac_auth_gateway")
		var accesslist map[string]bool
		if user_auth_type > 0 {
			params := strings.Split(strings.ToLower(ctx.Request.RequestURI), "/")
			if CheckAccess(params) {
				uinfo := ctx.Input.Session("userinfo")
				if uinfo == nil {
					ctx.Redirect(302, rbac_auth_gateway)
				}
				//admin用户不用认证权限
				adminuser := beego.AppConfig.String("rbac_admin_user")
				if uinfo.(m.User).Username == adminuser {
					return
				}

				if user_auth_type == 1 {
					listbysession := ctx.Input.Session("accesslist")
					if listbysession != nil {
						accesslist = listbysession.(map[string]bool)
					}
				} else if user_auth_type == 2 {

					accesslist, _ = GetAccessList(uinfo.(m.User).Id)
				}

				ret := AccessDecision(params, accesslist)
				if !ret {
					ctx.Output.Json(&map[string]interface{}{"status": false, "info": "权限不足"}, true, false)
				}
			}

		}
	}
	beego.AddFilter("*", "AfterStatic", Check)
}
Пример #10
0
func main() {
	initialize()

	beego.Info("AppPath:", beego.AppPath)

	if setting.IsProMode {
		beego.Info("Product mode enabled")
	} else {
		beego.Info("Develment mode enabled")
	}
	beego.Info(beego.AppName, setting.APP_VER, setting.AppUrl)

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

	// Add Filters
	beego.AddFilter("/img/:", "BeforeRouter", attachment.ImageFilter)

	beego.AddFilter("/captcha/:", "BeforeRouter", setting.Captcha.Handler)

	// Register routers.
	posts := new(post.PostListRouter)
	beego.Router("/", posts, "get:Home")
	beego.Router("/:slug(recent|best|cold|favs|follow)", posts, "get:Navs")
	beego.Router("/category/:slug", posts, "get:Category")
	beego.Router("/topic/:slug", posts, "get:Topic;post:TopicSubmit")

	postR := new(post.PostRouter)
	beego.Router("/new", postR, "get:New;post:NewSubmit")
	beego.Router("/post/:post([0-9]+)", postR, "get:Single;post:SingleSubmit")
	beego.Router("/post/:post([0-9]+)/edit", postR, "get:Edit;post:EditSubmit")

	if setting.NativeSearch || setting.SphinxEnabled {
		searchR := new(post.SearchRouter)
		beego.Router("/search", searchR, "get:Get")
	}

	user := new(auth.UserRouter)
	beego.Router("/user/:username/comments", user, "get:Comments")
	beego.Router("/user/:username/posts", user, "get:Posts")
	beego.Router("/user/:username/following", user, "get:Following")
	beego.Router("/user/:username/followers", user, "get:Followers")
	beego.Router("/user/:username/favs", user, "get:Favs")
	beego.Router("/user/:username", user, "get:Home")

	login := new(auth.LoginRouter)
	beego.Router("/login", login, "get:Get;post:Login")
	beego.Router("/logout", login, "get:Logout")

	beego.AddFilter("/login/:/access", "BeforeRouter", auth.OAuthAccess)
	beego.AddFilter("/login/:", "BeforeRouter", auth.OAuthRedirect)

	socialR := new(auth.SocialAuthRouter)
	beego.Router("/register/connect", socialR, "get:Connect;post:ConnectPost")

	register := new(auth.RegisterRouter)
	beego.Router("/register", register, "get:Get;post:Register")
	beego.Router("/active/success", register, "get:ActiveSuccess")
	beego.Router("/active/:code([0-9a-zA-Z]+)", register, "get:Active")

	settings := new(auth.SettingsRouter)
	beego.Router("/settings/profile", settings, "get:Profile;post:ProfileSave")

	forgot := new(auth.ForgotRouter)
	beego.Router("/forgot", forgot)
	beego.Router("/reset/:code([0-9a-zA-Z]+)", forgot, "get:Reset;post:ResetPost")

	upload := new(attachment.UploadRouter)
	beego.Router("/upload", upload, "post:Post")

	apiR := new(api.ApiRouter)
	beego.Router("/api/user", apiR, "post:Users")
	beego.Router("/api/md", apiR, "post:Markdown")

	adminDashboard := new(admin.AdminDashboardRouter)
	beego.Router("/admin", adminDashboard)

	adminR := new(admin.AdminRouter)
	beego.Router("/admin/model/get", adminR, "post:ModelGet")
	beego.Router("/admin/model/select", adminR, "post:ModelSelect")

	routes := map[string]beego.ControllerInterface{
		"user":     new(admin.UserAdminRouter),
		"post":     new(admin.PostAdminRouter),
		"comment":  new(admin.CommentAdminRouter),
		"topic":    new(admin.TopicAdminRouter),
		"category": new(admin.CategoryAdminRouter),
		"article":  new(admin.ArticleAdminRouter),
	}
	for name, router := range routes {
		beego.Router(fmt.Sprintf("/admin/:model(%s)", name), router, "get:List")
		beego.Router(fmt.Sprintf("/admin/:model(%s)/:id(new)", name), router, "get:Create;post:Save")
		beego.Router(fmt.Sprintf("/admin/:model(%s)/:id([0-9]+)", name), router, "get:Edit;post:Update")
		beego.Router(fmt.Sprintf("/admin/:model(%s)/:id([0-9]+)/:action(delete)", name), router, "get:Confirm;post:Delete")
	}

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

	articleR := new(article.ArticleRouter)
	beego.Router("/:slug([0-9a-z-./]+)", articleR, "get:Show")

	if beego.RunMode == "dev" {
		beego.Router("/test/:tmpl(mail/.*)", new(base.TestRouter))
	}

	// For all unknown pages.
	beego.Run()
}
Пример #11
0
func initialize() {
	var err error

	// setting beego orm
	err = orm.RegisterDataBase("default", "mysql", beego.AppConfig.String("orm_source"))
	if err != nil {
		beego.Error(err)
	}
	err = orm.RunSyncdb("default", false, false)
	if err != nil {
		beego.Error(err)
	}

	// OAuth
	var clientId, secret string

	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("dropbox_client_id")
	secret = beego.AppConfig.String("dropbox_client_secret")
	err = social.RegisterProvider(apps.NewDropbox(clientId, secret))
	if err != nil {
		beego.Error(err)
	}

	clientId = beego.AppConfig.String("facebook_client_id")
	secret = beego.AppConfig.String("facebook_client_secret")
	err = social.RegisterProvider(apps.NewFacebook(clientId, secret))
	if err != nil {
		beego.Error(err)
	}

	// global create a SocialAuth and auto set filter
	SocialAuth = social.NewSocial("/login/", new(socialAuther))
	beego.AddFilter("/login/:/access", "AfterStatic", HandleAccess)
	beego.AddFilter("/login/:", "AfterStatic", HandleRedirect)

	// set the DefaultTransport of social-auth
	//
	// social.DefaultTransport = &http.Transport{
	// 	Proxy: func(req *http.Request) (*url.URL, error) {
	// 		u, _ := url.ParseRequestURI("http://127.0.0.1:8118")
	// 		return u, nil
	// 	},
	// 	DisableKeepAlives: true,
	// }
}