正在显示
5 个修改的文件
包含
42 行增加
和
13 行删除
@@ -4,7 +4,6 @@ import ( | @@ -4,7 +4,6 @@ import ( | ||
4 | "crypto/sha256" | 4 | "crypto/sha256" |
5 | "encoding/hex" | 5 | "encoding/hex" |
6 | "fmt" | 6 | "fmt" |
7 | - "github.com/astaxie/beego" | ||
8 | "strconv" | 7 | "strconv" |
9 | "strings" | 8 | "strings" |
10 | 9 | ||
@@ -108,12 +107,11 @@ func FilterComm(ctx *context.Context) { | @@ -108,12 +107,11 @@ func FilterComm(ctx *context.Context) { | ||
108 | // return | 107 | // return |
109 | //} | 108 | //} |
110 | //TODO:注入账号,后期移除掉 | 109 | //TODO:注入账号,后期移除掉 |
111 | - if beego.BConfig.RunMode != "prod" || ctx.Input.Header("x-mmm-accesstoken") == "" { | 110 | + if ctx.Input.Header("x-mmm-accesstoken") == "" { |
112 | ctx.Request.Header.Set("x-mmm-accesstoken", "6839602f1d8211eabd85000c29ad8d6d") | 111 | ctx.Request.Header.Set("x-mmm-accesstoken", "6839602f1d8211eabd85000c29ad8d6d") |
113 | if ctx.Input.Header("x-mmm-accesstoken") == "" { | 112 | if ctx.Input.Header("x-mmm-accesstoken") == "" { |
114 | ctx.Request.Header.Add("x-mmm-accesstoken", "6839602f1d8211eabd85000c29ad8d6d") | 113 | ctx.Request.Header.Add("x-mmm-accesstoken", "6839602f1d8211eabd85000c29ad8d6d") |
115 | } | 114 | } |
116 | - //return | ||
117 | } else { | 115 | } else { |
118 | //1.检查签名 | 116 | //1.检查签名 |
119 | if !CheckSign(ctx) { | 117 | if !CheckSign(ctx) { |
@@ -18,6 +18,7 @@ type Company struct { | @@ -18,6 +18,7 @@ type Company struct { | ||
18 | CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now" description:"创建时间"` | 18 | CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now" description:"创建时间"` |
19 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | 19 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` |
20 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"` | 20 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"` |
21 | + UserCenterId int64 `orm:"column(user_center_id)" description:"统一用户中心企业id"` | ||
21 | } | 22 | } |
22 | 23 | ||
23 | func (t *Company) TableName() string { | 24 | func (t *Company) TableName() string { |
@@ -32,6 +32,7 @@ type RequestHeader struct { | @@ -32,6 +32,7 @@ type RequestHeader struct { | ||
32 | /*Login */ | 32 | /*Login */ |
33 | type LoginRequest struct { | 33 | type LoginRequest struct { |
34 | Uid int64 `json:"uid" valid:"Required;"` | 34 | Uid int64 `json:"uid" valid:"Required;"` |
35 | + Token string `json:"token" valid:"Required;"` | ||
35 | } | 36 | } |
36 | type LoginResponse struct { | 37 | type LoginResponse struct { |
37 | AuthCode string `json:"authCode"` | 38 | AuthCode string `json:"authCode"` |
@@ -10,6 +10,7 @@ const ( | @@ -10,6 +10,7 @@ const ( | ||
10 | MethodGetUser = "/users/" | 10 | MethodGetUser = "/users/" |
11 | MethodPutUser = "/users/" | 11 | MethodPutUser = "/users/" |
12 | MethodUserExists = "/users/isExist" | 12 | MethodUserExists = "/users/isExist" |
13 | + MethodServerLogin = "/auth/serverLogin" | ||
13 | ) | 14 | ) |
14 | 15 | ||
15 | /*UCenterLogin */ | 16 | /*UCenterLogin */ |
@@ -19,6 +20,11 @@ type UCenterLoginRequest struct { | @@ -19,6 +20,11 @@ type UCenterLoginRequest struct { | ||
19 | Code string `json:"code"` | 20 | Code string `json:"code"` |
20 | GrantType string `json:"grantType" valid:"Required"` | 21 | GrantType string `json:"grantType" valid:"Required"` |
21 | //ClientId string `json:"clientId" valid:"Required"` | 22 | //ClientId string `json:"clientId" valid:"Required"` |
23 | + | ||
24 | + Type int `json:"typoe"` //1为密码登录,管理后台登录,2为token登录,app登录 | ||
25 | + | ||
26 | + Uid int64 `json:"uid"` // type2 | ||
27 | + //CompanyId int64 `json:"companyId"` // type2 | ||
22 | } | 28 | } |
23 | type UCenterLoginResponse struct { | 29 | type UCenterLoginResponse struct { |
24 | Uid int64 `json:"uid"` //统一用户中心用户编号,作为登录凭证 | 30 | Uid int64 `json:"uid"` //统一用户中心用户编号,作为登录凭证 |
@@ -39,9 +45,9 @@ type UCenterGetUserResponse struct { | @@ -39,9 +45,9 @@ type UCenterGetUserResponse struct { | ||
39 | Phone string `json:"phone"` | 45 | Phone string `json:"phone"` |
40 | NickName string `json:"nickname"` | 46 | NickName string `json:"nickname"` |
41 | Avatar string `json:"avatar"` | 47 | Avatar string `json:"avatar"` |
42 | - Token string `json:"token"` | ||
43 | - Accid string `json:"accid"` | ||
44 | - CustomerAccount string `json:"customerAccount"` | 48 | + ImToken string `json:"imtoken"` |
49 | + Accid int64 `json:"accid"` | ||
50 | + CustomerAccount int64 `json:"customerAccount"` | ||
45 | } | 51 | } |
46 | 52 | ||
47 | /*修改用户信息 UCenterPutUser */ | 53 | /*修改用户信息 UCenterPutUser */ |
@@ -53,3 +59,14 @@ type UCenterPutUserRequest struct { | @@ -53,3 +59,14 @@ type UCenterPutUserRequest struct { | ||
53 | } | 59 | } |
54 | type UCenterPutUserResponse struct { | 60 | type UCenterPutUserResponse struct { |
55 | } | 61 | } |
62 | + | ||
63 | +/*服务端登录*/ | ||
64 | +type UCenterServerLoginRequest struct { | ||
65 | + Token string `json:"token"` | ||
66 | + Uid int64 `json:"uid"` | ||
67 | + CompanyId int64 `json:"company_id"` | ||
68 | + Type int `json:"type"` //1为密码登录,管理后台登录,2为token登录,app登录 | ||
69 | +} | ||
70 | + | ||
71 | +//type UCenterServerLoginResponse struct { | ||
72 | +//} |
@@ -9,7 +9,6 @@ import ( | @@ -9,7 +9,6 @@ import ( | ||
9 | "net/http" | 9 | "net/http" |
10 | "opp/internal/utils" | 10 | "opp/internal/utils" |
11 | "opp/services/agg" | 11 | "opp/services/agg" |
12 | - "strconv" | ||
13 | "time" | 12 | "time" |
14 | 13 | ||
15 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid" | 14 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid" |
@@ -37,9 +36,14 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | @@ -37,9 +36,14 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | ||
37 | var ( | 36 | var ( |
38 | user *models.User | 37 | user *models.User |
39 | userAuth *models.UserAuth | 38 | userAuth *models.UserAuth |
40 | - getUserRequest *protocol.UCenterGetUserRequest = &protocol.UCenterGetUserRequest{} | 39 | + getUserRequest *protocol.UCenterServerLoginRequest = &protocol.UCenterServerLoginRequest{ |
40 | + Uid: request.Uid, | ||
41 | + Token: request.Token, | ||
42 | + Type: 2, | ||
43 | + } | ||
41 | getUserResponse *protocol.UCenterGetUserResponse | 44 | getUserResponse *protocol.UCenterGetUserResponse |
42 | message *protocol.Message | 45 | message *protocol.Message |
46 | + company *models.Company | ||
43 | ) | 47 | ) |
44 | user, err = models.GetUserByUcenterId(request.Uid) | 48 | user, err = models.GetUserByUcenterId(request.Uid) |
45 | if err != nil { | 49 | if err != nil { |
@@ -47,10 +51,15 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | @@ -47,10 +51,15 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | ||
47 | err = protocol.NewErrWithMessage(2002, err) //账号不存在 | 51 | err = protocol.NewErrWithMessage(2002, err) //账号不存在 |
48 | return | 52 | return |
49 | } | 53 | } |
54 | + if userAuth, err = models.GetUserAuthByUserId(user.Id, protocol.DeviceType); err == nil { | ||
55 | + if company, err = models.GetCompanyById(userAuth.CurrentCompanyId); err == nil { | ||
56 | + getUserRequest.CompanyId = company.UserCenterId | ||
57 | + } | ||
58 | + } | ||
50 | //TODO:验证模块权限 | 59 | //TODO:验证模块权限 |
51 | 60 | ||
52 | //从用户中心获取用户信息 | 61 | //从用户中心获取用户信息 |
53 | - if _, err = agg.RequestUserCenter(fmt.Sprintf("%v%v", protocol.MethodGetUser, request.Uid), http.MethodGet, getUserRequest, &message); err != nil { | 62 | + if _, err = agg.RequestUserCenter(protocol.MethodServerLogin, http.MethodPost, getUserRequest, &message); err != nil { |
54 | log.Error(err) | 63 | log.Error(err) |
55 | return | 64 | return |
56 | } | 65 | } |
@@ -70,9 +79,12 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | @@ -70,9 +79,12 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | ||
70 | case 2002: | 79 | case 2002: |
71 | err = protocol.NewErrWithMessage(2002, err) //账号不存在 | 80 | err = protocol.NewErrWithMessage(2002, err) //账号不存在 |
72 | return | 81 | return |
82 | + case 10001: | ||
83 | + err = protocol.NewErrWithMessage(2002, err) //账号不存在 | ||
84 | + return | ||
73 | default: | 85 | default: |
74 | err = fmt.Errorf("error_no:%v msg:%v", message.Errno, message.Errmsg) | 86 | err = fmt.Errorf("error_no:%v msg:%v", message.Errno, message.Errmsg) |
75 | - break | 87 | + return |
76 | } | 88 | } |
77 | 89 | ||
78 | Success: | 90 | Success: |
@@ -93,11 +105,11 @@ Success: | @@ -93,11 +105,11 @@ Success: | ||
93 | userAuth.AuthCode = uid.NewV1().StringNoDash() | 105 | userAuth.AuthCode = uid.NewV1().StringNoDash() |
94 | 106 | ||
95 | /*更新用户信息*/ | 107 | /*更新用户信息*/ |
96 | - user.CsAccount, _ = strconv.ParseInt(getUserResponse.CustomerAccount, 10, 64) | ||
97 | - user.ImToken = getUserResponse.Token | 108 | + user.CsAccount = getUserResponse.CustomerAccount |
109 | + user.ImToken = getUserResponse.ImToken | ||
98 | user.Icon = getUserResponse.Avatar | 110 | user.Icon = getUserResponse.Avatar |
99 | user.NickName = getUserResponse.NickName | 111 | user.NickName = getUserResponse.NickName |
100 | - user.Accid, _ = strconv.ParseInt(getUserResponse.Accid, 10, 64) | 112 | + user.Accid = getUserResponse.Accid |
101 | user.UserCenterId = getUserResponse.Id | 113 | user.UserCenterId = getUserResponse.Id |
102 | if err = repository.User.UpdateUserInfo(user); err != nil { | 114 | if err = repository.User.UpdateUserInfo(user); err != nil { |
103 | log.Error(err) | 115 | log.Error(err) |
-
请 注册 或 登录 后发表评论