作者 yangfu

auth fix

@@ -73,9 +73,9 @@ func GetRequestHeader(ctx *context.Context)*protocol.RequestHeader{ @@ -73,9 +73,9 @@ func GetRequestHeader(ctx *context.Context)*protocol.RequestHeader{
73 73
74 //过滤器 74 //过滤器
75 func FilterComm(ctx *context.Context){ 75 func FilterComm(ctx *context.Context){
76 - if strings.HasSuffix(ctx.Request.RequestURI,"login"){  
77 - return  
78 - } 76 + //if strings.HasSuffix(ctx.Request.RequestURI,"login"){
  77 + // return
  78 + //}
79 if beego.BConfig.RunMode!="prod"{ 79 if beego.BConfig.RunMode!="prod"{
80 return 80 return
81 } 81 }
@@ -61,6 +61,9 @@ type RefreshTokenRequest struct { @@ -61,6 +61,9 @@ type RefreshTokenRequest struct {
61 ClientId string `json:"clientId" valid:"Required"` 61 ClientId string `json:"clientId" valid:"Required"`
62 ClientSecret string `json:"clientSecret" valid:"Required"` 62 ClientSecret string `json:"clientSecret" valid:"Required"`
63 RefreshToken string `json:"refreshToken" valid:"Required"` 63 RefreshToken string `json:"refreshToken" valid:"Required"`
  64 +
  65 + Uid int64 `json:"-"`
  66 + LoginType string `json:"-"`
64 } 67 }
65 type RefreshTokenResponse struct { 68 type RefreshTokenResponse struct {
66 RefreshToken string `json:"refreshToken"` 69 RefreshToken string `json:"refreshToken"`
@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 8 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
9 "strings" 9 "strings"
10 ) 10 )
11 - 11 +//登录
12 func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error){ 12 func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error){
13 var ( 13 var (
14 user *models.Users 14 user *models.Users
@@ -17,12 +17,16 @@ func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error @@ -17,12 +17,16 @@ func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error
17 user,err =models.GetUsersByMobile(request.Phone) 17 user,err =models.GetUsersByMobile(request.Phone)
18 if err!=nil{ 18 if err!=nil{
19 log.Error(err) 19 log.Error(err)
  20 + err =common.NewError(2020,err)//账号不存在
20 return 21 return
21 } 22 }
22 switch request.GrantType { 23 switch request.GrantType {
23 case protocol.LoginPassPord: 24 case protocol.LoginPassPord:
24 if strings.Compare(user.Password,request.PassWord)==0{ 25 if strings.Compare(user.Password,request.PassWord)==0{
25 goto Success 26 goto Success
  27 + }else{
  28 + err =common.NewError(2021,err)//登录密码错误
  29 + return
26 } 30 }
27 break 31 break
28 case protocol.LoginSmdcode: 32 case protocol.LoginSmdcode:
@@ -43,16 +47,16 @@ func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error @@ -43,16 +47,16 @@ func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error
43 } 47 }
44 return 48 return
45 } 49 }
46 - 50 +//短信验证码
47 func SmsCode(request *protocol.SmsCodeRequest)(rsp *protocol.SmsCodeResponse,err error){ 51 func SmsCode(request *protocol.SmsCodeRequest)(rsp *protocol.SmsCodeResponse,err error){
48 return nil,nil 52 return nil,nil
49 } 53 }
50 - 54 +//更新设备信息
51 func UpdateDevice(request *protocol.UpdateDeviceRequest)(rsp *protocol.UpdateDeviceResponse,err error){ 55 func UpdateDevice(request *protocol.UpdateDeviceRequest)(rsp *protocol.UpdateDeviceResponse,err error){
52 return nil,nil 56 return nil,nil
53 } 57 }
54 58
55 - 59 +//获取accessToken
56 func AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessTokenResponse,err error){ 60 func AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessTokenResponse,err error){
57 var ( 61 var (
58 userInfo *models.UserInfo 62 userInfo *models.UserInfo
@@ -73,7 +77,7 @@ func AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessToken @@ -73,7 +77,7 @@ func AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessToken
73 } 77 }
74 return 78 return
75 } 79 }
76 - 80 +//刷新token
77 func RefreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.RefreshTokenResponse,err error){ 81 func RefreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.RefreshTokenResponse,err error){
78 var ( 82 var (
79 userInfo *models.UserInfo 83 userInfo *models.UserInfo
@@ -87,7 +91,8 @@ func RefreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.RefreshTo @@ -87,7 +91,8 @@ func RefreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.RefreshTo
87 err = common.NewErrorWithMsg(2,"refresh token error.") 91 err = common.NewErrorWithMsg(2,"refresh token error.")
88 return 92 return
89 } 93 }
90 - if newAccess,err =refreshToken(userInfo.Id,"");err!=nil{ 94 + request.Uid,request.LoginType = userInfo.Id,"mobile"
  95 + if newAccess,err =refreshToken(request);err!=nil{
91 return 96 return
92 } 97 }
93 rsp = &protocol.RefreshTokenResponse{ 98 rsp = &protocol.RefreshTokenResponse{
@@ -97,12 +102,14 @@ func RefreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.RefreshTo @@ -97,12 +102,14 @@ func RefreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.RefreshTo
97 } 102 }
98 return 103 return
99 } 104 }
100 -  
101 -//loginType mobile im  
102 -func refreshToken(uid int64,loginType string)(rsp *protocol.Access,err error){ 105 +//刷新token loginType mobile im web
  106 +func refreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.Access,err error){
  107 + if request.Uid==0{
  108 + return
  109 + }
103 return nil,nil 110 return nil,nil
104 } 111 }
105 - 112 +//检查token有效性
106 func CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenResponse,err error){ 113 func CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenResponse,err error){
107 var ( 114 var (
108 userInfo *models.UserInfo 115 userInfo *models.UserInfo
@@ -122,7 +129,7 @@ func CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenRes @@ -122,7 +129,7 @@ func CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenRes
122 } 129 }
123 return 130 return
124 } 131 }
125 - 132 +//检查uuid 是否重复
126 func CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidResponse,err error){ 133 func CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidResponse,err error){
127 var ( 134 var (
128 logUuid *models.LogUuid 135 logUuid *models.LogUuid