package filter import ( "fmt" "app.yhyue.com/moapp/jypkg/jyutil" "log" "net/http" "strings" "app.yhyue.com/moapp/jybase/redis" "app.yhyue.com/moapp/jybase/mongodb" "app.yhyue.com/moapp/jybase/go-xweb/httpsession" ) //用户合并删除用户检测 type mergeFilter struct { W http.ResponseWriter R *http.Request Session *httpsession.Session GetSession map[string]interface{} } func (l *mergeFilter) Do() bool { if uid := l.GetSession["userId"]; uid != nil && uid != "" { if val := redis.Get("session", fmt.Sprintf("usermerge_delete_%s", uid)); val != nil { if sUid, ok := val.(string); sUid != "" && ok { //自动更新当前session为合并后账户 if _, sessionVal := jyutil.GetSessionVal(map[string]interface{}{"_id": mongodb.StringTOBsonId(sUid)}); len(sessionVal) > 0 { log.Printf("账户合并 mergeFilter 自动刷新session old:%s new:%s\n", uid, sUid) l.Session.SetMultiple(sessionVal) return true } } if l.R.Method == "GET" { sessId := l.Session.Id() redis.Del("session", sessId) if strings.HasPrefix(l.R.RequestURI, "/front/sess/") { http.Redirect(l.W, l.R, l.R.RequestURI, 302) } else { http.Redirect(l.W, l.R, "/", 302) } return false } } } //微信解绑-刷新session if sod, uid := l.GetSession["s_m_openid"], l.GetSession["userId"]; sod != nil && sod != "" && uid != nil && uid != "" { if mergerTimeStamp := redis.GetStr("session", fmt.Sprintf("accountInfo_unbindWx_%s_%s", uid, sod)); mergerTimeStamp != "" { //每个sessionid仅清除一次 if doOncekey := fmt.Sprintf("accountInfo_unbindWx_%s_%s_%s_%s", uid, sod, l.Session.Id(), mergerTimeStamp); redis.Get("session", doOncekey) == nil { //删除企业相关session for _, entSessionKey := range []string{"entId", "entName", "entUserId", "frameworkEntId", "frameworkEntName"} { l.Session.Del(entSessionKey) } redis.Put("session", doOncekey, 1, 60*60*24) _, sessionVal := jyutil.GetSessionVal(map[string]interface{}{"s_m_openid": sod}) if len(sessionVal) > 0 { l.Session.SetMultiple(sessionVal) } } } } return true }