diff --git a/core/api.go b/core/api.go index 769f4cf..21c2fe2 100644 --- a/core/api.go +++ b/core/api.go @@ -357,123 +357,6 @@ func (caller apiCaller) maintenanceAPI(w http.ResponseWriter, r *http.Request) e return nil } -func (caller apiCaller) accountAPI(w http.ResponseWriter, r *http.Request) error { - mg := caller.mg - queryvals := r.URL.Query() - if r.Method == "GET" { - service := queryvals.Get("service") - if len(service) == 0 { - return nil - } - - if !caller.isAdminOrValidToken() { - logger.Println("accountAPI failed. not vaild user :", r.Method, caller.userinfo) - w.WriteHeader(http.StatusUnauthorized) - return nil - } - - var accdoc primitive.M - if v := queryvals.Get("accid"); len(v) == 0 { - email := queryvals.Get("email") - platform := queryvals.Get("platform") - if len(email) == 0 || len(platform) == 0 { - return nil - } - - found, err := mg.mongoClient.FindOne(CollectionLink, bson.M{ - "email": email, - "platform": platform, - }) - if err != nil { - return err - } - if found == nil { - return nil - } - if idobj, ok := found["_id"]; ok { - svcdoc, err := mg.mongoClient.FindOne(common.CollectionName(service), bson.M{ - "_id": idobj, - }) - if err != nil { - return err - } - if svcdoc != nil { - found["accid"] = svcdoc["accid"] - } - - accdoc = found - } - } else { - accid, err := primitive.ObjectIDFromHex(v) - if err != nil { - return err - } - - svcdoc, err := mg.mongoClient.FindOne(common.CollectionName(service), bson.M{ - "accid": accid, - }) - if err != nil { - return err - } - - found, err := mg.mongoClient.FindOne(CollectionLink, bson.M{ - "_id": svcdoc["_id"], - }) - if err != nil { - return err - } - - if found != nil { - found["accid"] = accid - } - accdoc = found - } - - if accdoc != nil { - accdoc["code"] = service - delete(accdoc, "uid") - delete(accdoc, "_id") - - var bi blockinfo - if err := mg.mongoClient.FindOneAs(CollectionBlock, bson.M{ - "code": service, - "accid": accdoc["accid"], - }, &bi); err != nil { - return err - } - - if !bi.Start.Time().IsZero() && bi.End.Time().After(time.Now().UTC()) { - accdoc["blocked"] = bi - } - return json.NewEncoder(w).Encode(accdoc) - } - } else if r.Method == "POST" { - var account struct { - Code string - Accid string - Blocked blockinfo - } - - body, _ := io.ReadAll(r.Body) - if err := json.Unmarshal(body, &account); err != nil { - return err - } - - accid, _ := primitive.ObjectIDFromHex(account.Accid) - if !account.Blocked.Start.Time().IsZero() && account.Blocked.Start.Time().After(time.Now().UTC()) { - if _, _, err := mg.mongoClient.Update(CollectionBlock, bson.M{ - "code": account.Code, - "accid": accid, - }, bson.M{ - "$set": account.Blocked, - }, options.Update().SetUpsert(true)); err != nil { - return err - } - } - } - return nil -} - var errApiTokenMissing = errors.New("mg-x-api-token is missing") func (caller apiCaller) configAPI(w http.ResponseWriter, r *http.Request) error { @@ -583,8 +466,6 @@ func (mg *Maingate) api(w http.ResponseWriter, r *http.Request) { err = caller.whitelistAPI(w, r) } else if strings.HasSuffix(r.URL.Path, "/config") { err = caller.configAPI(w, r) - } else if strings.HasSuffix(r.URL.Path, "/account") { - err = caller.accountAPI(w, r) } else if strings.HasSuffix(r.URL.Path, "/upload") { err = caller.uploadAPI(w, r) } else if strings.HasSuffix(r.URL.Path, "/maintenance") { diff --git a/core/maingate.go b/core/maingate.go index d351838..d89de86 100644 --- a/core/maingate.go +++ b/core/maingate.go @@ -38,6 +38,7 @@ var ( CollectionAuth = common.CollectionName("auth") CollectionWhitelist = common.CollectionName("whitelist") CollectionService = common.CollectionName("service") + CollectionAccount = common.CollectionName("account") CollectionFile = common.CollectionName("file") CollectionBlock = common.CollectionName("block") CollectionPlatformLoginToken = common.CollectionName("platform_login_token") //-- 각 플랫폼에 로그인 및 권한 받아오는 과정에 사용하는 Key diff --git a/core/service.go b/core/service.go index c6109dc..999d223 100644 --- a/core/service.go +++ b/core/service.go @@ -370,7 +370,7 @@ func (sh *serviceDescription) link(w http.ResponseWriter, r *http.Request) { return } - _, newid, err := sh.mongoClient.Update(CollectionService, bson.M{ + _, newid, err := sh.mongoClient.Update(CollectionAccount, bson.M{ "_id": link["_id"].(primitive.ObjectID), }, bson.M{ "$setOnInsert": bson.M{ @@ -479,7 +479,7 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request) for i := 0; i < len(sh.serviceCodeBytes); i++ { newaccid[i] ^= sh.serviceCodeBytes[i] } - account, err := sh.mongoClient.FindOneAndUpdate(CollectionService, bson.M{ + account, err := sh.mongoClient.FindOneAndUpdate(CollectionAccount, bson.M{ "_id": linkid, }, bson.M{ "$setOnInsert": bson.M{