예제 #1
0
파일: main.go 프로젝트: benreic/dingus
func main() {

	utils.Log("Dingus starting")

	// Creates a gin router with default middleware:
	// logger and recovery (crash-free) middleware
	router := gin.Default()

	router.LoadHTMLGlob("templates/*.tmpl")
	router.Static("/public", "./public")

	public := router.Group("/")
	{
		public.GET("/", controllers.Hello)
		public.GET("/sign-up", controllers.SignUp)
		public.POST("/sign-up", controllers.ProcessSignUp)
		public.POST("/login", controllers.Login)
		public.GET("/automatic-redirect", controllers.AutomaticRedirect)
	}

	protected := router.Group("/", middleware.AuthRequired)
	{
		protected.GET("/dashboard", controllers.Dashboard)
		protected.POST("/logout", controllers.Logout)
	}

	// Listen and server on 0.0.0.0:8080
	err := router.Run(":" + config.Port())

	utils.Log("Dingus stopping")

	if err != nil {
		utils.LogError(err)
	}
}
예제 #2
0
파일: auth.go 프로젝트: benreic/dingus
func AuthRequired(c *gin.Context) {

	// before request, make sure we have a session
	// and that they have a handle
	session := sessions.Get(c)

	if !session.IsLoggedIn() {
		utils.Log("Nobody logged in, going to login screen.")
		c.Redirect(http.StatusMovedPermanently, "/")
		return
	}

	c.Next()

	// after request
}