作者 yangfu

修改: 登录提示修改

... ... @@ -4,9 +4,11 @@ import (
"fmt"
"github.com/tiptok/gocomm/xa/eda"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/event"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/domain_service"
http_gateway "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
... ... @@ -315,10 +317,10 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom
rsp.Partner, _ = loginSvr.PartnerStaticInfo()
rsp.Manager, _ = loginSvr.ManagerStaticInfo()
//没有有效人的时候
//if rsp.Partner ==nil && rsp.Manager ==nil{
// err = protocol.NewErrWithMessage(2002) //账号禁用
// return
//}
if !loginSvr.AvailableCompany {
err = protocol.NewErrWithMessage(10008) //账号禁用
return
}
var nickName string
if len(loginSvr.Users) > 0 {
... ... @@ -364,6 +366,11 @@ func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest
loginSvr.Init(claim.Phone)
rsp.Partner, _ = loginSvr.PartnerStaticInfo()
rsp.Manager, _ = loginSvr.ManagerStaticInfo()
//没有有效人的时候
if !loginSvr.AvailableCompany {
err = protocol.NewErrWithMessage(4140, err) //账号禁用
return
}
err = transactionContext.CommitTransaction()
return
}
... ... @@ -374,7 +381,9 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (
transactionContext, _ = factory.CreateTransactionContext(nil)
PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
CompanyRepository, _ = factory.CreateCompanyRepository(transactionContext)
userId int64
adminApiGateway = http_gateway.NewHttplibBusinessAdminApiServiceGateway()
)
rsp = &protocol.LoginResponse{}
if err = transactionContext.StartTransaction(); err != nil {
... ... @@ -387,15 +396,35 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (
err = protocol.NewErrWithMessage(4140, err)
return
}
if company, e := CompanyRepository.FindOne(map[string]interface{}{"id": request.Cid, "enable": 1}); e != nil || company == nil {
err = protocol.NewErrWithMessage(10007, err)
return
}
switch request.IdType {
case int(protocolx.AdminTypePartner):
if p, e := PartnerInfoRepository.FindOne(map[string]interface{}{"account": claim.Phone, "companyId": request.Cid, "status": 1}); e == nil {
if p, e := PartnerInfoRepository.FindOne(map[string]interface{}{"account": claim.Phone, "companyId": request.Cid}); e == nil {
userId = p.Id
if !p.IsEnable() {
err = protocol.NewErrWithMessage(10006, err) //当前账号已被禁用
return
}
}
break
case int(protocolx.AdminTypeManager):
if p, e := UsersRepository.FindOne(map[string]interface{}{"phone": claim.Phone, "companyId": request.Cid, "status": 1}); e == nil {
if p, e := UsersRepository.FindOne(map[string]interface{}{"phone": claim.Phone, "companyId": request.Cid}); e == nil {
userId = p.Id
if !p.IsEnable() {
err = protocol.NewErrWithMessage(10006, err) //当前账号已被禁用
return
}
}
//校验模块权限
if userId != 0 {
if code, e := adminApiGateway.UserAuth(userId, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 {
log.Debug("【检查权限】", userId, "【公司】", request.Cid, "【错误】:", code, e.Error())
err = protocol.NewErrWithMessage(10008, err) // 抱歉,企业管理员未帮您开通权限
return
}
}
break
default:
... ... @@ -403,7 +432,7 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (
return
}
if userId == 0 {
err = protocol.NewErrWithMessage(502, err) //账号不存在
err = protocol.NewErrWithMessage(10001, err) //账号不存在
return
}
//根据simnum + cid
... ...
... ... @@ -66,6 +66,11 @@ type UsersRepository interface {
Find(queryOptions map[string]interface{}) (int64, []*Users, error)
}
//账号是否有效
func (m *Users) IsEnable() bool {
return m.Status == 1
}
func (m *Users) Identify() interface{} {
if m.Id == 0 {
return nil
... ...
... ... @@ -23,28 +23,27 @@ func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService {
func (s *PgAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) {
errPartner := s.partner.ChangeUserPhone(userId, newPhone, oldPhone)
errManager := s.manager.ChangeUserPhone(userId, newPhone, oldPhone)
if errPartner != nil && errManager != nil {
log.Error("partner:", errPartner, "mannager:", errManager)
err = errPartner
return
}
return
return errResolve(errPartner, errManager)
}
func (s *PgAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) {
errPartner := s.partner.ChangeUserPassword(userId, newPwd, oldPwd, phone)
errManager := s.manager.ChangeUserPassword(userId, newPwd, oldPwd, phone)
if errPartner != nil && errManager != nil {
log.Error(errPartner, errManager)
err = errPartner
return
}
return
return errResolve(errPartner, errManager)
}
func (s *PgAuthService) ResetUserPassword(userId int64, phone, password string) (err error) {
errPartner := s.partner.ResetUserPassword(userId, phone, password)
errManager := s.manager.ResetUserPassword(userId, phone, password)
return errResolve(errPartner, errManager)
}
func errResolve(errPartner, errManager error) (err error) {
if errPartner != nil {
log.Error("partner:", errPartner)
}
if errManager != nil {
log.Error("mannager:", errManager)
}
if errPartner != nil && errManager != nil {
log.Error(errPartner, errManager)
err = errPartner
return
}
... ...
... ... @@ -21,6 +21,7 @@ type PgLoginService struct {
PartnerInfo []*domain.PartnerInfo
Users []*domain.Users
transactionContext *transaction.TransactionContext
AvailableCompany bool
}
func (svr *PgLoginService) Init(phone string) (err error) {
... ... @@ -142,6 +143,9 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
}
companys = append(companys, item)
}
if len(companys) > 0 {
svr.AvailableCompany = true
}
response["companys"] = companys
return response, nil
... ... @@ -170,7 +174,7 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) {
for i := range companyList {
c := companyList[i]
if constant.POSTGRESQL_DB_NAME != "partner_dev" {
if constant.POSTGRESQL_DB_NAME != "partner_dev1" {
//通过企业平台 校验模块权限
var user *domain.Users
for j := range svr.Users {
... ... @@ -179,6 +183,11 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) {
break
}
}
// 删除跳过
if user.DeleteAt.Unix() > 0 {
log.Debug("【检查权限】", svr.Phone, "【公司】", c.Id, user.Id, 0, "已删除,跳过")
continue
}
if user != nil {
if code, e := adminApiGateway.UserAuth(user.Id, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 {
log.Debug("【检查权限】", svr.Phone, "【公司】", c.Id, user.Id, code, e.Error())
... ... @@ -191,6 +200,9 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) {
item := newCompanyBase(c)
companys = append(companys, item)
}
if len(companys) > 0 {
svr.AvailableCompany = true
}
response["companys"] = companys
return response, nil
... ... @@ -300,5 +312,6 @@ type joinWay struct {
func NewPgLoginService(ctx *transaction.TransactionContext) *PgLoginService {
return &PgLoginService{
transactionContext: ctx,
AvailableCompany: false,
}
}
... ...
... ... @@ -26,4 +26,18 @@ var errmessge ErrorMap = map[int]string{
4140: "refreshToken过期,需要重新登录授权",
4141: "accessToken过期或无效,需要进行重新获取令牌",
4142: "Uuid已存在,请求失败",
// 平台级错误
10001: "用户不存在",
10002: "登录凭证已过期,请重新登陆",
10003: "验证码不能为空",
10004: "登录凭证不能为空",
10005: "密码不能为空",
10006: "当前账号已被禁用",
10007: "该企业已被禁用,无法正常访问!重新选择其他企业进入,或退出登录",
10008: "抱歉,企业管理员未帮您开通权限。如需访问,请联系企业管理员",
10009: "密码错误",
10010: " 验证码错误",
}
... ...