Skip to content

Instantly share code, notes, and snippets.

@Cibernomadas
Last active June 29, 2018 18:06
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/b66edbb102640ffa013e56531dcc05cd to your computer and use it in GitHub Desktop.
Save Cibernomadas/b66edbb102640ffa013e56531dcc05cd 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 {
dbc, exist := c.Get("db")
if !exist {
c.HTML(http.StatusOK, "login", gin.H{
"title": "Hi! GoBlog.",
"error": "We've got an internal error, please try later.",
})
return
}
db := dbc.(*gorm.DB)
user.LastSeen = time.Now().UTC().Format("02-01-2006 15:04:05")
db.Save(&user)
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