正在显示
5 个修改的文件
包含
81 行增加
和
21 行删除
@@ -4,9 +4,11 @@ import ( | @@ -4,9 +4,11 @@ import ( | ||
4 | "fmt" | 4 | "fmt" |
5 | "github.com/tiptok/gocomm/xa/eda" | 5 | "github.com/tiptok/gocomm/xa/eda" |
6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" |
7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" | ||
7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" |
8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/event" | 9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/event" |
9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/domain_service" | 10 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/domain_service" |
11 | + http_gateway "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr" | ||
10 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | 12 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" |
11 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | 13 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" |
12 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | 14 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" |
@@ -315,10 +317,10 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom | @@ -315,10 +317,10 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom | ||
315 | rsp.Partner, _ = loginSvr.PartnerStaticInfo() | 317 | rsp.Partner, _ = loginSvr.PartnerStaticInfo() |
316 | rsp.Manager, _ = loginSvr.ManagerStaticInfo() | 318 | rsp.Manager, _ = loginSvr.ManagerStaticInfo() |
317 | //没有有效人的时候 | 319 | //没有有效人的时候 |
318 | - //if rsp.Partner ==nil && rsp.Manager ==nil{ | ||
319 | - // err = protocol.NewErrWithMessage(2002) //账号禁用 | ||
320 | - // return | ||
321 | - //} | 320 | + if !loginSvr.AvailableCompany { |
321 | + err = protocol.NewErrWithMessage(10008) //账号禁用 | ||
322 | + return | ||
323 | + } | ||
322 | 324 | ||
323 | var nickName string | 325 | var nickName string |
324 | if len(loginSvr.Users) > 0 { | 326 | if len(loginSvr.Users) > 0 { |
@@ -364,6 +366,11 @@ func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest | @@ -364,6 +366,11 @@ func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest | ||
364 | loginSvr.Init(claim.Phone) | 366 | loginSvr.Init(claim.Phone) |
365 | rsp.Partner, _ = loginSvr.PartnerStaticInfo() | 367 | rsp.Partner, _ = loginSvr.PartnerStaticInfo() |
366 | rsp.Manager, _ = loginSvr.ManagerStaticInfo() | 368 | rsp.Manager, _ = loginSvr.ManagerStaticInfo() |
369 | + //没有有效人的时候 | ||
370 | + if !loginSvr.AvailableCompany { | ||
371 | + err = protocol.NewErrWithMessage(4140, err) //账号禁用 | ||
372 | + return | ||
373 | + } | ||
367 | err = transactionContext.CommitTransaction() | 374 | err = transactionContext.CommitTransaction() |
368 | return | 375 | return |
369 | } | 376 | } |
@@ -374,7 +381,9 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) ( | @@ -374,7 +381,9 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) ( | ||
374 | transactionContext, _ = factory.CreateTransactionContext(nil) | 381 | transactionContext, _ = factory.CreateTransactionContext(nil) |
375 | PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) | 382 | PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) |
376 | UsersRepository, _ = factory.CreateUsersRepository(transactionContext) | 383 | UsersRepository, _ = factory.CreateUsersRepository(transactionContext) |
384 | + CompanyRepository, _ = factory.CreateCompanyRepository(transactionContext) | ||
377 | userId int64 | 385 | userId int64 |
386 | + adminApiGateway = http_gateway.NewHttplibBusinessAdminApiServiceGateway() | ||
378 | ) | 387 | ) |
379 | rsp = &protocol.LoginResponse{} | 388 | rsp = &protocol.LoginResponse{} |
380 | if err = transactionContext.StartTransaction(); err != nil { | 389 | if err = transactionContext.StartTransaction(); err != nil { |
@@ -387,15 +396,35 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) ( | @@ -387,15 +396,35 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) ( | ||
387 | err = protocol.NewErrWithMessage(4140, err) | 396 | err = protocol.NewErrWithMessage(4140, err) |
388 | return | 397 | return |
389 | } | 398 | } |
399 | + if company, e := CompanyRepository.FindOne(map[string]interface{}{"id": request.Cid, "enable": 1}); e != nil || company == nil { | ||
400 | + err = protocol.NewErrWithMessage(10007, err) | ||
401 | + return | ||
402 | + } | ||
390 | switch request.IdType { | 403 | switch request.IdType { |
391 | case int(protocolx.AdminTypePartner): | 404 | case int(protocolx.AdminTypePartner): |
392 | - if p, e := PartnerInfoRepository.FindOne(map[string]interface{}{"account": claim.Phone, "companyId": request.Cid, "status": 1}); e == nil { | 405 | + if p, e := PartnerInfoRepository.FindOne(map[string]interface{}{"account": claim.Phone, "companyId": request.Cid}); e == nil { |
393 | userId = p.Id | 406 | userId = p.Id |
407 | + if !p.IsEnable() { | ||
408 | + err = protocol.NewErrWithMessage(10006, err) //当前账号已被禁用 | ||
409 | + return | ||
410 | + } | ||
394 | } | 411 | } |
395 | break | 412 | break |
396 | case int(protocolx.AdminTypeManager): | 413 | case int(protocolx.AdminTypeManager): |
397 | - if p, e := UsersRepository.FindOne(map[string]interface{}{"phone": claim.Phone, "companyId": request.Cid, "status": 1}); e == nil { | 414 | + if p, e := UsersRepository.FindOne(map[string]interface{}{"phone": claim.Phone, "companyId": request.Cid}); e == nil { |
398 | userId = p.Id | 415 | userId = p.Id |
416 | + if !p.IsEnable() { | ||
417 | + err = protocol.NewErrWithMessage(10006, err) //当前账号已被禁用 | ||
418 | + return | ||
419 | + } | ||
420 | + } | ||
421 | + //校验模块权限 | ||
422 | + if userId != 0 { | ||
423 | + if code, e := adminApiGateway.UserAuth(userId, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 { | ||
424 | + log.Debug("【检查权限】", userId, "【公司】", request.Cid, "【错误】:", code, e.Error()) | ||
425 | + err = protocol.NewErrWithMessage(10008, err) // 抱歉,企业管理员未帮您开通权限 | ||
426 | + return | ||
427 | + } | ||
399 | } | 428 | } |
400 | break | 429 | break |
401 | default: | 430 | default: |
@@ -403,7 +432,7 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) ( | @@ -403,7 +432,7 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) ( | ||
403 | return | 432 | return |
404 | } | 433 | } |
405 | if userId == 0 { | 434 | if userId == 0 { |
406 | - err = protocol.NewErrWithMessage(502, err) //账号不存在 | 435 | + err = protocol.NewErrWithMessage(10001, err) //账号不存在 |
407 | return | 436 | return |
408 | } | 437 | } |
409 | //根据simnum + cid | 438 | //根据simnum + cid |
@@ -66,6 +66,11 @@ type UsersRepository interface { | @@ -66,6 +66,11 @@ type UsersRepository interface { | ||
66 | Find(queryOptions map[string]interface{}) (int64, []*Users, error) | 66 | Find(queryOptions map[string]interface{}) (int64, []*Users, error) |
67 | } | 67 | } |
68 | 68 | ||
69 | +//账号是否有效 | ||
70 | +func (m *Users) IsEnable() bool { | ||
71 | + return m.Status == 1 | ||
72 | +} | ||
73 | + | ||
69 | func (m *Users) Identify() interface{} { | 74 | func (m *Users) Identify() interface{} { |
70 | if m.Id == 0 { | 75 | if m.Id == 0 { |
71 | return nil | 76 | return nil |
@@ -23,28 +23,27 @@ func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService { | @@ -23,28 +23,27 @@ func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService { | ||
23 | func (s *PgAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) { | 23 | func (s *PgAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) { |
24 | errPartner := s.partner.ChangeUserPhone(userId, newPhone, oldPhone) | 24 | errPartner := s.partner.ChangeUserPhone(userId, newPhone, oldPhone) |
25 | errManager := s.manager.ChangeUserPhone(userId, newPhone, oldPhone) | 25 | errManager := s.manager.ChangeUserPhone(userId, newPhone, oldPhone) |
26 | - if errPartner != nil && errManager != nil { | ||
27 | - log.Error("partner:", errPartner, "mannager:", errManager) | ||
28 | - err = errPartner | ||
29 | - return | ||
30 | - } | ||
31 | - return | 26 | + return errResolve(errPartner, errManager) |
32 | } | 27 | } |
33 | func (s *PgAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) { | 28 | func (s *PgAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) { |
34 | errPartner := s.partner.ChangeUserPassword(userId, newPwd, oldPwd, phone) | 29 | errPartner := s.partner.ChangeUserPassword(userId, newPwd, oldPwd, phone) |
35 | errManager := s.manager.ChangeUserPassword(userId, newPwd, oldPwd, phone) | 30 | errManager := s.manager.ChangeUserPassword(userId, newPwd, oldPwd, phone) |
36 | - if errPartner != nil && errManager != nil { | ||
37 | - log.Error(errPartner, errManager) | ||
38 | - err = errPartner | ||
39 | - return | ||
40 | - } | ||
41 | - return | 31 | + return errResolve(errPartner, errManager) |
42 | } | 32 | } |
43 | func (s *PgAuthService) ResetUserPassword(userId int64, phone, password string) (err error) { | 33 | func (s *PgAuthService) ResetUserPassword(userId int64, phone, password string) (err error) { |
44 | errPartner := s.partner.ResetUserPassword(userId, phone, password) | 34 | errPartner := s.partner.ResetUserPassword(userId, phone, password) |
45 | errManager := s.manager.ResetUserPassword(userId, phone, password) | 35 | errManager := s.manager.ResetUserPassword(userId, phone, password) |
36 | + return errResolve(errPartner, errManager) | ||
37 | +} | ||
38 | + | ||
39 | +func errResolve(errPartner, errManager error) (err error) { | ||
40 | + if errPartner != nil { | ||
41 | + log.Error("partner:", errPartner) | ||
42 | + } | ||
43 | + if errManager != nil { | ||
44 | + log.Error("mannager:", errManager) | ||
45 | + } | ||
46 | if errPartner != nil && errManager != nil { | 46 | if errPartner != nil && errManager != nil { |
47 | - log.Error(errPartner, errManager) | ||
48 | err = errPartner | 47 | err = errPartner |
49 | return | 48 | return |
50 | } | 49 | } |
@@ -21,6 +21,7 @@ type PgLoginService struct { | @@ -21,6 +21,7 @@ type PgLoginService struct { | ||
21 | PartnerInfo []*domain.PartnerInfo | 21 | PartnerInfo []*domain.PartnerInfo |
22 | Users []*domain.Users | 22 | Users []*domain.Users |
23 | transactionContext *transaction.TransactionContext | 23 | transactionContext *transaction.TransactionContext |
24 | + AvailableCompany bool | ||
24 | } | 25 | } |
25 | 26 | ||
26 | func (svr *PgLoginService) Init(phone string) (err error) { | 27 | func (svr *PgLoginService) Init(phone string) (err error) { |
@@ -142,6 +143,9 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | @@ -142,6 +143,9 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | ||
142 | } | 143 | } |
143 | companys = append(companys, item) | 144 | companys = append(companys, item) |
144 | } | 145 | } |
146 | + if len(companys) > 0 { | ||
147 | + svr.AvailableCompany = true | ||
148 | + } | ||
145 | 149 | ||
146 | response["companys"] = companys | 150 | response["companys"] = companys |
147 | return response, nil | 151 | return response, nil |
@@ -170,7 +174,7 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) { | @@ -170,7 +174,7 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) { | ||
170 | for i := range companyList { | 174 | for i := range companyList { |
171 | c := companyList[i] | 175 | c := companyList[i] |
172 | 176 | ||
173 | - if constant.POSTGRESQL_DB_NAME != "partner_dev" { | 177 | + if constant.POSTGRESQL_DB_NAME != "partner_dev1" { |
174 | //通过企业平台 校验模块权限 | 178 | //通过企业平台 校验模块权限 |
175 | var user *domain.Users | 179 | var user *domain.Users |
176 | for j := range svr.Users { | 180 | for j := range svr.Users { |
@@ -179,6 +183,11 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) { | @@ -179,6 +183,11 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) { | ||
179 | break | 183 | break |
180 | } | 184 | } |
181 | } | 185 | } |
186 | + // 删除跳过 | ||
187 | + if user.DeleteAt.Unix() > 0 { | ||
188 | + log.Debug("【检查权限】", svr.Phone, "【公司】", c.Id, user.Id, 0, "已删除,跳过") | ||
189 | + continue | ||
190 | + } | ||
182 | if user != nil { | 191 | if user != nil { |
183 | if code, e := adminApiGateway.UserAuth(user.Id, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 { | 192 | if code, e := adminApiGateway.UserAuth(user.Id, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 { |
184 | log.Debug("【检查权限】", svr.Phone, "【公司】", c.Id, user.Id, code, e.Error()) | 193 | log.Debug("【检查权限】", svr.Phone, "【公司】", c.Id, user.Id, code, e.Error()) |
@@ -191,6 +200,9 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) { | @@ -191,6 +200,9 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) { | ||
191 | item := newCompanyBase(c) | 200 | item := newCompanyBase(c) |
192 | companys = append(companys, item) | 201 | companys = append(companys, item) |
193 | } | 202 | } |
203 | + if len(companys) > 0 { | ||
204 | + svr.AvailableCompany = true | ||
205 | + } | ||
194 | 206 | ||
195 | response["companys"] = companys | 207 | response["companys"] = companys |
196 | return response, nil | 208 | return response, nil |
@@ -300,5 +312,6 @@ type joinWay struct { | @@ -300,5 +312,6 @@ type joinWay struct { | ||
300 | func NewPgLoginService(ctx *transaction.TransactionContext) *PgLoginService { | 312 | func NewPgLoginService(ctx *transaction.TransactionContext) *PgLoginService { |
301 | return &PgLoginService{ | 313 | return &PgLoginService{ |
302 | transactionContext: ctx, | 314 | transactionContext: ctx, |
315 | + AvailableCompany: false, | ||
303 | } | 316 | } |
304 | } | 317 | } |
@@ -26,4 +26,18 @@ var errmessge ErrorMap = map[int]string{ | @@ -26,4 +26,18 @@ var errmessge ErrorMap = map[int]string{ | ||
26 | 4140: "refreshToken过期,需要重新登录授权", | 26 | 4140: "refreshToken过期,需要重新登录授权", |
27 | 4141: "accessToken过期或无效,需要进行重新获取令牌", | 27 | 4141: "accessToken过期或无效,需要进行重新获取令牌", |
28 | 4142: "Uuid已存在,请求失败", | 28 | 4142: "Uuid已存在,请求失败", |
29 | + | ||
30 | + // 平台级错误 | ||
31 | + 10001: "用户不存在", | ||
32 | + 10002: "登录凭证已过期,请重新登陆", | ||
33 | + 10003: "验证码不能为空", | ||
34 | + 10004: "登录凭证不能为空", | ||
35 | + 10005: "密码不能为空", | ||
36 | + | ||
37 | + 10006: "当前账号已被禁用", | ||
38 | + 10007: "该企业已被禁用,无法正常访问!重新选择其他企业进入,或退出登录", | ||
39 | + 10008: "抱歉,企业管理员未帮您开通权限。如需访问,请联系企业管理员", | ||
40 | + | ||
41 | + 10009: "密码错误", | ||
42 | + 10010: " 验证码错误", | ||
29 | } | 43 | } |
-
请 注册 或 登录 后发表评论