作者 yangfu

注销 更新设备

@@ -5,6 +5,8 @@ @@ -5,6 +5,8 @@
5 |短信验证码|完成|2019.10.20|/v1/auth/smsCode| 5 |短信验证码|完成|2019.10.20|/v1/auth/smsCode|
6 |获取token|完成|2019.10.20|/v1/auth/accessToken| 6 |获取token|完成|2019.10.20|/v1/auth/accessToken|
7 |刷新token|完成|2019.10.20|/v1/auth/refreshToken| 7 |刷新token|完成|2019.10.20|/v1/auth/refreshToken|
  8 +|注销|完成|2019.10.26|/v1/auth/revoke|
  9 +|更新设备|完成|2019.10.26|/v1/auth/updateDevice|
8 |修改手机号-校验验证码|完成|2019.11.20|/v1/user/checkSmsCode| 10 |修改手机号-校验验证码|完成|2019.11.20|/v1/user/checkSmsCode|
9 |修改手机号|完成|2019.11.20|/v1/user/changePhone| 11 |修改手机号|完成|2019.11.20|/v1/user/changePhone|
10 |修改密码|完成|2019.11.20|v1/user/changePassword| 12 |修改密码|完成|2019.11.20|v1/user/changePassword|
@@ -12,10 +14,11 @@ @@ -12,10 +14,11 @@
12 |机会评论列表|完成|2019.11.21|/v1/chance/comments| 14 |机会评论列表|完成|2019.11.21|/v1/chance/comments|
13 |我来评论|完成|2019.11.21|/v1/chance/iComment| 15 |我来评论|完成|2019.11.21|/v1/chance/iComment|
14 |我的评论|完成|2019.11.21|/v1/chance/iComments| 16 |我的评论|完成|2019.11.21|/v1/chance/iComments|
15 -|评论详情-继续评论| |2019.11.21|/v1/chance/commentDetailsMulti|  
16 -|评论详情-不能评论| |2019.11.21|/v1/chance/commentDetailsSingle| 17 +|评论详情-继续评论|完成|2019.11.26|/v1/chance/commentDetailsMulti|
  18 +|评论详情-不能评论|完成|2019.11.26|/v1/chance/commentDetailsSingle|
17 |我的点赞| |2019.11.|v1/chance/favorite| 19 |我的点赞| |2019.11.|v1/chance/favorite|
18 |我的收藏| |2019.11.|v1/chance/favorite| 20 |我的收藏| |2019.11.|v1/chance/favorite|
  21 +|点赞/取消点赞| |2019.11.|v1/chance/sympathyAction|
19 |消息中心|完成|2019.11.|v1/message/messageCenter| 22 |消息中心|完成|2019.11.|v1/message/messageCenter|
20 |标记已读|完成|2019.11.|v1/message/msgCenterRead| 23 |标记已读|完成|2019.11.|v1/message/msgCenterRead|
21 |标记全部已读|完成|2019.11.|v1/message/msgCenterAllRead| 24 |标记全部已读|完成|2019.11.|v1/message/msgCenterAllRead|
@@ -4,13 +4,13 @@ import ( @@ -4,13 +4,13 @@ import (
4 "crypto/sha256" 4 "crypto/sha256"
5 "encoding/hex" 5 "encoding/hex"
6 "fmt" 6 "fmt"
  7 + "github.com/astaxie/beego"
7 "strconv" 8 "strconv"
8 "strings" 9 "strings"
9 10
10 "opp/protocol" 11 "opp/protocol"
11 - s_auth "opp/services/auth" 12 + "opp/services/auth"
12 13
13 - "github.com/astaxie/beego"  
14 "github.com/astaxie/beego/context" 14 "github.com/astaxie/beego/context"
15 "github.com/astaxie/beego/validation" 15 "github.com/astaxie/beego/validation"
16 "github.com/prometheus/client_golang/prometheus" 16 "github.com/prometheus/client_golang/prometheus"
@@ -22,7 +22,6 @@ import ( @@ -22,7 +22,6 @@ import (
22 var ( 22 var (
23 //prometheus 监控endpoint 23 //prometheus 监控endpoint
24 HTTPReqTotal *prometheus.CounterVec 24 HTTPReqTotal *prometheus.CounterVec
25 - auth s_auth.IAuthService = &s_auth.AuthService{}  
26 ) 25 )
27 26
28 type BaseController struct { 27 type BaseController struct {
@@ -82,7 +81,7 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader { @@ -82,7 +81,7 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader {
82 h := &protocol.RequestHeader{} 81 h := &protocol.RequestHeader{}
83 h.AccessToken = ctx.Input.Header("x-mmm-accesstoken") 82 h.AccessToken = ctx.Input.Header("x-mmm-accesstoken")
84 h.AppProject = ctx.Input.Header("x-mmm-appproject") 83 h.AppProject = ctx.Input.Header("x-mmm-appproject")
85 - h.DeviceType = ctx.Input.Header("x-mmm-devicetype") 84 + h.DeviceType, _ = strconv.Atoi(ctx.Input.Header("x-mmm-devicetype"))
86 h.Sign = ctx.Input.Header("x-mmm-sign") 85 h.Sign = ctx.Input.Header("x-mmm-sign")
87 h.Uuid = ctx.Input.Header("x-mmm-uuid") 86 h.Uuid = ctx.Input.Header("x-mmm-uuid")
88 h.TimeStamp = ctx.Input.Header("x-mmm-timestamp") 87 h.TimeStamp = ctx.Input.Header("x-mmm-timestamp")
@@ -107,7 +106,6 @@ func FilterComm(ctx *context.Context) { @@ -107,7 +106,6 @@ func FilterComm(ctx *context.Context) {
107 if beego.BConfig.RunMode == "dev" { 106 if beego.BConfig.RunMode == "dev" {
108 return 107 return
109 } 108 }
110 -  
111 //1.检查签名 109 //1.检查签名
112 if !CheckSign(ctx) { 110 if !CheckSign(ctx) {
113 return 111 return
@@ -117,9 +115,9 @@ func FilterComm(ctx *context.Context) { @@ -117,9 +115,9 @@ func FilterComm(ctx *context.Context) {
117 return 115 return
118 } 116 }
119 //3.查重uuid 117 //3.查重uuid
120 - if !CheckUuid(ctx) {  
121 - return  
122 - } 118 + //if !CheckUuid(ctx) {
  119 + // return
  120 + //}
123 return 121 return
124 } 122 }
125 123
@@ -5,14 +5,14 @@ import ( @@ -5,14 +5,14 @@ import (
5 5
6 "opp/controllers" 6 "opp/controllers"
7 "opp/protocol" 7 "opp/protocol"
8 - s_auth "opp/services/auth" 8 + "opp/services/auth"
9 9
10 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 10 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
11 ) 11 )
12 12
13 -var (  
14 - auth s_auth.IAuthService = &s_auth.AuthService{}  
15 -) 13 +//var (
  14 +// auth s_auth.IAuthService = &s_auth.AuthService{}
  15 +//)
16 16
17 type AuthController struct { 17 type AuthController struct {
18 controllers.BaseController 18 controllers.BaseController
@@ -35,7 +35,8 @@ func (this *AuthController) Login() { @@ -35,7 +35,8 @@ func (this *AuthController) Login() {
35 msg = m 35 msg = m
36 return 36 return
37 } 37 }
38 - msg = protocol.NewReturnResponse(auth.Login(request)) 38 + header := controllers.GetRequestHeader(this.Ctx)
  39 + msg = protocol.NewReturnResponse(auth.Login(header, request))
39 } 40 }
40 41
41 //SmsCode 42 //SmsCode
@@ -58,14 +59,14 @@ func (this *AuthController) SmsCode() { @@ -58,14 +59,14 @@ func (this *AuthController) SmsCode() {
58 msg = protocol.NewReturnResponse(auth.SmsCode(request)) 59 msg = protocol.NewReturnResponse(auth.SmsCode(request))
59 } 60 }
60 61
61 -//UpdateDevice  
62 -// @router /updateDevice [post]  
63 -func (this *AuthController) UpdateDevice() { 62 +//AccessToken
  63 +// @router /accessToken [post]
  64 +func (this *AuthController) AccessToken() {
64 var msg *protocol.ResponseMessage 65 var msg *protocol.ResponseMessage
65 defer func() { 66 defer func() {
66 this.Resp(msg) 67 this.Resp(msg)
67 }() 68 }()
68 - var request *protocol.UpdateDeviceRequest 69 + var request *protocol.AccessTokenRequest
69 if err := json.Unmarshal(this.ByteBody, &request); err != nil { 70 if err := json.Unmarshal(this.ByteBody, &request); err != nil {
70 log.Error(err) 71 log.Error(err)
71 msg = protocol.BadRequestParam(1) 72 msg = protocol.BadRequestParam(1)
@@ -75,17 +76,17 @@ func (this *AuthController) UpdateDevice() { @@ -75,17 +76,17 @@ func (this *AuthController) UpdateDevice() {
75 msg = m 76 msg = m
76 return 77 return
77 } 78 }
78 - msg = protocol.NewReturnResponse(auth.UpdateDevice(request)) 79 + msg = protocol.NewReturnResponse(auth.AccessToken(request))
79 } 80 }
80 81
81 -//AccessToken  
82 -// @router /accessToken [post]  
83 -func (this *AuthController) AccessToken() { 82 +//RefreshToken
  83 +// @router /refreshToken [post]
  84 +func (this *AuthController) RefreshToken() {
84 var msg *protocol.ResponseMessage 85 var msg *protocol.ResponseMessage
85 defer func() { 86 defer func() {
86 this.Resp(msg) 87 this.Resp(msg)
87 }() 88 }()
88 - var request *protocol.AccessTokenRequest 89 + var request *protocol.RefreshTokenRequest
89 if err := json.Unmarshal(this.ByteBody, &request); err != nil { 90 if err := json.Unmarshal(this.ByteBody, &request); err != nil {
90 log.Error(err) 91 log.Error(err)
91 msg = protocol.BadRequestParam(1) 92 msg = protocol.BadRequestParam(1)
@@ -95,17 +96,17 @@ func (this *AuthController) AccessToken() { @@ -95,17 +96,17 @@ func (this *AuthController) AccessToken() {
95 msg = m 96 msg = m
96 return 97 return
97 } 98 }
98 - msg = protocol.NewReturnResponse(auth.AccessToken(request)) 99 + msg = protocol.NewReturnResponse(auth.RefreshToken(request))
99 } 100 }
100 101
101 -//RefreshToken  
102 -// @router /refreshToken [post]  
103 -func (this *AuthController) RefreshToken() { 102 +//Revoke
  103 +//@router /revoke [post]
  104 +func (this *AuthController) Revoke() {
104 var msg *protocol.ResponseMessage 105 var msg *protocol.ResponseMessage
105 defer func() { 106 defer func() {
106 this.Resp(msg) 107 this.Resp(msg)
107 }() 108 }()
108 - var request *protocol.RefreshTokenRequest 109 + var request *protocol.RevokeRequest
109 if err := json.Unmarshal(this.ByteBody, &request); err != nil { 110 if err := json.Unmarshal(this.ByteBody, &request); err != nil {
110 log.Error(err) 111 log.Error(err)
111 msg = protocol.BadRequestParam(1) 112 msg = protocol.BadRequestParam(1)
@@ -115,5 +116,27 @@ func (this *AuthController) RefreshToken() { @@ -115,5 +116,27 @@ func (this *AuthController) RefreshToken() {
115 msg = m 116 msg = m
116 return 117 return
117 } 118 }
118 - msg = protocol.NewReturnResponse(auth.RefreshToken(request)) 119 + header := controllers.GetRequestHeader(this.Ctx)
  120 + msg = protocol.NewReturnResponse(auth.Revoke(header, request))
  121 +}
  122 +
  123 +//UpdateDevice
  124 +//@router /updateDevice [post]
  125 +func (this *AuthController) UpdateDevice() {
  126 + var msg *protocol.ResponseMessage
  127 + defer func() {
  128 + this.Resp(msg)
  129 + }()
  130 + var request *protocol.UpdateDeviceRequest
  131 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  132 + log.Error(err)
  133 + msg = protocol.BadRequestParam(1)
  134 + return
  135 + }
  136 + if b, m := this.Valid(request); !b {
  137 + msg = m
  138 + return
  139 + }
  140 + header := controllers.GetRequestHeader(this.Ctx)
  141 + msg = protocol.NewReturnResponse(auth.UpdateDevice(header, request))
119 } 142 }
@@ -3,7 +3,7 @@ package repository @@ -3,7 +3,7 @@ package repository
3 import "opp/models" 3 import "opp/models"
4 4
5 type IUserAuthRepository interface { 5 type IUserAuthRepository interface {
6 - GetUserAuthByUserId(uid int64) (v *models.UserAuth, err error) 6 + GetUserAuthByUserId(uid int64, deviceType int) (v *models.UserAuth, err error)
7 UpdateUserAuthById(m *models.UserAuth) (err error) 7 UpdateUserAuthById(m *models.UserAuth) (err error)
8 GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) 8 GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error)
9 GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error) 9 GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error)
@@ -15,8 +15,8 @@ var _ IUserAuthRepository = (*UserAuthRepository)(nil) @@ -15,8 +15,8 @@ var _ IUserAuthRepository = (*UserAuthRepository)(nil)
15 15
16 type UserAuthRepository struct{} 16 type UserAuthRepository struct{}
17 17
18 -func (r *UserAuthRepository) GetUserAuthByUserId(uid int64) (v *models.UserAuth, err error) {  
19 - return models.GetUserAuthByUserId(uid) 18 +func (r *UserAuthRepository) GetUserAuthByUserId(uid int64, deviceType int) (v *models.UserAuth, err error) {
  19 + return models.GetUserAuthByUserId(uid, deviceType)
20 } 20 }
21 21
22 func (r *UserAuthRepository) UpdateUserAuthById(m *models.UserAuth) (err error) { 22 func (r *UserAuthRepository) UpdateUserAuthById(m *models.UserAuth) (err error) {
@@ -10,7 +10,7 @@ var userAuth = &models.UserAuth{ @@ -10,7 +10,7 @@ var userAuth = &models.UserAuth{
10 10
11 type UserAuthMockRepository struct{} 11 type UserAuthMockRepository struct{}
12 12
13 -func (r *UserAuthMockRepository) GetUserAuthByUserId(uid int64) (v *models.UserAuth, err error) { 13 +func (r *UserAuthMockRepository) GetUserAuthByUserId(uid int64, deviceType int) (v *models.UserAuth, err error) {
14 v = userAuth 14 v = userAuth
15 return 15 return
16 } 16 }
@@ -173,7 +173,7 @@ func GetUserByAuthCode(authCode string) (v *UserAuth, err error) { @@ -173,7 +173,7 @@ func GetUserByAuthCode(authCode string) (v *UserAuth, err error) {
173 173
174 func GetUserAuthByRefreshToken(refreshToken string) (v *UserAuth, err error) { 174 func GetUserAuthByRefreshToken(refreshToken string) (v *UserAuth, err error) {
175 o := orm.NewOrm() 175 o := orm.NewOrm()
176 - sql := "select * from user_auth where refresh_token=? and refresh_token_exp >= Now()" // TODO: and enabled = 1 176 + sql := "select * from user_auth where refresh_token=? and refresh_token_exp >= Now()" //
177 if err = o.Raw(sql, refreshToken).QueryRow(&v); err == nil { 177 if err = o.Raw(sql, refreshToken).QueryRow(&v); err == nil {
178 return v, nil 178 return v, nil
179 } 179 }
@@ -182,7 +182,7 @@ func GetUserAuthByRefreshToken(refreshToken string) (v *UserAuth, err error) { @@ -182,7 +182,7 @@ func GetUserAuthByRefreshToken(refreshToken string) (v *UserAuth, err error) {
182 182
183 func GetUserAuthByToken(refreshToken string) (v *UserAuth, err error) { 183 func GetUserAuthByToken(refreshToken string) (v *UserAuth, err error) {
184 o := orm.NewOrm() 184 o := orm.NewOrm()
185 - sql := "select * from user_auth where access_token=? and access_token_exp >= Now()" // TODO: and enabled = 1 185 + sql := "select * from user_auth where access_token=? and access_token_exp >= Now()"
186 if err = o.Raw(sql, refreshToken).QueryRow(&v); err == nil { 186 if err = o.Raw(sql, refreshToken).QueryRow(&v); err == nil {
187 return v, nil 187 return v, nil
188 } 188 }
@@ -191,10 +191,10 @@ func GetUserAuthByToken(refreshToken string) (v *UserAuth, err error) { @@ -191,10 +191,10 @@ func GetUserAuthByToken(refreshToken string) (v *UserAuth, err error) {
191 191
192 // GetUserAuthById retrieves UserAuth by Id. Returns error if 192 // GetUserAuthById retrieves UserAuth by Id. Returns error if
193 // Id doesn't exist 193 // Id doesn't exist
194 -func GetUserAuthByUserId(uid int64) (v *UserAuth, err error) { 194 +func GetUserAuthByUserId(uid int64, deviceType int) (v *UserAuth, err error) {
195 o := orm.NewOrm() 195 o := orm.NewOrm()
196 - sql := "select * from user_auth where user_id=?" //  
197 - if err = o.Raw(sql, uid).QueryRow(&v); err == nil { 196 + sql := "select * from user_auth where user_id=? and device_type=?"
  197 + if err = o.Raw(sql, uid, deviceType).QueryRow(&v); err == nil {
198 return v, nil 198 return v, nil
199 } 199 }
200 return nil, err 200 return nil, err
@@ -15,7 +15,7 @@ type RequestHeader struct { @@ -15,7 +15,7 @@ type RequestHeader struct {
15 TimeStamp string 15 TimeStamp string
16 Uuid string 16 Uuid string
17 Sign string 17 Sign string
18 - DeviceType string 18 + DeviceType int
19 AppProject string 19 AppProject string
20 AccessToken string 20 AccessToken string
21 Uid int64 21 Uid int64
@@ -114,3 +114,9 @@ type CheckImResponse struct { @@ -114,3 +114,9 @@ type CheckImResponse struct {
114 ImToken string //net im token 114 ImToken string //net im token
115 CsAccount int64 //客服id 115 CsAccount int64 //客服id
116 } 116 }
  117 +
  118 +/*Revoke */
  119 +type RevokeRequest struct {
  120 +}
  121 +type RevokeResponse struct {
  122 +}
@@ -95,9 +95,18 @@ func NewReturnResponse(data interface{}, eRR error) *ResponseMessage { @@ -95,9 +95,18 @@ func NewReturnResponse(data interface{}, eRR error) *ResponseMessage {
95 msg.Data = data 95 msg.Data = data
96 return msg 96 return msg
97 } 97 }
  98 + //if x,ok :=eRR.(*ErrWithMessage);ok{
  99 + // if x.ErrorCode.Errno==0{
  100 + // msg = x.ParseToMessage()
  101 + // msg.Data = data
  102 + // }
  103 + // return msg
  104 + //}
98 // fmt.Println("日志:" + eRR.Error()) 105 // fmt.Println("日志:" + eRR.Error())
99 if x, ok := eRR.(CustomErrParse); ok { 106 if x, ok := eRR.(CustomErrParse); ok {
100 - return x.ParseToMessage() 107 + msg = x.ParseToMessage()
  108 + msg.Data = data
  109 + return msg
101 } 110 }
102 return NewMesage(1) 111 return NewMesage(1)
103 } 112 }
@@ -105,3 +114,10 @@ func NewReturnResponse(data interface{}, eRR error) *ResponseMessage { @@ -105,3 +114,10 @@ func NewReturnResponse(data interface{}, eRR error) *ResponseMessage {
105 func BadRequestParam(code int) *ResponseMessage { 114 func BadRequestParam(code int) *ResponseMessage {
106 return NewMesage(code) 115 return NewMesage(code)
107 } 116 }
  117 +
  118 +func NewSuccessWithMessage(msg string) *ErrWithMessage {
  119 + return &ErrWithMessage{
  120 + Err: nil,
  121 + ErrorCode: ErrorCode{0, msg},
  122 + }
  123 +}
@@ -33,6 +33,14 @@ func init() { @@ -33,6 +33,14 @@ func init() {
33 33
34 beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"], 34 beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
35 beego.ControllerComments{ 35 beego.ControllerComments{
  36 + Method: "Revoke",
  37 + Router: `/revoke`,
  38 + AllowHTTPMethods: []string{"post"},
  39 + MethodParams: param.Make(),
  40 + Params: nil})
  41 +
  42 + beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
  43 + beego.ControllerComments{
36 Method: "SmsCode", 44 Method: "SmsCode",
37 Router: `/smsCode`, 45 Router: `/smsCode`,
38 AllowHTTPMethods: []string{"post"}, 46 AllowHTTPMethods: []string{"post"},
@@ -7,6 +7,7 @@ import ( @@ -7,6 +7,7 @@ import (
7 "github.com/astaxie/beego/orm" 7 "github.com/astaxie/beego/orm"
8 "html/template" 8 "html/template"
9 "math/rand" 9 "math/rand"
  10 + "opp/internal/utils"
10 "strings" 11 "strings"
11 "time" 12 "time"
12 13
@@ -25,21 +26,21 @@ import ( @@ -25,21 +26,21 @@ import (
25 comm_time "gitlab.fjmaimaimai.com/mmm-go/gocomm/time" 26 comm_time "gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
26 ) 27 )
27 28
28 -type IAuthService interface {  
29 - Login(request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error)  
30 - AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessTokenResponse, err error)  
31 - RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshTokenResponse, err error)  
32 - UpdateDevice(request *protocol.UpdateDeviceRequest) (rsp *protocol.UpdateDeviceResponse, err error)  
33 - CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenResponse, err error)  
34 - CheckUuid(request *protocol.CheckUuidRequest) (rsp *protocol.CheckUuidResponse, err error)  
35 - SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, err error)  
36 -} 29 +//type IAuthService interface {
  30 +// Login(request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error)
  31 +// AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessTokenResponse, err error)
  32 +// RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshTokenResponse, err error)
  33 +// UpdateDevice(request *protocol.UpdateDeviceRequest) (rsp *protocol.UpdateDeviceResponse, err error)
  34 +// CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenResponse, err error)
  35 +// CheckUuid(request *protocol.CheckUuidRequest) (rsp *protocol.CheckUuidResponse, err error)
  36 +// SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, err error)
  37 +//}
37 38
38 type AuthService struct{} 39 type AuthService struct{}
39 40
40 -func assertImplement() {  
41 - var _ IAuthService = (*AuthService)(nil)  
42 -} 41 +//func assertImplement() {
  42 +// var _ IAuthService = (*AuthService)(nil)
  43 +//}
43 44
44 var ( 45 var (
45 //服务 46 //服务
@@ -50,7 +51,7 @@ var ( @@ -50,7 +51,7 @@ var (
50 ) 51 )
51 52
52 //登录 53 //登录
53 -func (s *AuthService) Login(request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) { 54 +func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) {
54 var ( 55 var (
55 user *models.User 56 user *models.User
56 userAuth *models.UserAuth 57 userAuth *models.UserAuth
@@ -90,11 +91,12 @@ Success: @@ -90,11 +91,12 @@ Success:
90 log.Error(err) 91 log.Error(err)
91 return 92 return
92 } 93 }
93 - userAuth, err = repository.UserAuth.GetUserAuthByUserId(user.Id) 94 + userAuth, err = repository.UserAuth.GetUserAuthByUserId(user.Id, header.DeviceType)
94 if err != nil { 95 if err != nil {
95 if err == orm.ErrNoRows { 96 if err == orm.ErrNoRows {
96 userAuth = &models.UserAuth{ 97 userAuth = &models.UserAuth{
97 UserId: user.Id, 98 UserId: user.Id,
  99 + DeviceType: int8(header.DeviceType),
98 } 100 }
99 repository.UserAuth.AddUserAuth(userAuth) 101 repository.UserAuth.AddUserAuth(userAuth)
100 } else { 102 } else {
@@ -122,18 +124,35 @@ Success: @@ -122,18 +124,35 @@ Success:
122 return 124 return
123 } 125 }
124 rsp = &protocol.LoginResponse{AuthCode: userAuth.AuthCode} 126 rsp = &protocol.LoginResponse{AuthCode: userAuth.AuthCode}
125 - return  
126 } 127 }
  128 + err = protocol.NewSuccessWithMessage("登录成功")
127 return 129 return
128 } 130 }
129 131
130 //更新设备信息 132 //更新设备信息
131 -func (s *AuthService) UpdateDevice(request *protocol.UpdateDeviceRequest) (rsp *protocol.UpdateDeviceResponse, err error) {  
132 - return nil, nil 133 +func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDeviceRequest) (rsp *protocol.UpdateDeviceResponse, err error) {
  134 + var (
  135 + userAuth *models.UserAuth
  136 + updateMap = make(map[string]interface{})
  137 + )
  138 + //rsp =&protocol.UpdateDeviceResponse{}
  139 + if userAuth, err = repository.UserAuth.GetUserAuthByUserId(header.Uid, header.DeviceType); err != nil {
  140 + log.Error(err)
  141 + return
  142 + }
  143 + {
  144 + updateMap["ClientId"] = request.ClientId
  145 + updateMap["DeviceToken"] = request.DeviceToken
  146 + }
  147 + if err = utils.UpdateTableByMap(userAuth, updateMap); err != nil {
  148 + log.Error(err)
  149 + }
  150 + err = protocol.NewSuccessWithMessage("更新成功")
  151 + return
133 } 152 }
134 153
135 //获取accessToken 154 //获取accessToken
136 -func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessTokenResponse, err error) { 155 +func AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessTokenResponse, err error) {
137 var ( 156 var (
138 userAuth *models.UserAuth 157 userAuth *models.UserAuth
139 ) 158 )
@@ -144,6 +163,7 @@ func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *pr @@ -144,6 +163,7 @@ func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *pr
144 //} 163 //}
145 userAuth, err = repository.UserAuth.GetUserAuthByAuthCode(request.AuthCode) 164 userAuth, err = repository.UserAuth.GetUserAuthByAuthCode(request.AuthCode)
146 if err != nil { 165 if err != nil {
  166 + log.Error(err)
147 err = protocol.NewErrWithMessage(4139, err) 167 err = protocol.NewErrWithMessage(4139, err)
148 return 168 return
149 } 169 }
@@ -165,7 +185,7 @@ func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *pr @@ -165,7 +185,7 @@ func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *pr
165 } 185 }
166 186
167 //刷新token 187 //刷新token
168 -func (s *AuthService) RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshTokenResponse, err error) { 188 +func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshTokenResponse, err error) {
169 var ( 189 var (
170 userAuth *models.UserAuth 190 userAuth *models.UserAuth
171 ) 191 )
@@ -200,7 +220,7 @@ func (s *AuthService) RefreshToken(request *protocol.RefreshTokenRequest) (rsp * @@ -200,7 +220,7 @@ func (s *AuthService) RefreshToken(request *protocol.RefreshTokenRequest) (rsp *
200 //} 220 //}
201 221
202 //检查token有效性 222 //检查token有效性
203 -func (s *AuthService) CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenResponse, err error) { 223 +func CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenResponse, err error) {
204 var ( 224 var (
205 userAuth *models.UserAuth 225 userAuth *models.UserAuth
206 ) 226 )
@@ -221,7 +241,7 @@ func (s *AuthService) CheckToken(request *protocol.CheckTokenRequest) (rsp *prot @@ -221,7 +241,7 @@ func (s *AuthService) CheckToken(request *protocol.CheckTokenRequest) (rsp *prot
221 } 241 }
222 242
223 //检查uuid 是否重复 243 //检查uuid 是否重复
224 -func (s *AuthService) CheckUuid(request *protocol.CheckUuidRequest) (rsp *protocol.CheckUuidResponse, err error) { 244 +func CheckUuid(request *protocol.CheckUuidRequest) (rsp *protocol.CheckUuidResponse, err error) {
225 //var ( 245 //var (
226 // logUuid *models.LogUuid 246 // logUuid *models.LogUuid
227 //) 247 //)
@@ -238,7 +258,7 @@ func (s *AuthService) CheckUuid(request *protocol.CheckUuidRequest) (rsp *protoc @@ -238,7 +258,7 @@ func (s *AuthService) CheckUuid(request *protocol.CheckUuidRequest) (rsp *protoc
238 } 258 }
239 259
240 //短信验证码 T 260 //短信验证码 T
241 -func (s *AuthService) SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, err error) { 261 +func SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, err error) {
242 var ( 262 var (
243 value, key, msgContent string 263 value, key, msgContent string
244 smsInfo *protocol.SmsInfo 264 smsInfo *protocol.SmsInfo
@@ -345,6 +365,28 @@ Fail: @@ -345,6 +365,28 @@ Fail:
345 return 365 return
346 } 366 }
347 367
  368 +//注销登录
  369 +func Revoke(header *protocol.RequestHeader, request *protocol.RevokeRequest) (rsp *protocol.RevokeResponse, err error) {
  370 + var (
  371 + userAuth *models.UserAuth
  372 + updateMap = make(map[string]interface{})
  373 + )
  374 + //rsp =&protocol.RevokeResponse{}
  375 + if userAuth, err = repository.UserAuth.GetUserAuthByUserId(header.Uid, header.DeviceType); err != nil {
  376 + log.Error(err)
  377 + return
  378 + }
  379 + {
  380 + updateMap["AccessToken"] = ""
  381 + updateMap["RefreshToken"] = ""
  382 + updateMap["AuthCode"] = ""
  383 + }
  384 + if err = utils.UpdateTableByMap(userAuth, updateMap); err != nil {
  385 + log.Error(err)
  386 + }
  387 + return
  388 +}
  389 +
348 func CheckIm(request *protocol.CheckImRequest) (rsp *protocol.CheckImResponse, err error) { 390 func CheckIm(request *protocol.CheckImRequest) (rsp *protocol.CheckImResponse, err error) {
349 var () 391 var ()
350 if beego.BConfig.RunMode != "prod" { 392 if beego.BConfig.RunMode != "prod" {
@@ -13,8 +13,6 @@ func init() { @@ -13,8 +13,6 @@ func init() {
13 repository.InitRepositoryMock() 13 repository.InitRepositoryMock()
14 } 14 }
15 15
16 -var auth = AuthService{}  
17 -  
18 func Test_SmsCode(t *testing.T) { 16 func Test_SmsCode(t *testing.T) {
19 var ( 17 var (
20 resp *protocol.SmsCodeResponse 18 resp *protocol.SmsCodeResponse
@@ -29,9 +27,8 @@ func Test_SmsCode(t *testing.T) { @@ -29,9 +27,8 @@ func Test_SmsCode(t *testing.T) {
29 {Phone: "18860183053", SendType: "sms_change_mobile"}, 27 {Phone: "18860183053", SendType: "sms_change_mobile"},
30 {Phone: "18860183054", SendType: "sms_change_mobile"}, 28 {Phone: "18860183054", SendType: "sms_change_mobile"},
31 } 29 }
32 - var s IAuthService = &AuthService{}  
33 for i := range input { 30 for i := range input {
34 - if resp, err = s.SmsCode(input[i]); err != nil { 31 + if resp, err = SmsCode(input[i]); err != nil {
35 t.Fatal("send sms code error. input:", input[i], err) 32 t.Fatal("send sms code error. input:", input[i], err)
36 } 33 }
37 if out, err = CheckSmsCode(input[i].Phone, resp.Code, input[i].SendType); err != nil || !out { 34 if out, err = CheckSmsCode(input[i].Phone, resp.Code, input[i].SendType); err != nil || !out {
@@ -48,7 +45,7 @@ func Test_Login(t *testing.T) { @@ -48,7 +45,7 @@ func Test_Login(t *testing.T) {
48 PassWord: "$2y$10$YWg7jPRVLBzc3kevokMkW.boswtCvhToqC.TappIwfqwJ.cI0efvy", 45 PassWord: "$2y$10$YWg7jPRVLBzc3kevokMkW.boswtCvhToqC.TappIwfqwJ.cI0efvy",
49 //ClientId:"123456", 46 //ClientId:"123456",
50 } 47 }
51 - loginRsp, err := auth.Login(login) 48 + loginRsp, err := Login(&protocol.RequestHeader{}, login)
52 if err != nil { 49 if err != nil {
53 t.Fatal(err, loginRsp) 50 t.Fatal(err, loginRsp)
54 } 51 }
@@ -58,14 +55,14 @@ func Test_AccessToken(t *testing.T) { @@ -58,14 +55,14 @@ func Test_AccessToken(t *testing.T) {
58 req := &protocol.AccessTokenRequest{ 55 req := &protocol.AccessTokenRequest{
59 AuthCode: "897ca746f46b11e98771000c29ad8d6d", 56 AuthCode: "897ca746f46b11e98771000c29ad8d6d",
60 } 57 }
61 - if rsp, err := auth.AccessToken(req); err != nil { 58 + if rsp, err := AccessToken(req); err != nil {
62 t.Fatal(err, rsp) 59 t.Fatal(err, rsp)
63 } 60 }
64 } 61 }
65 62
66 func Test_RefreshToken(t *testing.T) { 63 func Test_RefreshToken(t *testing.T) {
67 req := &protocol.RefreshTokenRequest{} 64 req := &protocol.RefreshTokenRequest{}
68 - if rsp, err := auth.RefreshToken(req); err != nil { 65 + if rsp, err := RefreshToken(req); err != nil {
69 t.Fatal(err, rsp) 66 t.Fatal(err, rsp)
70 } 67 }
71 } 68 }