Skip to content

Instantly share code, notes, and snippets.

@Cibernomadas
Created June 26, 2018 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cibernomadas/dec688ed9e47b26dc36a9d11ecb45b8d to your computer and use it in GitHub Desktop.
Save Cibernomadas/dec688ed9e47b26dc36a9d11ecb45b8d to your computer and use it in GitHub Desktop.
func Authenticated(c *gin.Context) {
session := sessions.Default(c)
u := session.Get("user")
if u != nil {
user := u.(models.User)
if user.IsAuthenticated {
c.Next()
return
}
}
c.HTML(http.StatusOK, "index", gin.H{
"title": "Hi! GoBlog.",
"error": "Restricted area, please login first.",
})
c.Abort()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment