|
@@ -4,16 +4,17 @@ import ( |
|
@@ -4,16 +4,17 @@ import ( |
4
|
"bytes"
|
4
|
"bytes"
|
5
|
"encoding/json"
|
5
|
"encoding/json"
|
6
|
"fmt"
|
6
|
"fmt"
|
7
|
- "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid"
|
|
|
8
|
"html/template"
|
7
|
"html/template"
|
9
|
"strings"
|
8
|
"strings"
|
10
|
"time"
|
9
|
"time"
|
11
|
|
10
|
|
|
|
11
|
+ "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid"
|
|
|
12
|
+
|
12
|
"ability/internal/repository"
|
13
|
"ability/internal/repository"
|
13
|
"ability/models"
|
14
|
"ability/models"
|
14
|
"ability/protocol"
|
15
|
"ability/protocol"
|
15
|
- s_sms "ability/services/sms"
|
|
|
16
|
s_im "ability/services/im"
|
16
|
s_im "ability/services/im"
|
|
|
17
|
+ s_sms "ability/services/sms"
|
17
|
|
18
|
|
18
|
"github.com/astaxie/beego"
|
19
|
"github.com/astaxie/beego"
|
19
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
|
20
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
|
|
@@ -40,7 +41,7 @@ func assertImplement() { |
|
@@ -40,7 +41,7 @@ func assertImplement() { |
40
|
|
41
|
|
41
|
var (
|
42
|
var (
|
42
|
//服务
|
43
|
//服务
|
43
|
- sms s_sms.ISmsService = &s_sms.YunPianSmsService{}
|
44
|
+ sms s_sms.ISmsService = &s_sms.YunPianSmsService{}
|
44
|
ConfigRepository repository.IConfigRepository = &repository.ConfigRepository{}
|
45
|
ConfigRepository repository.IConfigRepository = &repository.ConfigRepository{}
|
45
|
//仓储
|
46
|
//仓储
|
46
|
UserRepository repository.IUserRepository = &repository.UserRepository{}
|
47
|
UserRepository repository.IUserRepository = &repository.UserRepository{}
|
|
@@ -49,9 +50,9 @@ var ( |
|
@@ -49,9 +50,9 @@ var ( |
49
|
//登录
|
50
|
//登录
|
50
|
func (s *AuthService) Login(request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) {
|
51
|
func (s *AuthService) Login(request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) {
|
51
|
var (
|
52
|
var (
|
52
|
- user *models.Users
|
|
|
53
|
- userInfo *models.UserInfo
|
|
|
54
|
- result bool
|
53
|
+ user *models.Users
|
|
|
54
|
+ userInfo *models.UserInfo
|
|
|
55
|
+ result bool
|
55
|
checkImResponse *protocol.CheckImResponse
|
56
|
checkImResponse *protocol.CheckImResponse
|
56
|
)
|
57
|
)
|
57
|
user, err = UserRepository.GetUsersByMobile(request.Phone)
|
58
|
user, err = UserRepository.GetUsersByMobile(request.Phone)
|
|
@@ -89,19 +90,19 @@ Success: |
|
@@ -89,19 +90,19 @@ Success: |
89
|
if userInfo.Auth == "" {
|
90
|
if userInfo.Auth == "" {
|
90
|
userInfo.Auth = uid.NewV1().StringNoDash()
|
91
|
userInfo.Auth = uid.NewV1().StringNoDash()
|
91
|
}
|
92
|
}
|
92
|
- if checkImResponse,err=CheckIm(&protocol.CheckImRequest{
|
|
|
93
|
- Uid:fmt.Sprintf("%v",userInfo.Id),
|
|
|
94
|
- Uname:userInfo.Uname,
|
|
|
95
|
- Icon:userInfo.Icon,
|
|
|
96
|
- IsCreated:userInfo.ImToken=="",
|
|
|
97
|
- });err!=nil{
|
93
|
+ if checkImResponse, err = CheckIm(&protocol.CheckImRequest{
|
|
|
94
|
+ Uid: fmt.Sprintf("%v", userInfo.Id),
|
|
|
95
|
+ Uname: userInfo.Uname,
|
|
|
96
|
+ Icon: userInfo.Icon,
|
|
|
97
|
+ IsCreated: userInfo.ImToken == "",
|
|
|
98
|
+ }); err != nil {
|
98
|
return
|
99
|
return
|
99
|
}
|
100
|
}
|
100
|
userInfo.ImToken = checkImResponse.ImToken
|
101
|
userInfo.ImToken = checkImResponse.ImToken
|
101
|
- if userInfo.CsAccount==0{
|
102
|
+ if userInfo.CsAccount == 0 {
|
102
|
userInfo.CsAccount = checkImResponse.CsAccount
|
103
|
userInfo.CsAccount = checkImResponse.CsAccount
|
103
|
}
|
104
|
}
|
104
|
- userInfo.AuthExp = time.Now().Add(time.Second*protocol.TokenExpire)
|
105
|
+ userInfo.AuthExp = time.Now().Add(time.Second * protocol.TokenExpire)
|
105
|
if err = UserRepository.UpdateUserInfoById(userInfo); err != nil {
|
106
|
if err = UserRepository.UpdateUserInfoById(userInfo); err != nil {
|
106
|
return
|
107
|
return
|
107
|
}
|
108
|
}
|
|
@@ -149,7 +150,7 @@ func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *pr |
|
@@ -149,7 +150,7 @@ func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *pr |
149
|
//刷新token
|
150
|
//刷新token
|
150
|
func (s *AuthService) RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshTokenResponse, err error) {
|
151
|
func (s *AuthService) RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshTokenResponse, err error) {
|
151
|
var (
|
152
|
var (
|
152
|
- userInfo *models.UserInfo
|
153
|
+ userInfo *models.UserInfo
|
153
|
)
|
154
|
)
|
154
|
_, err = ConfigRepository.GetCfgClient(request.ClientId, request.ClientSecret)
|
155
|
_, err = ConfigRepository.GetCfgClient(request.ClientId, request.ClientSecret)
|
155
|
if err != nil {
|
156
|
if err != nil {
|
|
@@ -326,93 +327,92 @@ Fail: |
|
@@ -326,93 +327,92 @@ Fail: |
326
|
return
|
327
|
return
|
327
|
}
|
328
|
}
|
328
|
|
329
|
|
329
|
-func CheckIm(request *protocol.CheckImRequest)(rsp *protocol.CheckImResponse,err error){
|
|
|
330
|
- var (
|
|
|
331
|
-
|
|
|
332
|
- )
|
330
|
+func CheckIm(request *protocol.CheckImRequest) (rsp *protocol.CheckImResponse, err error) {
|
|
|
331
|
+ var ()
|
333
|
if beego.BConfig.RunMode != "prod" {
|
332
|
if beego.BConfig.RunMode != "prod" {
|
334
|
return
|
333
|
return
|
335
|
}
|
334
|
}
|
336
|
- rsp =&protocol.CheckImResponse{}
|
|
|
337
|
- if !request.IsCreated{
|
|
|
338
|
- if err = imUserCreate(request,rsp);err!=nil{
|
335
|
+ rsp = &protocol.CheckImResponse{}
|
|
|
336
|
+ if !request.IsCreated {
|
|
|
337
|
+ if err = imUserCreate(request, rsp); err != nil {
|
339
|
return
|
338
|
return
|
340
|
}
|
339
|
}
|
341
|
- }else{
|
|
|
342
|
- if err = imUserInfoUpdate(request,rsp);err!=nil{
|
340
|
+ } else {
|
|
|
341
|
+ if err = imUserInfoUpdate(request, rsp); err != nil {
|
343
|
return
|
342
|
return
|
344
|
}
|
343
|
}
|
345
|
}
|
344
|
}
|
346
|
- if err = imUserRefreshToken(request,rsp);err!=nil{
|
345
|
+ if err = imUserRefreshToken(request, rsp); err != nil {
|
347
|
return
|
346
|
return
|
348
|
}
|
347
|
}
|
349
|
return
|
348
|
return
|
350
|
}
|
349
|
}
|
|
|
350
|
+
|
351
|
//create
|
351
|
//create
|
352
|
-func imUserCreate(request *protocol.CheckImRequest,rsp *protocol.CheckImResponse)(err error){
|
|
|
353
|
- var(
|
|
|
354
|
- param s_im.UserCreate=s_im.UserCreate{
|
|
|
355
|
- Accid:request.Uid,
|
|
|
356
|
- Name:request.Uname,
|
|
|
357
|
- Icon:request.Icon,
|
352
|
+func imUserCreate(request *protocol.CheckImRequest, rsp *protocol.CheckImResponse) (err error) {
|
|
|
353
|
+ var (
|
|
|
354
|
+ param s_im.UserCreate = s_im.UserCreate{
|
|
|
355
|
+ Accid: request.Uid,
|
|
|
356
|
+ Name: request.Uname,
|
|
|
357
|
+ Icon: request.Icon,
|
358
|
}
|
358
|
}
|
359
|
resp []byte
|
359
|
resp []byte
|
360
|
- out s_im.UserCreateResult
|
360
|
+ out s_im.UserCreateResult
|
361
|
)
|
361
|
)
|
362
|
- if resp,err=s_im.DefaultImClient.Call(param);err!=nil{
|
362
|
+ if resp, err = s_im.DefaultImClient.Call(param); err != nil {
|
363
|
return
|
363
|
return
|
364
|
}
|
364
|
}
|
365
|
- if err = json.Unmarshal(resp,&out);err!=nil{
|
365
|
+ if err = json.Unmarshal(resp, &out); err != nil {
|
366
|
return
|
366
|
return
|
367
|
}
|
367
|
}
|
368
|
- if out.Code!=200 || (out.Info.Accid!=request.Uid){
|
368
|
+ if out.Code != 200 || (out.Info.Accid != request.Uid) {
|
369
|
return s_im.ErrorFailCall
|
369
|
return s_im.ErrorFailCall
|
370
|
}
|
370
|
}
|
371
|
rsp.ImToken = out.Info.Token
|
371
|
rsp.ImToken = out.Info.Token
|
372
|
return
|
372
|
return
|
373
|
}
|
373
|
}
|
|
|
374
|
+
|
374
|
//update user info
|
375
|
//update user info
|
375
|
-func imUserInfoUpdate(request *protocol.CheckImRequest,rsp *protocol.CheckImResponse)(err error){
|
|
|
376
|
- var(
|
|
|
377
|
- param s_im.UserUpdateUinfo=s_im.UserUpdateUinfo{
|
|
|
378
|
- Accid:request.Uid,
|
|
|
379
|
- Name:request.Uname,
|
|
|
380
|
- Icon:request.Icon,
|
376
|
+func imUserInfoUpdate(request *protocol.CheckImRequest, rsp *protocol.CheckImResponse) (err error) {
|
|
|
377
|
+ var (
|
|
|
378
|
+ param s_im.UserUpdateUinfo = s_im.UserUpdateUinfo{
|
|
|
379
|
+ Accid: request.Uid,
|
|
|
380
|
+ Name: request.Uname,
|
|
|
381
|
+ Icon: request.Icon,
|
381
|
}
|
382
|
}
|
382
|
resp []byte
|
383
|
resp []byte
|
383
|
- out s_im.BaseResp
|
384
|
+ out s_im.BaseResp
|
384
|
)
|
385
|
)
|
385
|
- if resp,err=s_im.DefaultImClient.Call(param);err!=nil{
|
386
|
+ if resp, err = s_im.DefaultImClient.Call(param); err != nil {
|
386
|
return
|
387
|
return
|
387
|
}
|
388
|
}
|
388
|
- if err = json.Unmarshal(resp,&out);err!=nil{
|
389
|
+ if err = json.Unmarshal(resp, &out); err != nil {
|
389
|
return
|
390
|
return
|
390
|
}
|
391
|
}
|
391
|
- if out.Code!=200{
|
392
|
+ if out.Code != 200 {
|
392
|
return s_im.ErrorFailCall
|
393
|
return s_im.ErrorFailCall
|
393
|
}
|
394
|
}
|
394
|
return
|
395
|
return
|
395
|
}
|
396
|
}
|
|
|
397
|
+
|
396
|
//refresh token
|
398
|
//refresh token
|
397
|
-func imUserRefreshToken(request *protocol.CheckImRequest,rsp *protocol.CheckImResponse)(err error){
|
|
|
398
|
- var(
|
|
|
399
|
- param s_im.UserRefreshToken=s_im.UserRefreshToken{
|
|
|
400
|
- Accid:request.Uid,
|
399
|
+func imUserRefreshToken(request *protocol.CheckImRequest, rsp *protocol.CheckImResponse) (err error) {
|
|
|
400
|
+ var (
|
|
|
401
|
+ param s_im.UserRefreshToken = s_im.UserRefreshToken{
|
|
|
402
|
+ Accid: request.Uid,
|
401
|
}
|
403
|
}
|
402
|
resp []byte
|
404
|
resp []byte
|
403
|
- out s_im.UserCreateResult
|
405
|
+ out s_im.UserCreateResult
|
404
|
)
|
406
|
)
|
405
|
- if resp,err=s_im.DefaultImClient.Call(param);err!=nil{
|
407
|
+ if resp, err = s_im.DefaultImClient.Call(param); err != nil {
|
406
|
return
|
408
|
return
|
407
|
}
|
409
|
}
|
408
|
- if err = json.Unmarshal(resp,&out);err!=nil{
|
410
|
+ if err = json.Unmarshal(resp, &out); err != nil {
|
409
|
return
|
411
|
return
|
410
|
}
|
412
|
}
|
411
|
- if out.Code!=200 || (out.Info.Accid!=request.Uid){
|
413
|
+ if out.Code != 200 || (out.Info.Accid != request.Uid) {
|
412
|
return s_im.ErrorFailCall
|
414
|
return s_im.ErrorFailCall
|
413
|
}
|
415
|
}
|
414
|
rsp.ImToken = out.Info.Token
|
416
|
rsp.ImToken = out.Info.Token
|
415
|
return
|
417
|
return
|
416
|
} |
418
|
} |
417
|
-
|
|
|
418
|
- |
|
|