作者 yangfu

用户注册修改

package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UserSignUpCommand struct {
// 企业名称
Name string `cname:"用户姓名" json:"name" valid:"Required"`
// 手机号码
Phone string `cname:"手机号码" json:"phone" valid:"Required"`
// 密码
Password string `cname:"密码" json:"password" valid:"Required"`
// 密码
SmsCode string `cname:"短信验证码" json:"smsCode" valid:"Required"`
}
func (companySignUpCommand *UserSignUpCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (companySignUpCommand *UserSignUpCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(companySignUpCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(companySignUpCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
... ... @@ -427,6 +427,27 @@ func (svr AuthService) CompanySignUp(companySignUpCommand *command.CompanySignUp
return companySignUpCommand, err
}
func (svr AuthService) UserSignUp(signUpCommand *command.UserSignUpCommand) (interface{}, error) {
if err := signUpCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
smsServeGateway := sms_serve.NewHttplibHttplibSmsServe()
err := smsServeGateway.CheckSmsCode(signUpCommand.Phone, signUpCommand.SmsCode)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
_, err = creationUserGateway.AuthUserSignUp(allied_creation_user.ReqAuthUserSignUp{
Name: signUpCommand.Name,
Phone: signUpCommand.Phone,
Password: signUpCommand.Password,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return signUpCommand, err
}
// ResetPassword 重置密码(找回密码)
func (svr AuthService) ResetPassword(resetPasswordCommand *command.ResetPasswordCommand) (interface{}, error) {
if err := resetPasswordCommand.ValidateCommand(); err != nil {
... ... @@ -496,15 +517,9 @@ func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
resultOrg, err := creationUserGateway.OrgGet(allied_creation_user.ReqOrgGet{
OrgId: int(operator.OrgId),
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var user = map[string]interface{}{
"userId": resultUser.UserBaseId,
//"publicUserId":fmt.Sprintf("%v",resultUser.UserBaseId),
"userId": resultUser.UserBaseId,
"userType": resultUser.UserType,
"userCode": resultUser.UserCode,
"userInfo": map[string]interface{}{
... ... @@ -514,23 +529,32 @@ func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error
"userCode": resultUser.UserInfo.UserCode,
"email": resultUser.UserInfo.Email,
},
"department": resultUser.Department,
"company": map[string]interface{}{
"department": resultUser.Department,
"im": resultUser.IM,
"favoriteMenus": resultUser.FavoriteMenus,
}
if operator.OrgId > 0 {
resultOrg, err := creationUserGateway.OrgGet(allied_creation_user.ReqOrgGet{
OrgId: int(operator.OrgId),
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
user["org"] = map[string]interface{}{
"orgId": resultOrg.OrgID,
"orgName": resultOrg.OrgName,
"orgCode": resultOrg.OrgCode,
"companyId": resultOrg.CompanyID,
}
}
if resultUser.Company != nil {
user["company"] = map[string]interface{}{
"companyId": resultUser.Company.CompanyId,
"companyName": resultUser.Company.CompanyName,
"logo": resultUser.Company.Logo,
"systemName": resultUser.Company.SystemName,
"address": resultUser.Company.Address,
},
"im": resultUser.IM,
"org": map[string]interface{}{
"orgId": resultOrg.OrgID,
"orgName": resultOrg.OrgName,
"orgCode": resultOrg.OrgCode,
"companyId": resultOrg.CompanyID,
},
//"currentLoginOrg": resultUser.Org,
"favoriteMenus": resultUser.FavoriteMenus,
}
}
return user, nil
}
... ... @@ -658,6 +682,7 @@ loopUser1:
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "账号不存在")
}
loginToken.UserId = int64(userBase.UserID)
loginToken.UserBaseId = int64(userBase.UserBaseID)
if userBase.UserBaseID > 0 {
cooperationUsers, _ := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
... ...
... ... @@ -139,6 +139,9 @@ func extQuires(operator domain.Operator) []*allied_creation_cooperation.SearchCo
}
for i := range users.Users {
u := users.Users[i]
if u.UserType == domain.UserTypeVisitor {
continue
}
q := &allied_creation_cooperation.SearchCooperationProjectExtQuery{
ExtCompanyId: int64(u.Company.CompanyId),
//ExtOrgId: int64(u.Org.OrgId),
... ...
... ... @@ -39,9 +39,9 @@ func (srv PersonStatisticsService) IndexStatistics(cmd *command.IndexStatisticsC
gatewayUser := allied_creation_user.NewHttplibAlliedCreationUser(
cmd.Operator)
users, err := gatewayUser.UserSearch(allied_creation_user.ReqUserSearch{
Limit: 1,
Offset: 0,
//UserType: domain.UserTypeCooperation,
Limit: 1,
Offset: 0,
UserType: domain.UserTypeCooperation | domain.UserTypeEmployee,
UserBaseId: cmd.Operator.UserBaseId,
})
if err != nil {
... ... @@ -114,6 +114,9 @@ func (srv PersonStatisticsService) CompanyStatistics(cmd *command.CooperationPer
var companyList []int
for i := range users.Users {
user := users.Users[i]
if user.Org == nil || user.Org.OrgId == 0 {
continue
}
companyList = append(companyList, user.Org.OrgId)
}
... ... @@ -145,13 +148,16 @@ func (srv PersonStatisticsService) CompanyStatistics(cmd *command.CooperationPer
if err := json.UnmarshalFromString(json.MarshalToString(result), &cooperationCompanyStatisticsResponses); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if len(cooperationCompanyStatisticsResponses) != len(users.Users) {
return nil, application.ThrowError(application.BUSINESS_ERROR, "数据不匹配")
}
//if len(cooperationCompanyStatisticsResponses) != len(users.Users) {
// return nil, application.ThrowError(application.BUSINESS_ERROR, "数据不匹配")
//}
var values = make([]interface{}, 0)
for i := range users.Users {
user := users.Users[i]
if user.Company == nil {
continue
}
cooperationCompanyStatisticsResponses[i].Company = domain.Company{
CompanyID: user.Org.OrgId,
CompanyName: user.Org.OrgName,
... ...
... ... @@ -593,7 +593,7 @@ func (usersService *UsersService) SelectorCooperationProjectUsers(q *query.Coope
for i := range resultApplication.Grid.List {
item := resultApplication.Grid.List[i]
user := map[string]interface{}{
"userId": item.CooperationApplicationApplicant.UserID,
"userId": fmt.Sprintf("%v", item.CooperationApplicationApplicant.UserID),
"userCode": item.CooperationApplicationApplicant.UserInfo.UserCode,
"userInfo": map[string]interface{}{
"userName": item.CooperationApplicationApplicant.UserInfo.UserName,
... ...
... ... @@ -5,6 +5,7 @@ package domain
const (
UserTypeEmployee = 1
UserTypeCooperation = 2
UserTypeVisitor = 4
UserTypeCompanyAdmin = 1024
)
... ...
... ... @@ -39,6 +39,37 @@ func (gateway HttplibAlliedCreationUser) AuthCompanySignUp(param ReqAuthCompanyS
return &data, err
}
// AuthUserSignUp 用户注册
func (gateway HttplibAlliedCreationUser) AuthUserSignUp(param ReqAuthUserSignUp) (*DataAuthUserSignUp, error) {
url := gateway.baseUrL + "/auth/user-sign-up"
method := "POST"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:用户注册。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求用户注册失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取用户注册失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:用户注册。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析用户注册:%w", err)
}
var data DataAuthUserSignUp
err = gateway.GetResponseData(result, &data)
return &data, err
}
//AuthChangePassword 修改密码
func (gateway HttplibAlliedCreationUser) AuthChangePassword(param ReqAuthChangePassword) (*DataAuthChangePassword, error) {
url := gateway.baseUrL + "/auth/change-password"
... ...
... ... @@ -15,6 +15,21 @@ type (
}
)
//企业注册
type (
ReqAuthUserSignUp struct {
// 企业名称
Name string `cname:"用户姓名" json:"name" valid:"Required"`
// 手机号码
Phone string `cname:"手机号码" json:"phone" valid:"Required"`
// 密码
Password string `cname:"密码" json:"password" valid:"Required"`
}
DataAuthUserSignUp struct {
}
)
//修改密码
type (
ReqAuthChangePassword struct {
... ... @@ -99,6 +114,7 @@ type (
Account string `cname:"账号" json:"account" valid:"Required"`
}
DataAuthUserBase struct {
UserID int `json:"userId"`
UserBaseID int `json:"userBaseId"`
UserInfo struct {
UserName string `json:"userName"`
... ...
... ... @@ -137,6 +137,18 @@ func (controller *AuthController) CompanySignUp() {
controller.Response(data, err)
}
func (controller *AuthController) UserSignUp() {
authService := service.AuthService{}
cmd := &command.UserSignUpCommand{}
err := controller.Unmarshal(cmd)
if err != nil {
controller.Response(nil, err)
return
}
data, err := authService.UserSignUp(cmd)
controller.Response(data, err)
}
func (controller *AuthController) ResetPassword() {
authService := service.AuthService{}
userOrgCommand := &command.ResetPasswordCommand{}
... ...
... ... @@ -18,6 +18,7 @@ func init() {
//web.Router("/v1/auth/access-token", &controllers.AuthController{}, "Post:GetAuthAccessToken")
web.Router("/v1/auth/refresh-token", &controllers.AuthController{}, "Post:RefreshAuthAccessToken")
web.Router("/v1/auth/company-sign-up", &controllers.AuthController{}, "Post:CompanySignUp") //公司用户注册
web.Router("/v1/auth/reset-password", &controllers.AuthController{}, "Post:ResetPassword") //公司重置密码
web.Router("/v1/auth/user-sign-up", &controllers.AuthController{}, "Post:UserSignUp")
web.Router("/v1/auth/reset-password", &controllers.AuthController{}, "Post:ResetPassword") //公司重置密码
web.Router("/v1/auth/org-switch", &controllers.AuthController{}, "Post:OrgSwitch")
}
... ...