|
@@ -1,26 +1,26 @@
|
|
|
package filter
|
|
|
|
|
|
import (
|
|
|
- "fmt"
|
|
|
- utils "jy/src/jfw/modules/app/src/app/jyutil"
|
|
|
- "jy/src/jfw/modules/app/src/jfw/config"
|
|
|
- "log"
|
|
|
- "net/http"
|
|
|
- "regexp"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
+ "fmt"
|
|
|
+ utils "jy/src/jfw/modules/app/src/app/jyutil"
|
|
|
+ "jy/src/jfw/modules/app/src/jfw/config"
|
|
|
+ "log"
|
|
|
+ "net/http"
|
|
|
+ "regexp"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
|
|
|
- qu "app.yhyue.com/moapp/jybase/common"
|
|
|
- . "app.yhyue.com/moapp/jybase/date"
|
|
|
- "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
- "app.yhyue.com/moapp/jybase/redis"
|
|
|
+ qu "app.yhyue.com/moapp/jybase/common"
|
|
|
+ . "app.yhyue.com/moapp/jybase/date"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
)
|
|
|
|
|
|
type phoneFilter struct {
|
|
|
- W http.ResponseWriter
|
|
|
- R *http.Request
|
|
|
- Session *httpsession.Session
|
|
|
- GetSession map[string]interface{}
|
|
|
+ W http.ResponseWriter
|
|
|
+ R *http.Request
|
|
|
+ Session *httpsession.Session
|
|
|
+ GetSession map[string]interface{}
|
|
|
}
|
|
|
|
|
|
var articleUrl = regexp.MustCompile("^/jyapp/article/.*")
|
|
@@ -28,109 +28,109 @@ var bindurl = []*regexp.Regexp{}
|
|
|
var initflag = true
|
|
|
|
|
|
func init() {
|
|
|
- //初始化不需要过滤的地址
|
|
|
- qu.ReadConfig("./phoneFilter.json", &config.PhoneFilterConfig)
|
|
|
- for _, v := range config.PhoneFilterConfig["regurl"].([]interface{}) {
|
|
|
- bindurl = append(bindurl, regexp.MustCompile(qu.ObjToString(v)))
|
|
|
- }
|
|
|
- if len(bindurl) == 0 {
|
|
|
- log.Println("初始化过滤地址失败。。")
|
|
|
- initflag = false
|
|
|
- }
|
|
|
+ //初始化不需要过滤的地址
|
|
|
+ qu.ReadConfig("./phoneFilter.json", &config.PhoneFilterConfig)
|
|
|
+ for _, v := range config.PhoneFilterConfig["regurl"].([]interface{}) {
|
|
|
+ bindurl = append(bindurl, regexp.MustCompile(qu.ObjToString(v)))
|
|
|
+ }
|
|
|
+ if len(bindurl) == 0 {
|
|
|
+ log.Println("初始化过滤地址失败。。")
|
|
|
+ initflag = false
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func (l *phoneFilter) Do() bool {
|
|
|
- if qu.Int64All(l.GetSession["positionType"]) == 1 {
|
|
|
- return true
|
|
|
- }
|
|
|
+ if qu.Int64All(l.GetSession["positionType"]) == 1 {
|
|
|
+ return true
|
|
|
+ }
|
|
|
userId, _ := l.GetSession["mgoUserId"].(string)
|
|
|
- // 请求过滤
|
|
|
- pass := func() bool {
|
|
|
- if !initflag || l.R.Method == "POST" || userId == "" {
|
|
|
- return true
|
|
|
- }
|
|
|
- if flag, _ := config.Sysconfig["phoneFilterFlag"].(bool); !flag {
|
|
|
- return true
|
|
|
- }
|
|
|
- for _, v := range bindurl {
|
|
|
- if v.MatchString(l.R.URL.Path) && !strings.Contains(l.R.URL.Path, "squeeze") {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- return false
|
|
|
- }()
|
|
|
- if pass {
|
|
|
- return true
|
|
|
- }
|
|
|
- isNewUser := false
|
|
|
- //是否需要跳转绑定手机号
|
|
|
- needBindPhone := func() bool {
|
|
|
- if phone := l.GetSession["phone"]; phone != nil && phone != "" {
|
|
|
- return false
|
|
|
- }
|
|
|
- if person := utils.Compatible.Select(userId, `{"s_phone":1,"s_m_phone":1,"l_registedate":1}`); person != nil {
|
|
|
- s_phone := qu.ObjToString((*person)["s_phone"])
|
|
|
- if s_phone == "" {
|
|
|
- s_phone = qu.ObjToString((*person)["s_m_phone"])
|
|
|
- }
|
|
|
- if s_phone != "" {
|
|
|
- l.Session.Set("phone", s_phone)
|
|
|
- return false
|
|
|
- }
|
|
|
- regtime := qu.Int64All((*person)["l_registedate"])
|
|
|
- reg := time.Unix(regtime, 0)
|
|
|
- //新用户时间
|
|
|
- accountMergeOnline, _ := config.Sysconfig["accountMergeOnline"].(string)
|
|
|
- onLineTime, _ := time.ParseInLocation(Date_Full_Layout, accountMergeOnline, time.Local)
|
|
|
- if onLineTime.After(reg) { //老用户
|
|
|
- dbname, _ := config.Sysconfig["bindPopRedis"].(string)
|
|
|
- key := fmt.Sprintf("bindPop_new_%s", userId)
|
|
|
- if redis.GetInt(dbname, key) >= qu.IntAll(config.Sysconfig["maxBindPop"]) {
|
|
|
- return true
|
|
|
- }
|
|
|
- if articleUrl.MatchString(l.R.URL.Path) {
|
|
|
- bindPopNum := redis.Incr(dbname, key)
|
|
|
- if bindPopNum == qu.Int64All(config.Sysconfig["firstBindPop"]) ||
|
|
|
- bindPopNum > qu.Int64All(config.Sysconfig["maxBindPop"]) {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- return false
|
|
|
- } else {
|
|
|
- isNewUser = true
|
|
|
- }
|
|
|
- //设置cookie 前端跳转
|
|
|
- SetCookie(l.R.URL.String(), int(time.Hour*24/time.Second), l.W)
|
|
|
- return true
|
|
|
- }
|
|
|
- return false
|
|
|
- }()
|
|
|
- var href string
|
|
|
- if needBindPhone {
|
|
|
- href = "/jyapp/account/phone/bind?mode=mergeBind"
|
|
|
- if isNewUser {
|
|
|
- href += "&act=logout"
|
|
|
- }
|
|
|
- } else {
|
|
|
- if exists, _ := redis.Exists("newother", fmt.Sprintf("abnormal_trigger_%s", userId)); exists {
|
|
|
- href = "/jyapp/frontPage/verify/free/index?mode=phoneCheck"
|
|
|
- }
|
|
|
- }
|
|
|
- if href != "" {
|
|
|
- http.Redirect(l.W, l.R, href, 302)
|
|
|
- return false
|
|
|
- }
|
|
|
- return true
|
|
|
+ // 请求过滤
|
|
|
+ pass := func() bool {
|
|
|
+ if !initflag || l.R.Method == "POST" || userId == "" {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ if flag, _ := config.Sysconfig["phoneFilterFlag"].(bool); !flag {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ for _, v := range bindurl {
|
|
|
+ if v.MatchString(l.R.URL.Path) && !strings.Contains(l.R.URL.Path, "squeeze") {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }()
|
|
|
+ if pass {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ isNewUser := false
|
|
|
+ //是否需要跳转绑定手机号
|
|
|
+ needBindPhone := func() bool {
|
|
|
+ if phone := l.GetSession["phone"]; phone != nil && phone != "" {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if person := utils.Compatible.Select(userId, `{"s_phone":1,"s_m_phone":1,"l_registedate":1}`); person != nil {
|
|
|
+ s_phone := qu.ObjToString((*person)["s_phone"])
|
|
|
+ if s_phone == "" {
|
|
|
+ s_phone = qu.ObjToString((*person)["s_m_phone"])
|
|
|
+ }
|
|
|
+ if s_phone != "" {
|
|
|
+ l.Session.Set("phone", s_phone)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ regtime := qu.Int64All((*person)["l_registedate"])
|
|
|
+ reg := time.Unix(regtime, 0)
|
|
|
+ //新用户时间
|
|
|
+ accountMergeOnline, _ := config.Sysconfig["accountMergeOnline"].(string)
|
|
|
+ onLineTime, _ := time.ParseInLocation(Date_Full_Layout, accountMergeOnline, time.Local)
|
|
|
+ if onLineTime.After(reg) { //老用户
|
|
|
+ dbname, _ := config.Sysconfig["bindPopRedis"].(string)
|
|
|
+ key := fmt.Sprintf("bindPop_new_%s", userId)
|
|
|
+ if redis.GetInt(dbname, key) >= qu.IntAll(config.Sysconfig["maxBindPop"]) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ if articleUrl.MatchString(l.R.URL.Path) {
|
|
|
+ bindPopNum := redis.Incr(dbname, key)
|
|
|
+ if bindPopNum == qu.Int64All(config.Sysconfig["firstBindPop"]) ||
|
|
|
+ bindPopNum > qu.Int64All(config.Sysconfig["maxBindPop"]) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ isNewUser = true
|
|
|
+ }
|
|
|
+ //设置cookie 前端跳转
|
|
|
+ SetCookie(l.R.URL.String(), int(time.Hour*24/time.Second), l.W)
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }()
|
|
|
+ var href string
|
|
|
+ if needBindPhone {
|
|
|
+ href = "/jyapp/account/phone/bind?mode=mergeBind"
|
|
|
+ if isNewUser {
|
|
|
+ href += "&act=logout"
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if exists, _ := redis.Exists("newother", fmt.Sprintf("abnormal_trigger_%s", userId)); exists {
|
|
|
+ href = "/jyapp/frontPage/verify/free/index?mode=phoneCheck"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if href != "" {
|
|
|
+ http.Redirect(l.W, l.R, href, 302)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
}
|
|
|
|
|
|
-//文章三级页跳转设置cookie
|
|
|
+// 文章三级页跳转设置cookie
|
|
|
func SetCookie(value string, timeout int, w http.ResponseWriter) {
|
|
|
- c := &http.Cookie{
|
|
|
- Name: "article",
|
|
|
- Value: value,
|
|
|
- Path: "/",
|
|
|
- HttpOnly: true,
|
|
|
- MaxAge: timeout,
|
|
|
- }
|
|
|
- http.SetCookie(w, c)
|
|
|
+ c := &http.Cookie{
|
|
|
+ Name: "article",
|
|
|
+ Value: value,
|
|
|
+ Path: "/",
|
|
|
+ HttpOnly: true,
|
|
|
+ MaxAge: timeout,
|
|
|
+ }
|
|
|
+ http.SetCookie(w, c)
|
|
|
}
|