Skip to content

Instantly share code, notes, and snippets.

@Cibernomadas Cibernomadas/handler.go
Last active Jun 29, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.