|
|
package user
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/auth"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/userAuth"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
|
|
|
domain_service_i "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/service"
|
...
|
...
|
@@ -132,20 +134,82 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe |
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
UserAuthService = CreateUserAuthService(header.AdminType, transactionContext)
|
|
|
)
|
|
|
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
if err = UserAuthService.ChangeUserPhone(header.UserId, request.Phone, request.OldPhone); err != nil {
|
|
|
err = protocol.NewCustomMessage(1, err.Error())
|
|
|
return
|
|
|
}
|
|
|
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// ChangePhoneAllCompany 修改手机号,强制退出登录
|
|
|
func ChangePhoneAllCompany(header *protocol.RequestHeader, request *protocol.ChangePhoneAllCompanyRequest) (rsp *protocol.ChangePhoneAllCompanyResponse, err error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
UserAuthService = CreateUserAuthService(header.AdminType, transactionContext)
|
|
|
)
|
|
|
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
if request.Module == "employee" && request.Action == "changePhoneAllCompany" {
|
|
|
var oldPhone string
|
|
|
var newPhone string
|
|
|
var data map[string]interface{}
|
|
|
|
|
|
err := json.Unmarshal([]byte(request.Data), &data)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
if value, ok := data["old_phone"]; ok {
|
|
|
oldPhone = value.(string)
|
|
|
}
|
|
|
if value, ok := data["new_phone"]; ok {
|
|
|
newPhone = value.(string)
|
|
|
}
|
|
|
|
|
|
if err = UserAuthService.ChangeUserPhone(header.UserId, newPhone, oldPhone); err != nil {
|
|
|
err = protocol.NewCustomMessage(1, err.Error())
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
//注销凭证
|
|
|
errRemoveAuth := userAuth.NewRedisUserCredential(oldPhone).RemoveAuth()
|
|
|
if errRemoveAuth != nil {
|
|
|
log.Error(err)
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
//注销token
|
|
|
id, _ := strconv.Atoi(oldPhone)
|
|
|
uAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(int64(id)))
|
|
|
if !uAuth.Exist() {
|
|
|
return nil, nil
|
|
|
}
|
|
|
if err = uAuth.RemoveAuth(); err != nil {
|
|
|
log.Error(err)
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
//重置密码
|
|
|
func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) {
|
|
|
var (
|
...
|
...
|
|