...
|
...
|
@@ -56,13 +56,13 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp |
|
|
}
|
|
|
break
|
|
|
case protocol.LoginTypeSmdcode:
|
|
|
if beego.BConfig.RunMode =="dev"{
|
|
|
goto Success
|
|
|
}
|
|
|
//if beego.BConfig.RunMode =="dev"{
|
|
|
// goto Success
|
|
|
//}
|
|
|
if result, err = CheckSmsCode(request.Phone, request.Code, protocol.SmsCode); result && err == nil {
|
|
|
goto Success
|
|
|
} else {
|
|
|
err = protocol.NewErrWithMessage(1012, err)
|
|
|
//err = protocol.NewErrWithMessage(1012, err)
|
|
|
return
|
|
|
}
|
|
|
default:
|
...
|
...
|
@@ -278,7 +278,8 @@ func SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, e |
|
|
smsInfo.Count = 0
|
|
|
smsInfo.CreateTime = time.Now().Unix()
|
|
|
}
|
|
|
if smsInfo.Count > 100 { //TODO:limit send time
|
|
|
if smsInfo.Count > protocol.SmscodeDayLimitTime { //TODO:limit send time
|
|
|
err=protocol.NewErrWithMessage(1011)
|
|
|
return
|
|
|
}
|
|
|
goto Send
|
...
|
...
|
@@ -319,31 +320,40 @@ func CheckSmsCode(phone, code, sendType string) (result bool, err error) { |
|
|
)
|
|
|
result = false
|
|
|
if value, err = redis.Hget(sendType, phone); err != nil { //protocol.SmsLoginCode
|
|
|
err = common.NewErrorWithMsg(1009, "smscode expire")
|
|
|
log.Error(fmt.Sprintf("smscode not exists"))
|
|
|
err =protocol.NewErrWithMessage(1009,fmt.Errorf("smscode expire"))
|
|
|
return
|
|
|
}
|
|
|
if err = json.Unmarshal([]byte(value), &smsInfo); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if smsInfo.ErrorCount >= 5 {
|
|
|
err = common.NewErrorWithMsg(1011, "smscode over error times")
|
|
|
log.Error(fmt.Sprintf("smscode over error times"))
|
|
|
err =protocol.NewErrWithMessage(1009)
|
|
|
return
|
|
|
}
|
|
|
if (smsInfo.LastTime + 60*5) < time.Now().Unix() {
|
|
|
err = common.NewErrorWithMsg(1009, fmt.Sprintf("smscode expire %v < %v", (smsInfo.LastTime+60*5), time.Now().Unix()))
|
|
|
log.Error(fmt.Sprintf("smscode expire %v < %v", (smsInfo.LastTime+60*5), time.Now().Unix()))
|
|
|
err =protocol.NewErrWithMessage(1009)
|
|
|
goto Fail
|
|
|
}
|
|
|
if smsInfo.Code == code {
|
|
|
result = true
|
|
|
return
|
|
|
} else {
|
|
|
err = common.NewErrorWithMsg(1012, "smscode error")
|
|
|
log.Error("smscode not equal:",smsInfo.Code,code)
|
|
|
err = protocol.NewErrWithMessage(1012)
|
|
|
goto Fail
|
|
|
}
|
|
|
Fail:
|
|
|
{
|
|
|
smsInfo.ErrorCount += 1
|
|
|
if err = redis.Hset(sendType, phone, common.AssertJson(smsInfo), -1); err != nil {
|
|
|
if e := redis.Hset(sendType, phone, common.AssertJson(smsInfo), -1); e != nil {
|
|
|
log.Error(e)
|
|
|
if err==nil{
|
|
|
err =e
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
}
|
...
|
...
|
|