|
@@ -56,13 +56,13 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp |
|
@@ -56,13 +56,13 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp |
56
|
}
|
56
|
}
|
57
|
break
|
57
|
break
|
58
|
case protocol.LoginTypeSmdcode:
|
58
|
case protocol.LoginTypeSmdcode:
|
59
|
- if beego.BConfig.RunMode =="dev"{
|
|
|
60
|
- goto Success
|
|
|
61
|
- }
|
59
|
+ //if beego.BConfig.RunMode =="dev"{
|
|
|
60
|
+ // goto Success
|
|
|
61
|
+ //}
|
62
|
if result, err = CheckSmsCode(request.Phone, request.Code, protocol.SmsCode); result && err == nil {
|
62
|
if result, err = CheckSmsCode(request.Phone, request.Code, protocol.SmsCode); result && err == nil {
|
63
|
goto Success
|
63
|
goto Success
|
64
|
} else {
|
64
|
} else {
|
65
|
- err = protocol.NewErrWithMessage(1012, err)
|
65
|
+ //err = protocol.NewErrWithMessage(1012, err)
|
66
|
return
|
66
|
return
|
67
|
}
|
67
|
}
|
68
|
default:
|
68
|
default:
|
|
@@ -278,7 +278,8 @@ func SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, e |
|
@@ -278,7 +278,8 @@ func SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, e |
278
|
smsInfo.Count = 0
|
278
|
smsInfo.Count = 0
|
279
|
smsInfo.CreateTime = time.Now().Unix()
|
279
|
smsInfo.CreateTime = time.Now().Unix()
|
280
|
}
|
280
|
}
|
281
|
- if smsInfo.Count > 100 { //TODO:limit send time
|
281
|
+ if smsInfo.Count > protocol.SmscodeDayLimitTime { //TODO:limit send time
|
|
|
282
|
+ err=protocol.NewErrWithMessage(1011)
|
282
|
return
|
283
|
return
|
283
|
}
|
284
|
}
|
284
|
goto Send
|
285
|
goto Send
|
|
@@ -319,31 +320,40 @@ func CheckSmsCode(phone, code, sendType string) (result bool, err error) { |
|
@@ -319,31 +320,40 @@ func CheckSmsCode(phone, code, sendType string) (result bool, err error) { |
319
|
)
|
320
|
)
|
320
|
result = false
|
321
|
result = false
|
321
|
if value, err = redis.Hget(sendType, phone); err != nil { //protocol.SmsLoginCode
|
322
|
if value, err = redis.Hget(sendType, phone); err != nil { //protocol.SmsLoginCode
|
322
|
- err = common.NewErrorWithMsg(1009, "smscode expire")
|
323
|
+ log.Error(fmt.Sprintf("smscode not exists"))
|
|
|
324
|
+ err =protocol.NewErrWithMessage(1009,fmt.Errorf("smscode expire"))
|
323
|
return
|
325
|
return
|
324
|
}
|
326
|
}
|
325
|
if err = json.Unmarshal([]byte(value), &smsInfo); err != nil {
|
327
|
if err = json.Unmarshal([]byte(value), &smsInfo); err != nil {
|
|
|
328
|
+ log.Error(err)
|
326
|
return
|
329
|
return
|
327
|
}
|
330
|
}
|
328
|
if smsInfo.ErrorCount >= 5 {
|
331
|
if smsInfo.ErrorCount >= 5 {
|
329
|
- err = common.NewErrorWithMsg(1011, "smscode over error times")
|
332
|
+ log.Error(fmt.Sprintf("smscode over error times"))
|
|
|
333
|
+ err =protocol.NewErrWithMessage(1009)
|
330
|
return
|
334
|
return
|
331
|
}
|
335
|
}
|
332
|
if (smsInfo.LastTime + 60*5) < time.Now().Unix() {
|
336
|
if (smsInfo.LastTime + 60*5) < time.Now().Unix() {
|
333
|
- err = common.NewErrorWithMsg(1009, fmt.Sprintf("smscode expire %v < %v", (smsInfo.LastTime+60*5), time.Now().Unix()))
|
337
|
+ log.Error(fmt.Sprintf("smscode expire %v < %v", (smsInfo.LastTime+60*5), time.Now().Unix()))
|
|
|
338
|
+ err =protocol.NewErrWithMessage(1009)
|
334
|
goto Fail
|
339
|
goto Fail
|
335
|
}
|
340
|
}
|
336
|
if smsInfo.Code == code {
|
341
|
if smsInfo.Code == code {
|
337
|
result = true
|
342
|
result = true
|
338
|
return
|
343
|
return
|
339
|
} else {
|
344
|
} else {
|
340
|
- err = common.NewErrorWithMsg(1012, "smscode error")
|
345
|
+ log.Error("smscode not equal:",smsInfo.Code,code)
|
|
|
346
|
+ err = protocol.NewErrWithMessage(1012)
|
341
|
goto Fail
|
347
|
goto Fail
|
342
|
}
|
348
|
}
|
343
|
Fail:
|
349
|
Fail:
|
344
|
{
|
350
|
{
|
345
|
smsInfo.ErrorCount += 1
|
351
|
smsInfo.ErrorCount += 1
|
346
|
- if err = redis.Hset(sendType, phone, common.AssertJson(smsInfo), -1); err != nil {
|
352
|
+ if e := redis.Hset(sendType, phone, common.AssertJson(smsInfo), -1); e != nil {
|
|
|
353
|
+ log.Error(e)
|
|
|
354
|
+ if err==nil{
|
|
|
355
|
+ err =e
|
|
|
356
|
+ }
|
347
|
return
|
357
|
return
|
348
|
}
|
358
|
}
|
349
|
}
|
359
|
}
|