Refactor
This commit is contained in:
@ -32,7 +32,14 @@ func UserInfo() aero.Middleware {
|
||||
next()
|
||||
|
||||
// Ignore non-HTML requests
|
||||
if strings.Index(ctx.GetRequestHeader("Accept"), "text/html") == -1 {
|
||||
if ctx.IsMediaResponse() {
|
||||
return
|
||||
}
|
||||
|
||||
// Ignore API requests
|
||||
// Note that API requests can filter data (privacy) and we might accidentally save the filtered data.
|
||||
// That's why it's very important to ignore all API requests and not call user.Save() in this context.
|
||||
if strings.HasPrefix(ctx.URI(), "/api/") {
|
||||
return
|
||||
}
|
||||
|
||||
@ -43,6 +50,11 @@ func UserInfo() aero.Middleware {
|
||||
return
|
||||
}
|
||||
|
||||
// Let's be 100% sure we really do not accidentally save filtered data.
|
||||
if user.Email == "" && user.IP == "" && user.FirstName == "" {
|
||||
return
|
||||
}
|
||||
|
||||
// This works asynchronously so it doesn't block the response
|
||||
go updateUserInfo(ctx, user)
|
||||
}
|
||||
|
Reference in New Issue
Block a user