func Logout(c *gin.Context) { session := sessions.Get(c) session.DriverId = 0 session.Handle = "" session.Save(c) c.Redirect(http.StatusMovedPermanently, "/") }
func Hello(c *gin.Context) { session := sessions.Get(c) if session.IsLoggedIn() { c.Redirect(http.StatusMovedPermanently, "/dashboard") return } content := utils.Render("templates/index.tmpl", gin.H{"handle": session.Handle, "loggedIn": false}) c.HTML(http.StatusOK, "master.tmpl", gin.H{"content": template.HTML(content)}) }
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 }
func Dashboard(c *gin.Context) { session := sessions.Get(c) content := utils.Render("templates/dashboard.tmpl", gin.H{"handle": session.Handle, "client_id": config.ClientId()}) c.HTML(http.StatusOK, "master.tmpl", gin.H{"content": template.HTML(content)}) }