...
|
...
|
@@ -358,6 +358,7 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom |
|
|
imInfo *domain.ImInfo
|
|
|
loginSvr = domain_service.NewPgLoginService(transactionContext)
|
|
|
isSenior bool
|
|
|
isPartner bool
|
|
|
)
|
|
|
|
|
|
// 转换手机号码
|
...
|
...
|
@@ -381,15 +382,15 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom |
|
|
}()
|
|
|
|
|
|
// 通过短信验证码登录的游客,注册一个账号到配置的公司去(ios审核使用)
|
|
|
if request.GrantType == protocol.LoginBySmsCode {
|
|
|
guestErr := loginSvr.RegistryGuest(request.Phone)
|
|
|
if guestErr != nil {
|
|
|
log.Error(guestErr)
|
|
|
}
|
|
|
}
|
|
|
//if request.GrantType == protocol.LoginBySmsCode {
|
|
|
// guestErr := loginSvr.RegistryGuest(request.Phone)
|
|
|
// if guestErr != nil {
|
|
|
// log.Error(guestErr)
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
// 通过密码登录的普通用户,注册一个账号到配置的公司去
|
|
|
if request.GrantType == protocol.LoginByPassword {
|
|
|
// 通过密码或校验码登录的普通用户或通过校验码登录的游客,注册一个账号到配置的公司去
|
|
|
if request.GrantType == protocol.LoginBySmsCode || request.GrantType == protocol.LoginByPassword {
|
|
|
userErr := loginSvr.RegistryUser(request.Phone)
|
|
|
if userErr != nil {
|
|
|
log.Error(userErr)
|
...
|
...
|
@@ -403,14 +404,25 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom |
|
|
return
|
|
|
}
|
|
|
|
|
|
// 高管初始化
|
|
|
// 高管标志位初始化
|
|
|
_ = loginSvr.InitSenior(request.Phone)
|
|
|
if len(loginSvr.Users) == 0 {
|
|
|
if len(loginSvr.IsSenior) == 0 {
|
|
|
isSenior = false
|
|
|
} else {
|
|
|
isSenior = true
|
|
|
}
|
|
|
|
|
|
// 合伙人标志位初始化
|
|
|
_ = loginSvr.InitPartner(request.Phone)
|
|
|
if len(loginSvr.IsPartnerInfo) == 0 {
|
|
|
isPartner = false
|
|
|
} else {
|
|
|
isPartner = true
|
|
|
}
|
|
|
|
|
|
fmt.Print(isPartner, "\n")
|
|
|
fmt.Print(isSenior, "\n")
|
|
|
|
|
|
switch request.GrantType {
|
|
|
case protocol.LoginByPassword:
|
|
|
if len(request.Password) == 0 {
|
...
|
...
|
@@ -422,6 +434,19 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom |
|
|
err = protocol.NewCustomMessage(1, "密码输入有误!")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//if isPartner { // 合伙人登录
|
|
|
// if loginSvr.ManagerLogin(request.Phone, request.Password) != nil && loginSvr.PartnerLogin(request.Phone, request.Password) != nil {
|
|
|
// err = protocol.NewCustomMessage(1, "密码输入有误!")
|
|
|
// return
|
|
|
// }
|
|
|
//} else { // 非合伙人高管或者非合伙人非高管
|
|
|
// if loginSvr.ManagerLogin(request.Phone, request.Password) != nil {
|
|
|
// err = protocol.NewCustomMessage(1, "密码输入有错误!")
|
|
|
// return
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
break
|
|
|
case protocol.LoginBySmsCode:
|
|
|
if _, err = CheckSmsCode(request.Phone, request.Captcha); err != nil {
|
...
|
...
|
@@ -477,23 +502,32 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom |
|
|
userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials)
|
|
|
|
|
|
// 判断是否高管
|
|
|
if isSenior {
|
|
|
if isSenior && isPartner { // 高管且合伙人
|
|
|
v = map[string]interface{}{"center": rsp}
|
|
|
} else {
|
|
|
} else if isSenior && !isPartner { // 高管非合伙人
|
|
|
var companies []interface{}
|
|
|
|
|
|
if rsp.Partner.(map[string]interface{})["companys"] != nil {
|
|
|
for _, company := range rsp.Partner.(map[string]interface{})["companys"].([]*domain_service.Company) {
|
|
|
if rsp.Manager.(map[string]interface{})["companys"] != nil {
|
|
|
for _, company := range rsp.Manager.(map[string]interface{})["companys"].([]protocol.CompanyBase) {
|
|
|
companies = append(companies, company)
|
|
|
}
|
|
|
} else {
|
|
|
companies = []interface{}{}
|
|
|
}
|
|
|
|
|
|
if rsp.Manager.(map[string]interface{})["companys"] != nil {
|
|
|
for _, company := range rsp.Manager.(map[string]interface{})["companys"].([]struct{}) {
|
|
|
rsp.Partner.(map[string]interface{})["companys"] = []struct{}{}
|
|
|
rsp.Manager.(map[string]interface{})["companys"] = companies
|
|
|
|
|
|
v = map[string]interface{}{"center": rsp}
|
|
|
} else { // 非高管合伙人
|
|
|
var companies []interface{}
|
|
|
|
|
|
if rsp.Partner.(map[string]interface{})["companys"] != nil {
|
|
|
for _, company := range rsp.Partner.(map[string]interface{})["companys"].([]*domain_service.Company) {
|
|
|
companies = append(companies, company)
|
|
|
}
|
|
|
} else {
|
|
|
companies = []interface{}{}
|
|
|
}
|
|
|
|
|
|
rsp.Partner.(map[string]interface{})["companys"] = companies
|
...
|
...
|
@@ -519,6 +553,7 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco |
|
|
loginSvr = domain_service.NewPgLoginService(transactionContext)
|
|
|
claim *utils.UserTokenClaims
|
|
|
isSenior bool
|
|
|
isPartner bool
|
|
|
)
|
|
|
rsp = &protocolx.CompanysResponse{}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
...
|
...
|
@@ -528,10 +563,12 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
if claim, err = utils.ParseJWTToken(request.Credentials); err != nil {
|
|
|
err = protocol.NewErrWithMessage(4140, err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//凭证是否存在
|
|
|
if constant.DISENABLE_MULTI_DEVICE_LOGIN {
|
|
|
if credential, e := userAuth.NewRedisUserCredential(claim.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) {
|
...
|
...
|
@@ -544,27 +581,41 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco |
|
|
// loginSvr 初始化
|
|
|
loginSvr.Init(claim.Phone)
|
|
|
|
|
|
// 高管初始化
|
|
|
// 高管标志位初始化
|
|
|
_ = loginSvr.InitSenior(claim.Phone)
|
|
|
if len(loginSvr.Users) == 0 {
|
|
|
if len(loginSvr.IsSenior) == 0 {
|
|
|
isSenior = false
|
|
|
} else {
|
|
|
isSenior = true
|
|
|
}
|
|
|
|
|
|
// 合伙人标志位初始化
|
|
|
_ = loginSvr.InitPartner(claim.Phone)
|
|
|
if len(loginSvr.IsPartnerInfo) == 0 {
|
|
|
isPartner = false
|
|
|
} else {
|
|
|
isPartner = true
|
|
|
}
|
|
|
|
|
|
rsp.Partner, _ = loginSvr.PartnerStaticInfo()
|
|
|
rsp.Manager, _ = loginSvr.ManagerStaticInfo()
|
|
|
|
|
|
if !isSenior { // 非高管普通用户
|
|
|
if !isSenior { // 非高管普通用户, 显示游客公司
|
|
|
var companies []interface{}
|
|
|
for _, company := range rsp.Manager.(map[string]interface{})["companys"].([]struct{}) {
|
|
|
companies = append(companies, company)
|
|
|
}
|
|
|
//for _, company := range rsp.Manager.(map[string]interface{})["companys"].([]protocol.CompanyBase) {
|
|
|
// companies = append(companies, company)
|
|
|
//}
|
|
|
if rsp.Partner.(map[string]interface{})["companys"] != nil {
|
|
|
for _, company := range rsp.Partner.(map[string]interface{})["companys"].([]*domain_service.Company) {
|
|
|
companies = append(companies, company)
|
|
|
}
|
|
|
} else {
|
|
|
companies = []interface{}{}
|
|
|
}
|
|
|
rsp.Partner.(map[string]interface{})["companys"] = companies
|
|
|
rsp.Manager.(map[string]interface{})["companys"] = []struct{}{}
|
|
|
} else if isSenior && !isPartner { // 高管非合伙人,显示高管公司
|
|
|
rsp.Partner.(map[string]interface{})["companys"] = []struct{}{}
|
|
|
}
|
|
|
|
|
|
if !loginSvr.HasAvailableCompany {
|
...
|
...
|
|