...
|
...
|
@@ -19,6 +19,7 @@ import ( |
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// 该方法废弃
|
|
|
func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -222,7 +223,7 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT |
|
|
return
|
|
|
}
|
|
|
|
|
|
//验证短信验证码 T
|
|
|
// 验证短信验证码 T
|
|
|
func CheckSmsCode(phone, code string) (result bool, err error) {
|
|
|
sms, _ := factory.CreateSmsCodeService()
|
|
|
var data map[string]interface{}
|
...
|
...
|
@@ -236,7 +237,7 @@ func CheckSmsCode(phone, code string) (result bool, err error) { |
|
|
return
|
|
|
}
|
|
|
|
|
|
//验证手机号码(修改手机号码、重置密码的前一步)
|
|
|
// 验证手机号码(修改手机号码、重置密码的前一步)
|
|
|
func AuthCheckSmsCode(header *protocol.RequestHeader, request *protocol.AuthCheckSmsCodeRequest) (rsp *protocol.AuthCheckSmsCodeResponse, err error) {
|
|
|
var ()
|
|
|
if _, err = CheckSmsCode(request.Phone, request.Captcha); err != nil {
|
...
|
...
|
@@ -248,7 +249,7 @@ func AuthCheckSmsCode(header *protocol.RequestHeader, request *protocol.AuthChec |
|
|
return
|
|
|
}
|
|
|
|
|
|
//注销登录
|
|
|
// 注销登录
|
|
|
func Revoke(header *protocol.RequestHeader, request *protocol.RevokeRequest) (rsp *protocol.RevokeResponse, err error) {
|
|
|
//auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(header.UserId))
|
|
|
//rsp = &protocol.RevokeResponse{}
|
...
|
...
|
@@ -263,7 +264,7 @@ func Revoke(header *protocol.RequestHeader, request *protocol.RevokeRequest) (rs |
|
|
return
|
|
|
}
|
|
|
|
|
|
//注销登录
|
|
|
// 注销登录
|
|
|
func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol.RevokeResponse, err error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -300,7 +301,8 @@ func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol. |
|
|
return
|
|
|
}
|
|
|
|
|
|
func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) {
|
|
|
// 企业平台-多公司登录
|
|
|
func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
imInfo *domain.ImInfo
|
...
|
...
|
@@ -320,14 +322,14 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 通过短信验证码登录的游客,注册一个账号到配置的公司去(ios审核使用)
|
|
|
if request.GrantType == protocol.LoginBySmsCode {
|
|
|
e := loginSvr.RegistryGuest(request.Phone)
|
|
|
if e != nil {
|
|
|
log.Error(e)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// loginSvr 初始化
|
|
|
loginSvr.Init(request.Phone)
|
|
|
if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 {
|
|
|
err = protocol.NewErrWithMessage(10001)
|
...
|
...
|
@@ -365,22 +367,21 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom |
|
|
break
|
|
|
}
|
|
|
|
|
|
//获取统计信息
|
|
|
// 获取统计信息(合伙人/高管)
|
|
|
rsp.Partner, _ = loginSvr.PartnerStaticInfo()
|
|
|
rsp.Manager, _ = loginSvr.ManagerStaticInfo()
|
|
|
//没有有效人的时候
|
|
|
if !loginSvr.AvailableCompany {
|
|
|
if !loginSvr.HasAvailableCompany {
|
|
|
err = protocol.NewErrWithMessage(10008) //账号禁用
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 初始化网易IM信息
|
|
|
var nickName string
|
|
|
if len(loginSvr.Users) > 0 {
|
|
|
nickName = loginSvr.Users[0].Name
|
|
|
} else if len(loginSvr.PartnerInfo) > 0 {
|
|
|
nickName = loginSvr.PartnerInfo[0].PartnerName
|
|
|
}
|
|
|
//初始化im信息
|
|
|
if imInfo, err = InitOrUpdateUserIMInfo(int64(phoneId), nickName, transactionContext); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
...
|
...
|
@@ -395,12 +396,13 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom |
|
|
//添加手机对应的凭证
|
|
|
userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials)
|
|
|
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
v = map[string]interface{}{"center": rsp}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest) (rsp *protocolx.CompanysResponse, err error) {
|
|
|
// 企业平台-多公司登录 - 通过凭证
|
|
|
func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protocolx.CompanysRequest) (rsp *protocolx.CompanysResponse, err error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
loginSvr = domain_service.NewPgLoginService(transactionContext)
|
...
|
...
|
@@ -424,11 +426,12 @@ func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest |
|
|
err = protocol.NewErrWithMessage(4140, err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// loginSvr 初始化
|
|
|
loginSvr.Init(claim.Phone)
|
|
|
rsp.Partner, _ = loginSvr.PartnerStaticInfo()
|
|
|
rsp.Manager, _ = loginSvr.ManagerStaticInfo()
|
|
|
//没有有效人的时候
|
|
|
if !loginSvr.AvailableCompany {
|
|
|
if !loginSvr.HasAvailableCompany {
|
|
|
err = protocol.NewErrWithMessage(4140, err) //账号禁用
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -437,6 +440,7 @@ func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest |
|
|
return
|
|
|
}
|
|
|
|
|
|
// 登录
|
|
|
func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (rsp *protocol.LoginResponse, err error) {
|
|
|
var (
|
|
|
claim *utils.UserTokenClaims
|
...
|
...
|
@@ -477,12 +481,12 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) ( |
|
|
return
|
|
|
}
|
|
|
}
|
|
|
//验证公司模块权限
|
|
|
if _, adminUsers, e := UsersRepository.Find(map[string]interface{}{"inCompanyIds": []int64{int64(request.Cid)}, "adminType": 2, "deleteAtIsNull": true}); e == nil {
|
|
|
if len(adminUsers) > 0 {
|
|
|
au := adminUsers[0]
|
|
|
if code, e := adminApiGateway.UserAuth(au.Id, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 {
|
|
|
log.Debug("【合伙人检查权限】", claim.Phone, "【公司】", request.Cid, au.Id, code, e.Error())
|
|
|
//合伙人 需要验证对应公司模块权限(查询该公司的主管理员是否有权限)
|
|
|
if _, admins, e := UsersRepository.Find(map[string]interface{}{"inCompanyIds": []int64{int64(request.Cid)}, "adminType": 2, "deleteAtIsNull": true}); e == nil {
|
|
|
if len(admins) > 0 {
|
|
|
admin := admins[0]
|
|
|
if code, e := adminApiGateway.UserAuth(admin.Id, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 {
|
|
|
log.Debug("【合伙人检查权限】", claim.Phone, "【公司】", request.Cid, admin.Id, code, e.Error())
|
|
|
err = protocol.NewErrWithMessage(10008, err) // 抱歉,企业管理员未帮您开通权限
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -497,7 +501,7 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) ( |
|
|
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())
|
...
|
...
|
@@ -514,7 +518,8 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) ( |
|
|
err = protocol.NewErrWithMessage(10001, err) //账号不存在
|
|
|
return
|
|
|
}
|
|
|
//根据simnum + cid
|
|
|
|
|
|
// 生成授权码
|
|
|
userClaims := utils.UserTokenClaims{
|
|
|
UserId: userId,
|
|
|
CompanyId: int64(request.Cid),
|
...
|
...
|
|