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