Last active
June 29, 2018 18:06
-
-
Save Cibernomadas/b66edbb102640ffa013e56531dcc05cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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