Compare commits

..

9 Commits

Author SHA1 Message Date
e37a974d9c [이민권] 계정 삭제
- 계정 삭제 시, Firebase 정보 삭제
2024-01-12 12:31:21 +09:00
470591cb44 [이민권] 계정 삭제
- 계정 삭제 취소 기능 추가
2024-01-11 19:11:43 +09:00
38114769b3 [이민권] 계정 삭제
- 계정 삭제 취소 기능 추가
2024-01-11 12:54:48 +09:00
b05473a1c6 [이민권] 계정 삭제
- 계정 삭제 취소 기능 추가
2024-01-10 18:40:38 +09:00
0fff694e8a [이민권] 계정 삭제
- 계정 삭제 취소 기능 추가
2024-01-10 18:10:18 +09:00
d8713298c4 [이민권] 계정 삭제
- 계정 삭제 취소 기능 추가
2024-01-10 17:35:00 +09:00
763b0fc4bd [이민권] 계정 삭제
- 계정 삭제 취소 기능 추가
2024-01-10 17:28:24 +09:00
d8e18d7ffc [이민권] 서비스 준비
- 계정 삭제 시, TTL 적용
2024-01-09 19:56:57 +09:00
381f1edb80 [이민우] 정보가 아니라 주소갑이 나와서 수정 (대리 커밋) 2023-12-08 17:08:14 +09:00
4 changed files with 64 additions and 15 deletions

View File

@ -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" : "",

View File

@ -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)

View File

@ -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
} }

View File

@ -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) w.WriteHeader(http.StatusInternalServerError)
return return
} }
_, err = sh.mongoClient.DeleteMany(CollectionLink, delfilter) delfilter = primitive.M{"_id": targetLinkId[0]["_id"].(primitive.ObjectID)}
if err != nil { delop = primitive.M{
logger.Error("delacc failed. Delete many CollectionLink err :", err) "$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
} }
logger.Println("delacc success :", delaccnum) updated, _, err = sh.mongoClient.Update(CollectionLink, delfilter, delop, options.Update().SetUpsert(false))
if !updated || err != nil {
logger.Error("delacc failed. Update CollectionLink timestamp err :", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
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) {