...
|
...
|
@@ -56,7 +56,7 @@ func (s *AuthService)Login(request *protocol.LoginRequest)(rsp *protocol.LoginRe |
|
|
return
|
|
|
}
|
|
|
switch request.GrantType {
|
|
|
case protocol.LoginPassPord:
|
|
|
case protocol.LoginTypePassPord:
|
|
|
if strings.Compare(user.Password,request.PassWord)==0{
|
|
|
goto Success
|
|
|
}else{
|
...
|
...
|
@@ -64,8 +64,8 @@ func (s *AuthService)Login(request *protocol.LoginRequest)(rsp *protocol.LoginRe |
|
|
return
|
|
|
}
|
|
|
break
|
|
|
case protocol.LoginSmdcode:
|
|
|
if result,err=CheckSmsCode(request);result && err==nil{
|
|
|
case protocol.LoginTypeSmdcode:
|
|
|
if result,err=CheckSmsCode(request.Phone,request.Code,protocol.SmsLoginCode);result && err==nil{
|
|
|
goto Success
|
|
|
}else{
|
|
|
return
|
...
|
...
|
@@ -179,7 +179,7 @@ func (s *AuthService)CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol |
|
|
rsp =&protocol.CheckUuidResponse{}
|
|
|
return
|
|
|
}
|
|
|
//短信验证码
|
|
|
//短信验证码 T
|
|
|
func (s *AuthService)SmsCode(request *protocol.SmsCodeRequest)(rsp *protocol.SmsCodeResponse,err error){
|
|
|
var(
|
|
|
value,key,msgContent string
|
...
|
...
|
@@ -240,17 +240,20 @@ func (s *AuthService)SmsCode(request *protocol.SmsCodeRequest)(rsp *protocol.Sms |
|
|
},)
|
|
|
request.Content = buf.String()
|
|
|
err = sms.Send(request)
|
|
|
rsp = &protocol.SmsCodeResponse{
|
|
|
Code:smsInfo.Code,
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
//验证短信验证码
|
|
|
func CheckSmsCode(request *protocol.LoginRequest)(result bool,err error){
|
|
|
//验证短信验证码 T
|
|
|
func CheckSmsCode(phone ,code ,sendType string)(result bool,err error){
|
|
|
var(
|
|
|
value string
|
|
|
smsInfo *protocol.SmsInfo
|
|
|
)
|
|
|
result =false
|
|
|
if value,err =redis.Hget(protocol.SmsLoginCode,request.Phone);err!=nil{
|
|
|
if value,err =redis.Hget(sendType,phone);err!=nil{//protocol.SmsLoginCode
|
|
|
err = common.NewErrorWithMsg(1009,"smscode expire")
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -261,11 +264,11 @@ func CheckSmsCode(request *protocol.LoginRequest)(result bool,err error){ |
|
|
err = common.NewErrorWithMsg(1011,"smscode over error times")
|
|
|
return
|
|
|
}
|
|
|
if smsInfo.LastTime+60*5<time.Now().Unix(){
|
|
|
err = common.NewErrorWithMsg(1009,"smscode expire")
|
|
|
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()))
|
|
|
goto Fail
|
|
|
}
|
|
|
if smsInfo.Code == request.Code{
|
|
|
if smsInfo.Code == code{
|
|
|
result = true
|
|
|
return
|
|
|
}else{
|
...
|
...
|
@@ -275,7 +278,7 @@ func CheckSmsCode(request *protocol.LoginRequest)(result bool,err error){ |
|
|
Fail:
|
|
|
{
|
|
|
smsInfo.ErrorCount +=1
|
|
|
if err=redis.Hset(protocol.SmsLoginCode,request.Phone,common.AssertJson(smsInfo),-1);err!=nil{
|
|
|
if err=redis.Hset(sendType,phone,common.AssertJson(smsInfo),-1);err!=nil{
|
|
|
return
|
|
|
}
|
|
|
}
|
...
|
...
|
|