diff --git a/go.mod b/go.mod index d8cc4dcc..a5c653a1 100644 --- a/go.mod +++ b/go.mod @@ -13,10 +13,11 @@ require ( github.com/h2non/filetype v1.1.3 github.com/hashicorp/go-multierror v1.1.1 github.com/json-iterator/go v1.1.12 + github.com/meilisearch/meilisearch-go v0.26.0 github.com/nats-io/nats.go v1.28.0 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/prometheus/client_golang v1.14.0 - github.com/seventv/common v0.0.0-20231109022220-2f3ccd557f7d + github.com/seventv/common v0.0.0-20231202052307-1d4dd4479600 github.com/seventv/compactdisc v0.0.0-20221006190906-ccfe99954e48 github.com/seventv/image-processor/go v0.0.0-20221128171540-d050701ac324 github.com/seventv/message-queue/go v0.0.0-20231201171845-1bb9d5db6881 @@ -34,7 +35,6 @@ require ( require ( github.com/golang-jwt/jwt v3.2.1+incompatible // indirect - github.com/meilisearch/meilisearch-go v0.26.0 // indirect github.com/nats-io/nats-server/v2 v2.9.21 // indirect github.com/nats-io/nkeys v0.4.4 // indirect github.com/nats-io/nuid v1.0.1 // indirect diff --git a/go.sum b/go.sum index a4814562..76ec624a 100644 --- a/go.sum +++ b/go.sum @@ -141,8 +141,6 @@ github.com/go-redsync/redsync/v4 v4.8.1/go.mod h1:LmUAsQuQxhzZAoGY7JS6+dNhNmZyon github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c= github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= -github.com/golang-jwt/jwt/v4 v4.4.3 h1:Hxl6lhQFj4AnOX6MLrsCb/+7tCj7DxP7VA+2rDIq5AU= -github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -352,18 +350,14 @@ github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1Avp github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee/go.mod h1:qwtSXrKuJh/zsFQ12yEE89xfCrGKK63Rr7ctU/uCo4g= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= -github.com/seventv/common v0.0.0-20230729093701-30b85f9e2678 h1:zhFPVeJYPyOldp/DM2Sntjky04mFsp6O5WopISLcLVc= -github.com/seventv/common v0.0.0-20230729093701-30b85f9e2678/go.mod h1:jHHFe3uNMyzb/ReDqMvaI/A1euvV/PW/G+2PhcWQqWw= -github.com/seventv/common v0.0.0-20231024151424-2d40af75f204 h1:bsndtlthK0mvlwNcBkVCshkkzxn9l0sfKx9j35mgWCE= -github.com/seventv/common v0.0.0-20231024151424-2d40af75f204/go.mod h1:jHHFe3uNMyzb/ReDqMvaI/A1euvV/PW/G+2PhcWQqWw= github.com/seventv/common v0.0.0-20231109022220-2f3ccd557f7d h1:zMhDCupeb6lCR7nVOGHuZoonAuSCfD3SmCEvuzVoY5Y= github.com/seventv/common v0.0.0-20231109022220-2f3ccd557f7d/go.mod h1:jHHFe3uNMyzb/ReDqMvaI/A1euvV/PW/G+2PhcWQqWw= +github.com/seventv/common v0.0.0-20231202052307-1d4dd4479600 h1:qwu6BlOxmKPBe9S8YXFVPXFUnaAVkN77k7Bcqn+fbNc= +github.com/seventv/common v0.0.0-20231202052307-1d4dd4479600/go.mod h1:jHHFe3uNMyzb/ReDqMvaI/A1euvV/PW/G+2PhcWQqWw= github.com/seventv/compactdisc v0.0.0-20221006190906-ccfe99954e48 h1:IqWrtt/yob45YnOQ5Wwkbf8qP22eKVtg0WzfyEkGnFg= github.com/seventv/compactdisc v0.0.0-20221006190906-ccfe99954e48/go.mod h1:T+ldp0YQe03s44+A5HHHI/jB3ZmWqOIaNouEqAS+1Dk= github.com/seventv/image-processor/go v0.0.0-20221128171540-d050701ac324 h1:iU3wWepRTbkNoTAPR23m6TAW6Yb9pOMCYVr0K++OBAw= github.com/seventv/image-processor/go v0.0.0-20221128171540-d050701ac324/go.mod h1:0AAXPHKWVVbOdHlfSsL4xwRAxSYgI+v/XPHJeb8XbLs= -github.com/seventv/message-queue/go v0.0.0-20220721124044-9fd23bda9643 h1:7DAXa8jZl3f3mltSEaqLFir+qLkDKx/J04LcxcpdEhA= -github.com/seventv/message-queue/go v0.0.0-20220721124044-9fd23bda9643/go.mod h1:L1iYDSmltUnxlVGX9RayCoVi3e8aNtFrrLJL6Jv+mrM= github.com/seventv/message-queue/go v0.0.0-20231201171845-1bb9d5db6881 h1:hftRpO0JO4o+EKJFwTMK5jW2ayMR3PLgCJm9tBKp5tI= github.com/seventv/message-queue/go v0.0.0-20231201171845-1bb9d5db6881/go.mod h1:L1iYDSmltUnxlVGX9RayCoVi3e8aNtFrrLJL6Jv+mrM= github.com/spf13/afero v1.9.3 h1:41FoI0fD7OR7mGcKE/aOiLkGreyf8ifIOQmJANWogMk= @@ -387,8 +381,8 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stvp/tempredis v0.0.0-20181119212430-b82af8480203 h1:QVqDTf3h2WHt08YuiTGPZLls0Wq99X9bWd0Q5ZSBesM= github.com/stvp/tempredis v0.0.0-20181119212430-b82af8480203/go.mod h1:oqN97ltKNihBbwlX8dLpwxCl3+HnXKV/R0e+sRLd9C8= diff --git a/internal/middleware/auth.middleware.go b/internal/middleware/auth.middleware.go index dc559dd9..7e8ad864 100644 --- a/internal/middleware/auth.middleware.go +++ b/internal/middleware/auth.middleware.go @@ -52,23 +52,22 @@ func Auth(gctx global.Context) Middleware { ipDidChange := clientIP != "" && user.State.ClientIP != clientIP lastVisitDidChange := user.State.LastVisitDate.Before(time.Now().Add(-time.Hour * 1)) usernameDidChange := false + currentUsername := user.Username - /* - // Check for username change - // Find primary user account - if len(user.Connections) > 0 { - conn := user.Connections[0] - connUsername, connDisplayName := conn.Username() + // Check for username change + // Find primary user account + if len(user.Connections) > 0 { + conn := user.Connections[0] + connUsername, connDisplayName := conn.Username() - usernameDidChange = connUsername != user.Username - if usernameDidChange { - user.Username, user.DisplayName = connUsername, connDisplayName + usernameDidChange = connUsername != user.Username || connDisplayName != user.DisplayName + if usernameDidChange { + user.Username, user.DisplayName = connUsername, connDisplayName - user.SetDiscriminator("") - user.InferUsername() - } - } - */ + user.SetDiscriminator("") + user.InferUsername() + } + } if ipDidChange || lastVisitDidChange || usernameDidChange { user.State.ClientIP = clientIP @@ -82,6 +81,7 @@ func Auth(gctx global.Context) Middleware { m["username"] = user.Username m["display_name"] = user.DisplayName m["state.username_changed_at"] = time.Now() + m["state.former_username"] = currentUsername } if _, err := gctx.Inst().Mongo.Collection(mongo.CollectionNameUsers).UpdateOne(gctx, bson.M{