|
@@ -2,19 +2,45 @@ package auth |
|
@@ -2,19 +2,45 @@ package auth |
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
4
|
"fmt"
|
4
|
"fmt"
|
|
|
5
|
+ "gitlab.fjmaimaimai.com/mmm-go/ability/internal/repository"
|
5
|
"gitlab.fjmaimaimai.com/mmm-go/ability/models"
|
6
|
"gitlab.fjmaimaimai.com/mmm-go/ability/models"
|
6
|
"gitlab.fjmaimaimai.com/mmm-go/ability/protocol"
|
7
|
"gitlab.fjmaimaimai.com/mmm-go/ability/protocol"
|
7
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
|
8
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
|
8
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
9
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
9
|
"strings"
|
10
|
"strings"
|
10
|
)
|
11
|
)
|
|
|
12
|
+
|
|
|
13
|
+type IAuthService interface {
|
|
|
14
|
+ Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error)
|
|
|
15
|
+ AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessTokenResponse,err error)
|
|
|
16
|
+ RefreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.RefreshTokenResponse,err error)
|
|
|
17
|
+ UpdateDevice(request *protocol.UpdateDeviceRequest)(rsp *protocol.UpdateDeviceResponse,err error)
|
|
|
18
|
+ CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenResponse,err error)
|
|
|
19
|
+ CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidResponse,err error)
|
|
|
20
|
+ SmsCode(request *protocol.SmsCodeRequest)(rsp *protocol.SmsCodeResponse,err error)
|
|
|
21
|
+}
|
|
|
22
|
+
|
|
|
23
|
+type AuthService struct {}
|
|
|
24
|
+
|
|
|
25
|
+func assertImplement(){
|
|
|
26
|
+ var _ IAuthService = (*AuthService)(nil)
|
|
|
27
|
+}
|
|
|
28
|
+
|
|
|
29
|
+var(
|
|
|
30
|
+ //服务
|
|
|
31
|
+ //sms s_sms.ISmsService = &s_sms.SmsService{}
|
|
|
32
|
+
|
|
|
33
|
+ //仓储
|
|
|
34
|
+ UserRepository repository.IUserRepository =&repository.UserRepository{}
|
|
|
35
|
+)
|
|
|
36
|
+
|
11
|
//登录
|
37
|
//登录
|
12
|
-func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error){
|
38
|
+func (s *AuthService)Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error){
|
13
|
var (
|
39
|
var (
|
14
|
user *models.Users
|
40
|
user *models.Users
|
15
|
userInfo *models.UserInfo
|
41
|
userInfo *models.UserInfo
|
16
|
)
|
42
|
)
|
17
|
- user,err =models.GetUsersByMobile(request.Phone)
|
43
|
+ user,err =UserRepository.GetUsersByMobile(request.Phone)
|
18
|
if err!=nil{
|
44
|
if err!=nil{
|
19
|
log.Error(err)
|
45
|
log.Error(err)
|
20
|
err =common.NewError(2020,err)//账号不存在
|
46
|
err =common.NewError(2020,err)//账号不存在
|
|
@@ -37,7 +63,7 @@ func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error |
|
@@ -37,7 +63,7 @@ func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error |
37
|
}
|
63
|
}
|
38
|
Success:
|
64
|
Success:
|
39
|
{
|
65
|
{
|
40
|
- userInfo,err =models.GetUserInfoByMobile(request.Phone)
|
66
|
+ userInfo,err =UserRepository.GetUserInfoByMobile(request.Phone)
|
41
|
if err!=nil{
|
67
|
if err!=nil{
|
42
|
log.Error(err)
|
68
|
log.Error(err)
|
43
|
return
|
69
|
return
|
|
@@ -47,17 +73,12 @@ func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error |
|
@@ -47,17 +73,12 @@ func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error |
47
|
}
|
73
|
}
|
48
|
return
|
74
|
return
|
49
|
}
|
75
|
}
|
50
|
-//短信验证码
|
|
|
51
|
-func SmsCode(request *protocol.SmsCodeRequest)(rsp *protocol.SmsCodeResponse,err error){
|
|
|
52
|
- return nil,nil
|
|
|
53
|
-}
|
|
|
54
|
//更新设备信息
|
76
|
//更新设备信息
|
55
|
-func UpdateDevice(request *protocol.UpdateDeviceRequest)(rsp *protocol.UpdateDeviceResponse,err error){
|
77
|
+func (s *AuthService)UpdateDevice(request *protocol.UpdateDeviceRequest)(rsp *protocol.UpdateDeviceResponse,err error){
|
56
|
return nil,nil
|
78
|
return nil,nil
|
57
|
}
|
79
|
}
|
58
|
-
|
|
|
59
|
//获取accessToken
|
80
|
//获取accessToken
|
60
|
-func AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessTokenResponse,err error){
|
81
|
+func (s *AuthService)AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessTokenResponse,err error){
|
61
|
var (
|
82
|
var (
|
62
|
userInfo *models.UserInfo
|
83
|
userInfo *models.UserInfo
|
63
|
)
|
84
|
)
|
|
@@ -78,7 +99,7 @@ func AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessToken |
|
@@ -78,7 +99,7 @@ func AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessToken |
78
|
return
|
99
|
return
|
79
|
}
|
100
|
}
|
80
|
//刷新token
|
101
|
//刷新token
|
81
|
-func RefreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.RefreshTokenResponse,err error){
|
102
|
+func (s *AuthService)RefreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.RefreshTokenResponse,err error){
|
82
|
var (
|
103
|
var (
|
83
|
userInfo *models.UserInfo
|
104
|
userInfo *models.UserInfo
|
84
|
newAccess *protocol.Access
|
105
|
newAccess *protocol.Access
|
|
@@ -110,7 +131,7 @@ func refreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.Access,er |
|
@@ -110,7 +131,7 @@ func refreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.Access,er |
110
|
return nil,nil
|
131
|
return nil,nil
|
111
|
}
|
132
|
}
|
112
|
//检查token有效性
|
133
|
//检查token有效性
|
113
|
-func CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenResponse,err error){
|
134
|
+func (s *AuthService)CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenResponse,err error){
|
114
|
var (
|
135
|
var (
|
115
|
userInfo *models.UserInfo
|
136
|
userInfo *models.UserInfo
|
116
|
)
|
137
|
)
|
|
@@ -130,7 +151,7 @@ func CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenRes |
|
@@ -130,7 +151,7 @@ func CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenRes |
130
|
return
|
151
|
return
|
131
|
}
|
152
|
}
|
132
|
//检查uuid 是否重复
|
153
|
//检查uuid 是否重复
|
133
|
-func CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidResponse,err error){
|
154
|
+func (s *AuthService)CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidResponse,err error){
|
134
|
var (
|
155
|
var (
|
135
|
logUuid *models.LogUuid
|
156
|
logUuid *models.LogUuid
|
136
|
)
|
157
|
)
|
|
@@ -144,4 +165,8 @@ func CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidRespon |
|
@@ -144,4 +165,8 @@ func CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidRespon |
144
|
models.AddLogUuid(&models.LogUuid{Uuid:request.Uuid})
|
165
|
models.AddLogUuid(&models.LogUuid{Uuid:request.Uuid})
|
145
|
rsp =&protocol.CheckUuidResponse{}
|
166
|
rsp =&protocol.CheckUuidResponse{}
|
146
|
return
|
167
|
return
|
|
|
168
|
+}
|
|
|
169
|
+//短信验证码
|
|
|
170
|
+func (s *AuthService)SmsCode(request *protocol.SmsCodeRequest)(rsp *protocol.SmsCodeResponse,err error){
|
|
|
171
|
+ return nil,nil
|
147
|
} |
172
|
} |