Beispiel #1
0
func testServer() *httptest.Server {
	e := echo.New()
	e.SetRenderer(tmpl.NewRenderer())
	// middlewares
	e.Use(i18n.Langs())      // languages
	e.Use(flash.Flash())     // flash messages
	e.Use(userAuth.Normal()) // adding user context data

	// HOME
	e.Get("/", base.Home)

	// AUTH
	xauth := e.Group("/auth")

	xauth.Use(csrf.Nosurf()) // csrf protection
	xauth.Use(csrf.Tokens()) // csrf tokens

	xauth.Get("/login", Login)
	xauth.Post("/login", LoginPost)
	xauth.Get("/register", Register)
	xauth.Post("/register", RegisterPost)
	xauth.Get("/logout", Logout)

	return httptest.NewServer(e)
}
Beispiel #2
0
// Routes is the echo instance with all zedlist routes.
func Routes() *echo.Echo {
	e := echo.New()

	e.SetRenderer(tmpl.NewRenderer()) // Set renderer

	// middlewares
	e.Use(i18n.Langs())      // languages
	e.Use(flash.Flash())     // flash messages
	e.Use(userAuth.Normal()) // adding user context data
	e.Use(middleware.Gzip()) // Gzip

	// API
	a := e.Group("/api")
	a.Post("/jobs", japi.CreateJob)
	a.Get("/jobs/:id", japi.GetJob)
	a.Get("/jobs", japi.GetIndex)
	a.Put("/jobs", japi.UpdateJob)

	// HOME
	e.Get("/", base.Home)
	e.Get("/language/:lang", base.SetLanguage)

	// DOCS
	e.Get("/docs", base.DocsHome)
	e.Get("/docs/:name", base.Docs)

	// BASE
	b := e.Group("/jobs")
	b.Get("/", base.JobsHome)
	b.Get("/view/:id", base.JobView)
	b.Get("/regions", base.RegionsHome)
	b.Get("/regions/:name", base.RegionsJobView)
	b.Get("/regions/:name/:from/:to", base.RegionsJobPaginate)

	// AUTH
	xauth := e.Group("/auth")

	// add csrf protection
	xauth.Use(csrf.Nosurf())
	xauth.Use(csrf.Tokens())

	xauth.Get("/login", auth.Login)
	xauth.Post("/login", auth.LoginPost)
	xauth.Get("/register", auth.Register)
	xauth.Post("/register", auth.RegisterPost)
	xauth.Get("/logout", auth.Logout)

	// DASHBOARD
	dashboard := e.Group("/dash")
	dashboard.Use(userAuth.Must())
	dashboard.Get("/", dash.Home)
	dashboard.Get("/jobs/new", dash.JobsNewGet)
	dashboard.Post("/jobs/new", dash.JobsNewPost)
	dashboard.Get("/profile", dash.Profile)
	dashboard.Post("/profile/name", dash.ProfileName)

	// RESUME
	r := e.Group("/resume")
	r.Get("/", resume.Home)
	r.Post("/new", resume.Create)
	r.Get("/view:id", resume.View)
	r.Post("/update/:id", resume.Update)
	r.Post("/delete/:id", resume.Delete)

	// SEARCH
	e.Post("/search", search.Find)

	// STATIC
	box := &ass.AssetFS{
		Asset:    static.Asset,
		AssetDir: static.AssetDir,
		Prefix:   "static",
	}
	staticFileServer := http.StripPrefix("/static/", http.FileServer(box))
	e.Get("/static/*", staticFileServer)
	return e
}