session.provider로 교체
This commit is contained in:
@ -14,6 +14,7 @@ import (
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
"repositories.action2quare.com/ayo/gocommon/session"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@ -111,11 +112,11 @@ type serviceDescription struct {
|
||||
MaximumNumLinkAccount int64
|
||||
VersionSplits map[string]string `bson:"version_splits" json:"version_splits"`
|
||||
|
||||
auths *gocommon.AuthCollection
|
||||
wl memberContainerPtr[string, *whitelistmember]
|
||||
bl memberContainerPtr[primitive.ObjectID, *blockinfo]
|
||||
mongoClient gocommon.MongoClient
|
||||
sessionTTL time.Duration
|
||||
sessionProvider session.Provider
|
||||
wl memberContainerPtr[string, *whitelistmember]
|
||||
bl memberContainerPtr[primitive.ObjectID, *blockinfo]
|
||||
mongoClient gocommon.MongoClient
|
||||
sessionTTL time.Duration
|
||||
|
||||
serviceCodeBytes []byte
|
||||
getUserBrowserInfo func(r *http.Request) (string, error)
|
||||
@ -251,7 +252,7 @@ func (sh *serviceDescription) prepare(mg *Maingate) error {
|
||||
|
||||
sh.MaximumNumLinkAccount = mg.maingateConfig.MaximumNumLinkAccount
|
||||
sh.mongoClient = mg.mongoClient
|
||||
sh.auths = mg.auths
|
||||
sh.sessionProvider = mg.sessionProvider
|
||||
sh.sessionTTL = time.Duration(mg.SessionTTL * int64(time.Second))
|
||||
sh.serviceCodeBytes, _ = hex.DecodeString(sh.ServiceCode)
|
||||
sh.getUserBrowserInfo = mg.GetUserBrowserInfo
|
||||
@ -291,11 +292,10 @@ func (sh *serviceDescription) link(w http.ResponseWriter, r *http.Request) {
|
||||
newType := queryvals.Get("ntype")
|
||||
newId := queryvals.Get("nid")
|
||||
|
||||
oldAuth := sh.auths.Find(sk)
|
||||
if oldAuth == nil {
|
||||
// 잘못된 세션
|
||||
logger.Println("link failed. session key is not valid :", sk)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
oldAuth, err := sh.sessionProvider.Query(sk)
|
||||
if err != nil {
|
||||
logger.Println("sessionProvider.Query return err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@ -370,7 +370,7 @@ func (sh *serviceDescription) link(w http.ResponseWriter, r *http.Request) {
|
||||
"_id": link["_id"].(primitive.ObjectID),
|
||||
}, bson.M{
|
||||
"$setOnInsert": bson.M{
|
||||
"accid": oldAuth.Accid,
|
||||
"accid": oldAuth.Account,
|
||||
"create": createtime,
|
||||
},
|
||||
}, options.Update().SetUpsert(true))
|
||||
@ -410,11 +410,10 @@ func (sh *serviceDescription) unlink(w http.ResponseWriter, r *http.Request) {
|
||||
sId := queryvals.Get("sid")
|
||||
sk := queryvals.Get("sk")
|
||||
|
||||
authInfo := sh.auths.Find(sk)
|
||||
if authInfo == nil {
|
||||
// 잘못된 세션
|
||||
logger.Println("linkinfo failed. session key is not valid :", sk)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
authInfo, err := sh.sessionProvider.Query(sk)
|
||||
if err != nil {
|
||||
logger.Println("sessionProvider.Query return err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@ -433,7 +432,7 @@ func (sh *serviceDescription) unlink(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
numRecord, err := sh.mongoClient.Collection(CollectionAccount).CountDocuments(context.Background(), bson.M{
|
||||
"accid": authInfo.Accid,
|
||||
"accid": authInfo.Account,
|
||||
}, options.Count().SetLimit(2))
|
||||
|
||||
if err != nil {
|
||||
@ -502,11 +501,10 @@ func (sh *serviceDescription) linkinfo(w http.ResponseWriter, r *http.Request) {
|
||||
sId := queryvals.Get("sid")
|
||||
sk := queryvals.Get("sk")
|
||||
|
||||
authInfo := sh.auths.Find(sk)
|
||||
if authInfo == nil {
|
||||
// 잘못된 세션
|
||||
logger.Println("linkinfo failed. session key is not valid :", sk)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
authInfo, err := sh.sessionProvider.Query(sk)
|
||||
if err != nil {
|
||||
logger.Println("sessionProvider.Query return err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@ -526,7 +524,7 @@ func (sh *serviceDescription) linkinfo(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
numRecord, err := sh.mongoClient.Collection(CollectionAccount).CountDocuments(context.Background(), bson.M{
|
||||
"accid": authInfo.Accid,
|
||||
"accid": authInfo.Account,
|
||||
}, options.Count().SetLimit(sh.MaximumNumLinkAccount))
|
||||
|
||||
if err != nil {
|
||||
@ -767,7 +765,14 @@ func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request)
|
||||
// TODO : 각 서버에 있는 자산? 캐릭터 정보를 보여줘야 하나. 뭘 보여줄지는 프로젝트에 문의
|
||||
// 일단 서버 종류만 내려보내자
|
||||
// 세션키가 있는지 확인
|
||||
if _, ok := sh.auths.IsValid(sk, ""); !ok {
|
||||
authInfo, err := sh.sessionProvider.Query(sk)
|
||||
if err != nil {
|
||||
logger.Println("sessionProvider.Query return err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if authInfo == nil {
|
||||
logger.Println("sessionkey is not valid :", sk)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
@ -788,7 +793,14 @@ func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request)
|
||||
// TODO : 각 서버에 있는 자산? 캐릭터 정보를 보여줘야 하나. 뭘 보여줄지는 프로젝트에 문의
|
||||
// 일단 서버 종류만 내려보내자
|
||||
// 세션키가 있는지 확인
|
||||
if _, ok := sh.auths.IsValid(sk, ""); !ok {
|
||||
authInfo, err := sh.sessionProvider.Query(sk)
|
||||
if err != nil {
|
||||
logger.Println("sessionProvider.Query return err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if authInfo == nil {
|
||||
logger.Println("sessionkey is not valid :", sk)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
@ -804,13 +816,14 @@ func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
case DivisionState_RestrictedOpen:
|
||||
// 점검중이면 whitelist만 입장 가능
|
||||
cell := sh.auths.QuerySession(sk, "")
|
||||
if cell == nil {
|
||||
logger.Println("sessionkey is not valid :", sk)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
authInfo, err := sh.sessionProvider.Query(sk)
|
||||
if err != nil {
|
||||
logger.Println("sessionProvider.Query return err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
wm := &whitelistmember{Email: cell.ToAuthinfo().Email, Platform: cell.ToAuthinfo().Platform}
|
||||
|
||||
wm := &whitelistmember{Email: authInfo.Email, Platform: authInfo.Platform}
|
||||
if sh.wl.contains(wm.Key(), nil) {
|
||||
// qa 권한이면 입장 가능
|
||||
w.Write([]byte(fmt.Sprintf(`{"service":"%s"}`, div.Url)))
|
||||
|
||||
Reference in New Issue
Block a user