...
|
...
|
@@ -6,8 +6,6 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/auth/query"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
|
|
|
"math/rand"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -109,8 +107,8 @@ func (authService *AuthService) Login(loginQuery *query.LoginQuery) (interface{} |
|
|
)
|
|
|
UserAuthRepository, _ := factory.CreateUserAuthRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
UserRepository, _ := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
switch loginQuery.GrantType {
|
|
|
case "signInPassword":
|
|
|
switch domain.LoginType(loginQuery.GrantType) {
|
|
|
case domain.SignInPassword:
|
|
|
if len(loginQuery.Password) == 0 {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "密码不能为空!")
|
|
|
}
|
...
|
...
|
@@ -121,18 +119,20 @@ func (authService *AuthService) Login(loginQuery *query.LoginQuery) (interface{} |
|
|
if !strings.EqualFold(userAuth.PhoneAuth.Password, loginQuery.Password) {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "密码有误!")
|
|
|
}
|
|
|
case "signInCaptcha":
|
|
|
case "signInCredentials":
|
|
|
case domain.SignInCaptcha:
|
|
|
case domain.SignInCredentials:
|
|
|
default:
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "undefined grantType:"+loginQuery.GrantType)
|
|
|
}
|
|
|
_, users, err = UserRepository.Find(map[string]interface{}{"inUserIds": userAuth.Users, "status": domain.StatusEnable})
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
cred := domain.NewCredentialAuth(loginQuery.DeviceType, loginQuery.Credentials)
|
|
|
userAuth.BindCredentialAuth(cred)
|
|
|
if _, err = UserAuthRepository.Save(userAuth); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
credentials := "cred:" + strconv.Itoa(rand.Int())
|
|
|
rspMapData["credentials"] = credentials
|
|
|
|
|
|
rspMapData["credentials"] = cred.Credential
|
|
|
CompanyRepository, _ := factory.CreateCompanyRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
for i := range users {
|
|
|
company, _ := CompanyRepository.FindOne(map[string]interface{}{"companyId": users[i].CompanyId, "status": domain.StatusEnable})
|
...
|
...
|
@@ -145,7 +145,12 @@ func (authService *AuthService) Login(loginQuery *query.LoginQuery) (interface{} |
|
|
}
|
|
|
userCompanies = append(userCompanies, item)
|
|
|
}
|
|
|
return map[string]interface{}{"userCompanies": userCompanies, "credentials": credentials}, nil
|
|
|
rspMapData["userCompanies"] = userCompanies
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return rspMapData, nil
|
|
|
}
|
|
|
|
|
|
// 用户按公司登录
|
...
|
...
|
@@ -164,8 +169,9 @@ func (authService *AuthService) LoginByCompany(loginByCompanyCommand *command.Lo |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
//todo:valid/refresh credentials
|
|
|
if len(loginByCompanyCommand.Credentials) == 0 {
|
|
|
UserAuthRepository, _ := factory.CreateUserAuthRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
userAuth, _ := UserAuthRepository.FindOne(map[string]interface{}{"credential": loginByCompanyCommand.Credentials})
|
|
|
if userAuth == nil || !userAuth.CheckCredentialAuth(loginByCompanyCommand.DeviceType, loginByCompanyCommand.Credentials) {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "credentials expire")
|
|
|
}
|
|
|
|
...
|
...
|
@@ -180,10 +186,11 @@ func (authService *AuthService) LoginByCompany(loginByCompanyCommand *command.Lo |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
authCode := domain.SignToken(user.UserId, company.CompanyId)
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
authCode := domain.SignToken(user.UserId, company.CompanyId)
|
|
|
return map[string]interface{}{"user": user, "company": company, "authCode": authCode}, nil
|
|
|
}
|
|
|
|
...
|
...
|
|