계정 제재 개선
This commit is contained in:
54
core/api.go
54
core/api.go
@ -160,9 +160,12 @@ func (caller apiCaller) uploadAPI(w http.ResponseWriter, r *http.Request) error
|
|||||||
|
|
||||||
func (caller apiCaller) blockAPI(w http.ResponseWriter, r *http.Request) error {
|
func (caller apiCaller) blockAPI(w http.ResponseWriter, r *http.Request) error {
|
||||||
mg := caller.mg
|
mg := caller.mg
|
||||||
|
logger.Println("blockAPI :", r.Method)
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
target, ok := gocommon.ReadObjectIDFormValue(r.Form, "accid")
|
target, ok := gocommon.ReadObjectIDFormValue(r.Form, "accid")
|
||||||
|
logger.Println("Get :", target, ok)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
// 페이지네이션 해야할 듯
|
||||||
json.NewEncoder(w).Encode(mg.bl.all())
|
json.NewEncoder(w).Encode(mg.bl.all())
|
||||||
} else if !target.IsZero() {
|
} else if !target.IsZero() {
|
||||||
if blocked, ok := mg.bl.get(target); ok && blocked != nil {
|
if blocked, ok := mg.bl.get(target); ok && blocked != nil {
|
||||||
@ -170,37 +173,34 @@ func (caller apiCaller) blockAPI(w http.ResponseWriter, r *http.Request) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if r.Method == "PUT" {
|
} else if r.Method == "PUT" {
|
||||||
body, _ := io.ReadAll(r.Body)
|
var targets struct {
|
||||||
|
Start primitive.DateTime
|
||||||
var bipl blockinfoWithStringId
|
End primitive.DateTime
|
||||||
if err := json.Unmarshal(body, &bipl); err != nil {
|
Accounts map[primitive.ObjectID]primitive.M // accid->meta
|
||||||
|
}
|
||||||
|
if err := gocommon.MakeDecoder(r).Decode(&targets); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
accid, err := primitive.ObjectIDFromHex(bipl.StrId)
|
for accid, meta := range targets.Accounts {
|
||||||
if err != nil {
|
bi := blockinfo{
|
||||||
return err
|
Start: targets.Start,
|
||||||
|
End: targets.End,
|
||||||
|
Meta: meta,
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, err := mg.mongoClient.Update(CollectionBlock, bson.M{
|
||||||
|
"_id": accid,
|
||||||
|
}, bson.M{
|
||||||
|
"$set": &bi,
|
||||||
|
}, options.Update().SetUpsert(true))
|
||||||
|
if err != nil {
|
||||||
|
logger.Println("account is not blocked. err :", err)
|
||||||
|
} else {
|
||||||
|
logger.Println("account is blocked :", meta)
|
||||||
|
mg.sessionProvider.Delete(accid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bi := blockinfo{
|
|
||||||
Start: primitive.NewDateTimeFromTime(time.Unix(bipl.StartUnix, 0)),
|
|
||||||
End: primitive.NewDateTimeFromTime(time.Unix(bipl.EndUnix, 0)),
|
|
||||||
Reason: bipl.Reason,
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.Println("bi :", accid, bi)
|
|
||||||
|
|
||||||
_, _, err = mg.mongoClient.Update(CollectionBlock, bson.M{
|
|
||||||
"_id": accid,
|
|
||||||
}, bson.M{
|
|
||||||
"$set": &bi,
|
|
||||||
}, options.Update().SetUpsert(true))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
mg.sessionProvider.Delete(accid)
|
|
||||||
} else if r.Method == "DELETE" {
|
} else if r.Method == "DELETE" {
|
||||||
id := r.URL.Query().Get("id")
|
id := r.URL.Query().Get("id")
|
||||||
|
|
||||||
|
|||||||
@ -1,39 +1,9 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
|
||||||
"repositories.action2quare.com/ayo/gocommon"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMakeLocalUniqueId(t *testing.T) {
|
func TestMakeLocalUniqueId(t *testing.T) {
|
||||||
ts := int64(1690815600)
|
|
||||||
start := primitive.NewDateTimeFromTime(time.Unix(ts, 0))
|
|
||||||
ts = int64(1693493999)
|
|
||||||
end := primitive.NewDateTimeFromTime(time.Unix(ts, 0))
|
|
||||||
|
|
||||||
fmt.Println(start.Time().Format(time.RFC3339))
|
|
||||||
fmt.Println(end.Time().Format(time.RFC3339))
|
|
||||||
|
|
||||||
mongoClient, err := gocommon.NewMongoClient(context.Background(), "mongodb://121.134.91.160:27018/?replicaSet=rs0&retrywrites=true")
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
bi := blockinfo{
|
|
||||||
Start: start,
|
|
||||||
End: end,
|
|
||||||
Reason: "test",
|
|
||||||
}
|
|
||||||
mongoClient.Update(CollectionBlock, bson.M{
|
|
||||||
"_id": primitive.NewObjectID(),
|
|
||||||
}, bson.M{
|
|
||||||
"$set": &bi,
|
|
||||||
}, options.Update().SetUpsert(true))
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -387,6 +387,8 @@ func (mg *Maingate) prepare(context context.Context) (err error) {
|
|||||||
if err := mg.mongoClient.AllAs(CollectionBlock, &blocks); err != nil {
|
if err := mg.mongoClient.AllAs(CollectionBlock, &blocks); err != nil {
|
||||||
return logger.ErrorWithCallStack(err)
|
return logger.ErrorWithCallStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Println("allblocks :", blocks)
|
||||||
mg.bl.init(blocks)
|
mg.bl.init(blocks)
|
||||||
|
|
||||||
go mg.wl.watchCollection(context, CollectionWhitelist, mg.mongoClient)
|
go mg.wl.watchCollection(context, CollectionWhitelist, mg.mongoClient)
|
||||||
@ -870,15 +872,6 @@ func JWTparseCode(keyurl string, code string) (string, string, string) {
|
|||||||
return claims["sub"].(string), email, nonce
|
return claims["sub"].(string), email, nonce
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mg *Maingate) google_analytics_html(w http.ResponseWriter, r *http.Request) {
|
|
||||||
parsedTemplate, _ := template.ParseFiles("template/track-event.html")
|
|
||||||
err := parsedTemplate.Execute(w, nil)
|
|
||||||
if err != nil {
|
|
||||||
logger.Error("Error executing template :", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mg *Maingate) google_analytics_js(w http.ResponseWriter, r *http.Request) {
|
func (mg *Maingate) google_analytics_js(w http.ResponseWriter, r *http.Request) {
|
||||||
fgaconfig := Firebase_Google_Analytics_JS_SDK_Config{
|
fgaconfig := Firebase_Google_Analytics_JS_SDK_Config{
|
||||||
FGA_apiKey: mg.FGA_apiKey,
|
FGA_apiKey: mg.FGA_apiKey,
|
||||||
|
|||||||
@ -22,17 +22,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type blockinfo struct {
|
type blockinfo struct {
|
||||||
Start primitive.DateTime `bson:"start" json:"start"`
|
Start primitive.DateTime `bson:"start" json:"start"`
|
||||||
End primitive.DateTime `bson:"_ts" json:"_ts"`
|
End primitive.DateTime `bson:"_ts" json:"_ts"`
|
||||||
Reason string `bson:"reason" json:"reason"`
|
Accid primitive.ObjectID `bson:"_id,omitempty" json:"_id,omitempty"`
|
||||||
Accid primitive.ObjectID `bson:"_id,omitempty" json:"_id,omitempty"`
|
Meta primitive.M `bson:"meta,omitempty" json:"meta,omitempty"`
|
||||||
}
|
|
||||||
|
|
||||||
type blockinfoWithStringId struct {
|
|
||||||
Reason string `bson:"reason" json:"reason"`
|
|
||||||
StrId string `bson:"id" json:"id"`
|
|
||||||
StartUnix int64 `bson:"start_unix" json:"start_unix"`
|
|
||||||
EndUnix int64 `bson:"end_unix" json:"end_unix"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type whitelistmember struct {
|
type whitelistmember struct {
|
||||||
@ -663,7 +656,6 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
|
|||||||
// 블럭된 계정. 블락 정보를 알려준다.
|
// 블럭된 계정. 블락 정보를 알려준다.
|
||||||
w.Header().Add("MG-ACCOUNTBLOCK-START", strconv.FormatInt(bi.Start.Time().Unix(), 10))
|
w.Header().Add("MG-ACCOUNTBLOCK-START", strconv.FormatInt(bi.Start.Time().Unix(), 10))
|
||||||
w.Header().Add("MG-ACCOUNTBLOCK-END", strconv.FormatInt(bi.End.Time().Unix(), 10))
|
w.Header().Add("MG-ACCOUNTBLOCK-END", strconv.FormatInt(bi.End.Time().Unix(), 10))
|
||||||
w.Header().Add("MG-ACCOUNTBLOCK-REASON", bi.Reason)
|
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user