Implemented new user registrations
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/aerogo/log"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
// Log middleware logs every request into logs/request.log and errors into logs/error.log.
|
||||
@ -27,8 +28,14 @@ func Log() aero.Middleware {
|
||||
responseTimeString := strconv.Itoa(int(responseTime.Nanoseconds()/1000000)) + " ms"
|
||||
responseTimeString = strings.Repeat(" ", 8-len(responseTimeString)) + responseTimeString
|
||||
|
||||
user := utils.GetUser(ctx)
|
||||
|
||||
// Log every request
|
||||
request.Info(ctx.RealIP(), ctx.StatusCode, responseTimeString, ctx.URI())
|
||||
if user != nil {
|
||||
request.Info(user.Nick, ctx.RealIP(), ctx.StatusCode, responseTimeString, ctx.URI())
|
||||
} else {
|
||||
request.Info("[guest]", ctx.RealIP(), ctx.StatusCode, responseTimeString, ctx.URI())
|
||||
}
|
||||
|
||||
// Log all requests that failed
|
||||
switch ctx.StatusCode {
|
||||
|
@ -2,7 +2,6 @@ package middleware
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
@ -46,8 +45,7 @@ func updateUserInfo(ctx *aero.Context) {
|
||||
}
|
||||
|
||||
// Ignore non-HTML requests
|
||||
println(ctx.GetRequestHeader("Accept-Type"))
|
||||
if strings.Index(ctx.GetRequestHeader("Accept-Type"), "text/html") == -1 {
|
||||
if strings.Index(ctx.GetRequestHeader("Accept"), "text/html") == -1 {
|
||||
return
|
||||
}
|
||||
|
||||
@ -63,37 +61,36 @@ func updateUserInfo(ctx *aero.Context) {
|
||||
// Browser
|
||||
user.Browser.Name, user.Browser.Version = parsed.Browser()
|
||||
|
||||
arn.PrettyPrint(user.Browser)
|
||||
|
||||
// OS
|
||||
os := parsed.OSInfo()
|
||||
user.OS.Name = os.Name
|
||||
user.OS.Version = os.Version
|
||||
|
||||
arn.PrettyPrint(user.OS)
|
||||
}
|
||||
|
||||
if user.IP != newIP {
|
||||
user.IP = newIP
|
||||
locationAPI := "https://api.ipinfodb.com/v3/ip-city/?key=" + apiKeys.IPInfoDB.ID + "&ip=" + "2a02:8108:8dc0:3000:6cf1:af03:ce6e:679a" + "&format=json"
|
||||
locationAPI := "https://api.ipinfodb.com/v3/ip-city/?key=" + apiKeys.IPInfoDB.ID + "&ip=" + user.IP + "&format=json"
|
||||
|
||||
response, data, err := gorequest.New().Get(locationAPI).EndBytes()
|
||||
|
||||
if len(err) > 0 && err[0] != nil {
|
||||
color.Red(err[0].Error())
|
||||
color.Red("Couldn't fetch location data | Error: %s | IP: %s", err[0].Error(), user.IP)
|
||||
return
|
||||
}
|
||||
|
||||
if response.StatusCode != http.StatusOK {
|
||||
body, _ := ioutil.ReadAll(response.Body)
|
||||
fmt.Println(response.StatusCode, locationAPI)
|
||||
fmt.Println(string(body))
|
||||
color.Red("Couldn't fetch location data | Status: %d | IP: %s", response.StatusCode, user.IP)
|
||||
return
|
||||
}
|
||||
|
||||
json.Unmarshal(data, &user.Location)
|
||||
arn.PrettyPrint(user.Location)
|
||||
newLocation := arn.UserLocation{}
|
||||
json.Unmarshal(data, &newLocation)
|
||||
|
||||
if newLocation.CountryName != "-" {
|
||||
user.Location = newLocation
|
||||
}
|
||||
}
|
||||
|
||||
// user.Save()
|
||||
user.LastSeen = arn.DateTimeUTC()
|
||||
user.Save()
|
||||
}
|
||||
|
Reference in New Issue
Block a user