Upgraded to latest aero version
This commit is contained in:
assets
auth
config.jsondocs
go.modgo.sumlayout
main.gomain_test.gomakefilemiddleware
pages
activity
admin
amv
amvs
anime
animeimport
animelist
animelistitem
apiview
calendar
character
characters
charge
companies
company
compare
editlog
editor
editor.go
filteranime
all.goanilist.gocharacters.goduplicatemappings.goepisodelength.gogenres.golicensors.golowresimages.gomal.goproducers.gorelations.goshoboi.gosource.gostartdate.gostudios.gosynopsis.gotrailers.goutils.go
filtercompanies
filtersoundtracks
jobs
kitsu.gomal.goembed
episode
explore
forum
frontpage
genre
genres
group
groups
home
index/staffroutes
inventory
listimport
login
me
newthread
notifications
paypal
popular
post
profile
quote
quotes
recommended
search
settings
shop
soundtrack
soundtracks
sse
statistics
support
terms
thread
upload
user
users
welcome
scripts/Actions
tools
utils
@ -14,33 +14,35 @@ import (
|
||||
)
|
||||
|
||||
// UserInfo updates user related information after each request.
|
||||
func UserInfo() aero.Middleware {
|
||||
return func(ctx *aero.Context, next func()) {
|
||||
next()
|
||||
func UserInfo(next aero.Handler) aero.Handler {
|
||||
return func(ctx aero.Context) error {
|
||||
err := next(ctx)
|
||||
|
||||
// Ignore non-HTML requests
|
||||
contentType := ctx.Response().Header().Get("Content-Type")
|
||||
contentType := ctx.Response().Header("Content-Type")
|
||||
|
||||
if !strings.HasPrefix(contentType, "text/html") {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
user := utils.GetUser(ctx)
|
||||
|
||||
// When there's no user logged in, nothing to update
|
||||
if user == nil {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
// This works asynchronously so it doesn't block the response
|
||||
go updateUserInfo(ctx, user)
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Update browser and OS data
|
||||
func updateUserInfo(ctx *aero.Context, user *arn.User) {
|
||||
newIP := ctx.RealIP()
|
||||
newUserAgent := ctx.UserAgent()
|
||||
func updateUserInfo(ctx aero.Context, user *arn.User) {
|
||||
newIP := ctx.IP()
|
||||
newUserAgent := ctx.Request().Header("User-Agent")
|
||||
|
||||
if user.UserAgent != newUserAgent {
|
||||
user.UserAgent = newUserAgent
|
||||
@ -91,7 +93,12 @@ func updateUserLocation(user *arn.User, newIP string) {
|
||||
}
|
||||
|
||||
newLocation := arn.IPInfoDBLocation{}
|
||||
response.Unmarshal(&newLocation)
|
||||
err = response.Unmarshal(&newLocation)
|
||||
|
||||
if err != nil {
|
||||
color.Red("Couldn't deserialize location data | Status: %d | IP: %s", response.StatusCode, user.IP)
|
||||
return
|
||||
}
|
||||
|
||||
if newLocation.CountryName != "-" {
|
||||
user.Location.CountryName = newLocation.CountryName
|
||||
|
Reference in New Issue
Block a user