func configureBlogs(routes *wcg.Router) { // check user is already signed in or not. routes.All("/admin/blogs/*", func(res *wcg.Response, req *wcg.Request) { if wcg.IsGuest(req.User) { res.Redirect("/", http.StatusFound) } }) // public interfaces. routes.Get("/my/", myblogRedirector(true)) routes.Get("/:blog_id/", showBlogHandler) // admin interfaces routes.Get("/admin/blogs/my/", myblogRedirector(false)) routes.Get("/admin/blogs/:blog_id/", manageBlogHandler) routes.Post("/admin/blogs/", createBlogHandler) routes.Put("/admin/blogs/:blog_id/", updateBlogHandler) routes.Delete("/admin/blogs/:blog_id/", deleteBlogHandler) }
func configureOAuth(routes *wcg.Router) { GoogleAuthConfig, _ := google.NewAuthConfigFromFile("") FacebookAuthConfig, _ := facebook.NewAuthConfigFromFile("") GoogleAuthConfig.RedirectURL = "/login/google/callback" GoogleAuthConfig.TransportFactory = gae.NewHttpTransport GoogleAuthConfig.UnauthorizedHandler = unauthorized GoogleAuthConfig.AuthorizedHandler = authorized GoogleAuthConfig.InvalidatedHandler = invalidated gauth, gcallback, gvalidates, glogout := middleware.OAuth2(GoogleAuthConfig) routes.All("/*", gvalidates) routes.Get("/login/google", gauth) routes.Get("/login/google/callback", gcallback) routes.Get("/logout/google", glogout) FacebookAuthConfig.RedirectURL = "/login/facebook/callback" FacebookAuthConfig.TransportFactory = gae.NewHttpTransport FacebookAuthConfig.UnauthorizedHandler = unauthorized FacebookAuthConfig.AuthorizedHandler = authorized FacebookAuthConfig.InvalidatedHandler = invalidated fbauth, fbcallback, fbvalidates, fblogout := middleware.OAuth2(FacebookAuthConfig) routes.All("/*", fbvalidates) routes.All("/*", func(res *wcg.Response, req *wcg.Request) { res.SetLocal("fb_app_id", FacebookAuthConfig.ClientId) }) routes.Get("/login/facebook", fbauth) routes.Get("/login/facebook/callback", fbcallback) routes.Post("/logout/facebook", fblogout) }