Compare commits
9 Commits
a8e448b8ca
...
f9a146321c
| Author | SHA1 | Date | |
|---|---|---|---|
| e37a974d9c | |||
| 470591cb44 | |||
| 38114769b3 | |||
| b05473a1c6 | |||
| 0fff694e8a | |||
| d8713298c4 | |||
| 763b0fc4bd | |||
| d8e18d7ffc | |||
| 381f1edb80 |
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"maingate_mongodb_url": "mongodb://...",
|
"maingate_mongodb_url": "mongodb://...",
|
||||||
"autologin_ttl": 604800,
|
"autologin_ttl": 604800,
|
||||||
|
"acc_del_ttl": 7776000,
|
||||||
"maximum_num_link_account": 10,
|
"maximum_num_link_account": 10,
|
||||||
"redirect_base_url": "",
|
"redirect_base_url": "",
|
||||||
"google_client_id" : "",
|
"google_client_id" : "",
|
||||||
|
|||||||
@ -124,6 +124,7 @@ type maingateConfig struct {
|
|||||||
Mongo string `json:"maingate_mongodb_url"`
|
Mongo string `json:"maingate_mongodb_url"`
|
||||||
SessionTTL int64 `json:"maingate_session_ttl"`
|
SessionTTL int64 `json:"maingate_session_ttl"`
|
||||||
Autologin_ttl int64 `json:"autologin_ttl"`
|
Autologin_ttl int64 `json:"autologin_ttl"`
|
||||||
|
AccDelTTL int64 `json:"acc_del_ttl"`
|
||||||
MaximumNumLinkAccount int64 `json:"maximum_num_link_account"`
|
MaximumNumLinkAccount int64 `json:"maximum_num_link_account"`
|
||||||
RedirectBaseUrl string `json:"redirect_base_url"`
|
RedirectBaseUrl string `json:"redirect_base_url"`
|
||||||
GoogleClientId string `json:"google_client_id"`
|
GoogleClientId string `json:"google_client_id"`
|
||||||
@ -354,6 +355,14 @@ func (mg *Maingate) prepare(context context.Context) (err error) {
|
|||||||
return makeErrorWithStack(err)
|
return makeErrorWithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = mg.mongoClient.MakeExpireIndex(CollectionAccount, int32(mg.AccDelTTL)); err != nil {
|
||||||
|
return makeErrorWithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = mg.mongoClient.MakeExpireIndex(CollectionLink, int32(mg.AccDelTTL)); err != nil {
|
||||||
|
return makeErrorWithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
// Delete대신 _ts로 expire시킴. pipeline에 삭제 알려주기 위함
|
// Delete대신 _ts로 expire시킴. pipeline에 삭제 알려주기 위함
|
||||||
if err = mg.mongoClient.MakeExpireIndex(CollectionWhitelist, 10); err != nil {
|
if err = mg.mongoClient.MakeExpireIndex(CollectionWhitelist, 10); err != nil {
|
||||||
return makeErrorWithStack(err)
|
return makeErrorWithStack(err)
|
||||||
|
|||||||
@ -95,7 +95,7 @@ func (p *memberContainerPtr[K, T]) contains(key K, out *T) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if out != nil {
|
if out != nil {
|
||||||
out = &found
|
*out = found
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -678,13 +678,15 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
|
|||||||
"create": createtime,
|
"create": createtime,
|
||||||
"email": email,
|
"email": email,
|
||||||
},
|
},
|
||||||
}, options.FindOneAndUpdate().SetReturnDocument(options.After).SetUpsert(true).SetProjection(bson.M{"_id": 1}))
|
}, options.FindOneAndUpdate().SetReturnDocument(options.After).SetUpsert(true).SetProjection(bson.M{
|
||||||
|
"_id": 1,
|
||||||
|
"_ts": 1,
|
||||||
|
}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("authorize failed :", err)
|
logger.Error("authorize failed :", err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
linkid := link["_id"].(primitive.ObjectID)
|
linkid := link["_id"].(primitive.ObjectID)
|
||||||
newaccid := primitive.NewObjectID()
|
newaccid := primitive.NewObjectID()
|
||||||
for i := 0; i < len(sh.serviceCodeBytes); i++ {
|
for i := 0; i < len(sh.serviceCodeBytes); i++ {
|
||||||
@ -749,6 +751,14 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
|
|||||||
if *noauth {
|
if *noauth {
|
||||||
output["noauth"] = true
|
output["noauth"] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if link["_ts"] != nil {
|
||||||
|
delts := link["_ts"].(primitive.DateTime)
|
||||||
|
if !delts.Time().IsZero() {
|
||||||
|
// 삭제된 계정. 삭제 되었다고 알려주자
|
||||||
|
w.Header().Add("MG-ACCOUNT-DELETED", "TRUE")
|
||||||
|
}
|
||||||
|
}
|
||||||
bt, _ := json.Marshal(output)
|
bt, _ := json.Marshal(output)
|
||||||
w.Write(bt)
|
w.Write(bt)
|
||||||
} else if len(session) > 0 {
|
} else if len(session) > 0 {
|
||||||
@ -824,6 +834,7 @@ func (sh *serviceDescription) delacc(w http.ResponseWriter, r *http.Request) {
|
|||||||
sType := queryvals.Get("stype")
|
sType := queryvals.Get("stype")
|
||||||
sId := queryvals.Get("sid")
|
sId := queryvals.Get("sid")
|
||||||
sk := queryvals.Get("sk")
|
sk := queryvals.Get("sk")
|
||||||
|
cancel := queryvals.Has("cancel")
|
||||||
|
|
||||||
authInfo := sh.auths.Find(sk)
|
authInfo := sh.auths.Find(sk)
|
||||||
if authInfo == nil {
|
if authInfo == nil {
|
||||||
@ -839,7 +850,7 @@ func (sh *serviceDescription) delacc(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
accids, err := sh.mongoClient.FindAll(CollectionAccount, bson.M{
|
linkidMap, err := sh.mongoClient.FindAll(CollectionAccount, bson.M{
|
||||||
"accid": authInfo.Accid,
|
"accid": authInfo.Accid,
|
||||||
}, options.Find().SetProjection(bson.M{
|
}, options.Find().SetProjection(bson.M{
|
||||||
"_id": 1,
|
"_id": 1,
|
||||||
@ -850,27 +861,55 @@ func (sh *serviceDescription) delacc(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var addIdFilter bson.A
|
var linkidAry primitive.A
|
||||||
for _, accid := range accids {
|
for _, linkid := range linkidMap {
|
||||||
addIdFilter = append(addIdFilter, accid["_id"].(primitive.ObjectID))
|
linkidAry = append(linkidAry, linkid["_id"].(primitive.ObjectID))
|
||||||
}
|
}
|
||||||
|
|
||||||
delfilter := bson.D{{Key: "_id", Value: bson.D{{Key: "$in", Value: addIdFilter}}}}
|
delfilter := primitive.M{"_id": bson.M{"$in": linkidAry}}
|
||||||
delaccnum, err := sh.mongoClient.DeleteMany(CollectionAccount, delfilter)
|
var delop primitive.M
|
||||||
if err != nil {
|
if !cancel {
|
||||||
logger.Error("delacc failed. Delete many CollectionAccount err :", err)
|
curtime := primitive.NewDateTimeFromTime(time.Now().UTC())
|
||||||
|
delop = primitive.M{
|
||||||
|
"$set": primitive.M{"_ts": curtime},
|
||||||
|
}
|
||||||
|
|
||||||
|
if sType == AuthPlatformFirebaseAuth {
|
||||||
|
sh.mongoClient.Delete(CollectionFirebaseUserInfo, bson.M{
|
||||||
|
"firebaseuserid": sId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
delfilter["platform"] = sType
|
||||||
|
targetLinkId, err := sh.mongoClient.FindAll(CollectionLink, delfilter, options.Find().SetProjection(bson.M{
|
||||||
|
"_id": 1,
|
||||||
|
}))
|
||||||
|
if len(targetLinkId) != 1 {
|
||||||
|
logger.Error("delacc failed. FindAll link err :", err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
delfilter = primitive.M{"_id": targetLinkId[0]["_id"].(primitive.ObjectID)}
|
||||||
|
delop = primitive.M{
|
||||||
|
"$unset": primitive.M{"_ts": true},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updated, _, err := sh.mongoClient.Update(CollectionAccount, delfilter, delop, options.Update().SetUpsert(false))
|
||||||
|
if !updated || err != nil {
|
||||||
|
logger.Error("delacc failed. Update CollectionAccount timestamp err :", err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = sh.mongoClient.DeleteMany(CollectionLink, delfilter)
|
updated, _, err = sh.mongoClient.Update(CollectionLink, delfilter, delop, options.Update().SetUpsert(false))
|
||||||
if err != nil {
|
if !updated || err != nil {
|
||||||
logger.Error("delacc failed. Delete many CollectionLink err :", err)
|
logger.Error("delacc failed. Update CollectionLink timestamp err :", err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Println("delacc success :", delaccnum)
|
logger.Println("delacc success :", linkidMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request) {
|
func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user