|
@@ -10,6 +10,7 @@ package captcha
|
|
|
**/
|
|
|
|
|
|
import (
|
|
|
+ "app.yhyue.com/moapp/jybase/captcha/phoneCache"
|
|
|
"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
"fmt"
|
|
|
"net/http"
|
|
@@ -42,6 +43,7 @@ func InitCaptcha() {
|
|
|
ClickBasicCaptcha()
|
|
|
ClickShapeCaptcha()
|
|
|
RotateCaptcha()
|
|
|
+ go phoneCache.RunTimedTask()
|
|
|
}
|
|
|
|
|
|
func (c *GetCaptcha) GetCaptchaData() (cd CaptRes, err error) {
|
|
@@ -49,34 +51,7 @@ func (c *GetCaptcha) GetCaptchaData() (cd CaptRes, err error) {
|
|
|
err = fmt.Errorf("phone param is empty or incorrect")
|
|
|
return
|
|
|
}
|
|
|
- var times int
|
|
|
- //CaptLock.Lock()
|
|
|
- //captLock := CaptLockMap[c.Phone]
|
|
|
- //if captLock == nil {
|
|
|
- // CaptLockMap[c.Phone] = &sync.Mutex{}
|
|
|
- // captLock = CaptLockMap[c.Phone]
|
|
|
- //}
|
|
|
- //CaptLock.Unlock()
|
|
|
- //captLock.Lock()
|
|
|
- //timesPhoneKey := fmt.Sprintf(TimesCacheKey, c.Phone)
|
|
|
- //timesSessIdKey := fmt.Sprintf(TimesCacheKey, c.Sess.Id())
|
|
|
- //timesByPhone := redis.GetInt(RedisCode, timesPhoneKey)
|
|
|
- //timesBySessId := redis.GetInt(RedisCode, timesSessIdKey)
|
|
|
- //times = func() int {
|
|
|
- // if timesBySessId < timesByPhone {
|
|
|
- // return timesByPhone
|
|
|
- // }
|
|
|
- // return timesBySessId
|
|
|
- //}()
|
|
|
- //go func(times int, timesPhoneKey, timesSessIdKey string) {
|
|
|
- // if times == 0 {
|
|
|
- // redis.Put(RedisCode, timesPhoneKey, times, 24*60*60)
|
|
|
- // redis.Put(RedisCode, timesSessIdKey, times, 24*60*60)
|
|
|
- // }
|
|
|
- // redis.Incr(RedisCode, timesPhoneKey)
|
|
|
- // redis.Incr(RedisCode, timesSessIdKey)
|
|
|
- //}(times, timesPhoneKey, timesSessIdKey)
|
|
|
- //captLock.Unlock()
|
|
|
+ var times = phoneCache.GetAccessCount(c.Phone)
|
|
|
switch {
|
|
|
case times < MiniTimes:
|
|
|
return c.GetSlideCaptchaData()
|