|
@@ -4,6 +4,7 @@ import ( |
|
@@ -4,6 +4,7 @@ import ( |
4
|
"github.com/linmadan/egglib-go/core/application"
|
4
|
"github.com/linmadan/egglib-go/core/application"
|
5
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/command"
|
5
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/command"
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
|
|
7
|
+ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
|
7
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
8
|
)
|
9
|
)
|
9
|
|
10
|
|
|
@@ -53,7 +54,7 @@ func (service *AuthService) Login(loginCommand *command.LoginCommand) (interface |
|
@@ -53,7 +54,7 @@ func (service *AuthService) Login(loginCommand *command.LoginCommand) (interface |
53
|
"companyId": company.Id,
|
54
|
"companyId": company.Id,
|
54
|
})
|
55
|
})
|
55
|
if err != nil {
|
56
|
if err != nil {
|
56
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司数据失败")
|
57
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户数据失败")
|
57
|
}
|
58
|
}
|
58
|
if user.Status != domain.UserStatusEnable {
|
59
|
if user.Status != domain.UserStatusEnable {
|
59
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户被禁用")
|
60
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户被禁用")
|
|
@@ -81,9 +82,8 @@ func (service *AuthService) Login(loginCommand *command.LoginCommand) (interface |
|
@@ -81,9 +82,8 @@ func (service *AuthService) Login(loginCommand *command.LoginCommand) (interface |
81
|
}, nil
|
82
|
}, nil
|
82
|
}
|
83
|
}
|
83
|
|
84
|
|
84
|
-//手机端登录 ,来源于能力展示app
|
|
|
85
|
-
|
|
|
86
|
-func (service *AuthService) MobileLogin(param command.AuthorizeCommand) (map[string]interface{}, error) {
|
85
|
+// 员工绩效 手机端登录,来源于能力展示app
|
|
|
86
|
+func (service *AuthService) MobileLogin(param *command.MobileLoginCommand) (map[string]interface{}, error) {
|
87
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
87
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
88
|
if err != nil {
|
88
|
if err != nil {
|
89
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
89
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
@@ -94,13 +94,61 @@ func (service *AuthService) MobileLogin(param command.AuthorizeCommand) (map[str |
|
@@ -94,13 +94,61 @@ func (service *AuthService) MobileLogin(param command.AuthorizeCommand) (map[str |
94
|
defer func() {
|
94
|
defer func() {
|
95
|
_ = transactionContext.RollbackTransaction()
|
95
|
_ = transactionContext.RollbackTransaction()
|
96
|
}()
|
96
|
}()
|
97
|
-
|
97
|
+ // 统一用户中心登录
|
|
|
98
|
+ authCodeReply, err := factory.UCenterApi().AppAuthCode(param.Credentials, param.Cuid, param.Cid)
|
|
|
99
|
+ if err != nil || !authCodeReply.IsOk() {
|
|
|
100
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统一用户中心认证失败")
|
|
|
101
|
+ }
|
|
|
102
|
+ // 用户权限校验
|
|
|
103
|
+ // 登录平台ID,28-绩效管理后台 29-员工绩效
|
|
|
104
|
+ userAuthReply, err := factory.BusinessAdminApi().GetUserAuth(authCodeReply.Data.MUid, constant.IdPlatformUser)
|
|
|
105
|
+ if err != nil {
|
|
|
106
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户鉴权失败")
|
|
|
107
|
+ }
|
|
|
108
|
+ if !userAuthReply.IsOk() {
|
|
|
109
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, userAuthReply.Message())
|
|
|
110
|
+ }
|
|
|
111
|
+ //获取公司数据
|
|
|
112
|
+ companyRepository := factory.CreateCompanyRepository(map[string]interface{}{
|
|
|
113
|
+ "transactionContext": transactionContext,
|
|
|
114
|
+ })
|
|
|
115
|
+ company, err := companyRepository.FindOne(map[string]interface{}{
|
|
|
116
|
+ "id": authCodeReply.Data.CompanyId,
|
|
|
117
|
+ })
|
|
|
118
|
+ if err != nil {
|
|
|
119
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司数据失败")
|
|
|
120
|
+ }
|
|
|
121
|
+ userRepository := factory.CreateUserRepository(map[string]interface{}{
|
|
|
122
|
+ "transactionContext": transactionContext,
|
|
|
123
|
+ })
|
|
|
124
|
+ user, err := userRepository.FindOne(map[string]interface{}{
|
|
|
125
|
+ "id": authCodeReply.Data.MUid,
|
|
|
126
|
+ "companyId": company.Id,
|
|
|
127
|
+ })
|
|
|
128
|
+ if err != nil {
|
|
|
129
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户数据失败")
|
|
|
130
|
+ }
|
|
|
131
|
+ if user.Status != domain.UserStatusEnable {
|
|
|
132
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户被禁用")
|
|
|
133
|
+ }
|
|
|
134
|
+ userAuth := &domain.UserAuth{
|
|
|
135
|
+ UserId: user.Id,
|
|
|
136
|
+ CompanyId: user.CompanyId,
|
|
|
137
|
+ Phone: user.Account,
|
|
|
138
|
+ PlatformId: constant.IdPlatformUser,
|
|
|
139
|
+ Name: user.Name,
|
|
|
140
|
+ AdminType: user.AdminType,
|
|
|
141
|
+ }
|
|
|
142
|
+ accessToken, err := userAuth.CreateAccessToken()
|
|
|
143
|
+ if err != nil {
|
|
|
144
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
145
|
+ }
|
98
|
if err := transactionContext.CommitTransaction(); err != nil {
|
146
|
if err := transactionContext.CommitTransaction(); err != nil {
|
99
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
147
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
100
|
}
|
148
|
}
|
101
|
result := map[string]interface{}{
|
149
|
result := map[string]interface{}{
|
102
|
"access": map[string]interface{}{
|
150
|
"access": map[string]interface{}{
|
103
|
- "accessToken": "",
|
151
|
+ "accessToken": accessToken,
|
104
|
"expiresIn": domain.JWTExpiresSecond,
|
152
|
"expiresIn": domain.JWTExpiresSecond,
|
105
|
},
|
153
|
},
|
106
|
}
|
154
|
}
|