正在显示
10 个修改的文件
包含
162 行增加
和
23 行删除
pkg/application/auth/command/user_sign_up.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type UserSignUpCommand struct { | ||
12 | + // 企业名称 | ||
13 | + Name string `cname:"用户姓名" json:"name" valid:"Required"` | ||
14 | + // 手机号码 | ||
15 | + Phone string `cname:"手机号码" json:"phone" valid:"Required"` | ||
16 | + // 密码 | ||
17 | + Password string `cname:"密码" json:"password" valid:"Required"` | ||
18 | + // 密码 | ||
19 | + SmsCode string `cname:"短信验证码" json:"smsCode" valid:"Required"` | ||
20 | +} | ||
21 | + | ||
22 | +func (companySignUpCommand *UserSignUpCommand) Valid(validation *validation.Validation) { | ||
23 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
24 | +} | ||
25 | + | ||
26 | +func (companySignUpCommand *UserSignUpCommand) ValidateCommand() error { | ||
27 | + valid := validation.Validation{} | ||
28 | + b, err := valid.Valid(companySignUpCommand) | ||
29 | + if err != nil { | ||
30 | + return err | ||
31 | + } | ||
32 | + if !b { | ||
33 | + elem := reflect.TypeOf(companySignUpCommand).Elem() | ||
34 | + for _, validErr := range valid.Errors { | ||
35 | + field, isExist := elem.FieldByName(validErr.Field) | ||
36 | + if isExist { | ||
37 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
38 | + } else { | ||
39 | + return fmt.Errorf(validErr.Message) | ||
40 | + } | ||
41 | + } | ||
42 | + } | ||
43 | + return nil | ||
44 | +} |
@@ -427,6 +427,27 @@ func (svr AuthService) CompanySignUp(companySignUpCommand *command.CompanySignUp | @@ -427,6 +427,27 @@ func (svr AuthService) CompanySignUp(companySignUpCommand *command.CompanySignUp | ||
427 | return companySignUpCommand, err | 427 | return companySignUpCommand, err |
428 | } | 428 | } |
429 | 429 | ||
430 | +func (svr AuthService) UserSignUp(signUpCommand *command.UserSignUpCommand) (interface{}, error) { | ||
431 | + if err := signUpCommand.ValidateCommand(); err != nil { | ||
432 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
433 | + } | ||
434 | + smsServeGateway := sms_serve.NewHttplibHttplibSmsServe() | ||
435 | + err := smsServeGateway.CheckSmsCode(signUpCommand.Phone, signUpCommand.SmsCode) | ||
436 | + if err != nil { | ||
437 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
438 | + } | ||
439 | + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{}) | ||
440 | + _, err = creationUserGateway.AuthUserSignUp(allied_creation_user.ReqAuthUserSignUp{ | ||
441 | + Name: signUpCommand.Name, | ||
442 | + Phone: signUpCommand.Phone, | ||
443 | + Password: signUpCommand.Password, | ||
444 | + }) | ||
445 | + if err != nil { | ||
446 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
447 | + } | ||
448 | + return signUpCommand, err | ||
449 | +} | ||
450 | + | ||
430 | // ResetPassword 重置密码(找回密码) | 451 | // ResetPassword 重置密码(找回密码) |
431 | func (svr AuthService) ResetPassword(resetPasswordCommand *command.ResetPasswordCommand) (interface{}, error) { | 452 | func (svr AuthService) ResetPassword(resetPasswordCommand *command.ResetPasswordCommand) (interface{}, error) { |
432 | if err := resetPasswordCommand.ValidateCommand(); err != nil { | 453 | if err := resetPasswordCommand.ValidateCommand(); err != nil { |
@@ -496,15 +517,9 @@ func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error | @@ -496,15 +517,9 @@ func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error | ||
496 | if err != nil { | 517 | if err != nil { |
497 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 518 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
498 | } | 519 | } |
499 | - resultOrg, err := creationUserGateway.OrgGet(allied_creation_user.ReqOrgGet{ | ||
500 | - OrgId: int(operator.OrgId), | ||
501 | - }) | ||
502 | - if err != nil { | ||
503 | - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
504 | - } | 520 | + |
505 | var user = map[string]interface{}{ | 521 | var user = map[string]interface{}{ |
506 | "userId": resultUser.UserBaseId, | 522 | "userId": resultUser.UserBaseId, |
507 | - //"publicUserId":fmt.Sprintf("%v",resultUser.UserBaseId), | ||
508 | "userType": resultUser.UserType, | 523 | "userType": resultUser.UserType, |
509 | "userCode": resultUser.UserCode, | 524 | "userCode": resultUser.UserCode, |
510 | "userInfo": map[string]interface{}{ | 525 | "userInfo": map[string]interface{}{ |
@@ -515,22 +530,31 @@ func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error | @@ -515,22 +530,31 @@ func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error | ||
515 | "email": resultUser.UserInfo.Email, | 530 | "email": resultUser.UserInfo.Email, |
516 | }, | 531 | }, |
517 | "department": resultUser.Department, | 532 | "department": resultUser.Department, |
518 | - "company": map[string]interface{}{ | ||
519 | - "companyId": resultUser.Company.CompanyId, | ||
520 | - "companyName": resultUser.Company.CompanyName, | ||
521 | - "logo": resultUser.Company.Logo, | ||
522 | - "systemName": resultUser.Company.SystemName, | ||
523 | - "address": resultUser.Company.Address, | ||
524 | - }, | ||
525 | "im": resultUser.IM, | 533 | "im": resultUser.IM, |
526 | - "org": map[string]interface{}{ | 534 | + "favoriteMenus": resultUser.FavoriteMenus, |
535 | + } | ||
536 | + if operator.OrgId > 0 { | ||
537 | + resultOrg, err := creationUserGateway.OrgGet(allied_creation_user.ReqOrgGet{ | ||
538 | + OrgId: int(operator.OrgId), | ||
539 | + }) | ||
540 | + if err != nil { | ||
541 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
542 | + } | ||
543 | + user["org"] = map[string]interface{}{ | ||
527 | "orgId": resultOrg.OrgID, | 544 | "orgId": resultOrg.OrgID, |
528 | "orgName": resultOrg.OrgName, | 545 | "orgName": resultOrg.OrgName, |
529 | "orgCode": resultOrg.OrgCode, | 546 | "orgCode": resultOrg.OrgCode, |
530 | "companyId": resultOrg.CompanyID, | 547 | "companyId": resultOrg.CompanyID, |
531 | - }, | ||
532 | - //"currentLoginOrg": resultUser.Org, | ||
533 | - "favoriteMenus": resultUser.FavoriteMenus, | 548 | + } |
549 | + } | ||
550 | + if resultUser.Company != nil { | ||
551 | + user["company"] = map[string]interface{}{ | ||
552 | + "companyId": resultUser.Company.CompanyId, | ||
553 | + "companyName": resultUser.Company.CompanyName, | ||
554 | + "logo": resultUser.Company.Logo, | ||
555 | + "systemName": resultUser.Company.SystemName, | ||
556 | + "address": resultUser.Company.Address, | ||
557 | + } | ||
534 | } | 558 | } |
535 | return user, nil | 559 | return user, nil |
536 | } | 560 | } |
@@ -658,6 +682,7 @@ loopUser1: | @@ -658,6 +682,7 @@ loopUser1: | ||
658 | if err != nil { | 682 | if err != nil { |
659 | return nil, application.ThrowError(application.TRANSACTION_ERROR, "账号不存在") | 683 | return nil, application.ThrowError(application.TRANSACTION_ERROR, "账号不存在") |
660 | } | 684 | } |
685 | + loginToken.UserId = int64(userBase.UserID) | ||
661 | loginToken.UserBaseId = int64(userBase.UserBaseID) | 686 | loginToken.UserBaseId = int64(userBase.UserBaseID) |
662 | if userBase.UserBaseID > 0 { | 687 | if userBase.UserBaseID > 0 { |
663 | cooperationUsers, _ := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{ | 688 | cooperationUsers, _ := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{ |
@@ -139,6 +139,9 @@ func extQuires(operator domain.Operator) []*allied_creation_cooperation.SearchCo | @@ -139,6 +139,9 @@ func extQuires(operator domain.Operator) []*allied_creation_cooperation.SearchCo | ||
139 | } | 139 | } |
140 | for i := range users.Users { | 140 | for i := range users.Users { |
141 | u := users.Users[i] | 141 | u := users.Users[i] |
142 | + if u.UserType == domain.UserTypeVisitor { | ||
143 | + continue | ||
144 | + } | ||
142 | q := &allied_creation_cooperation.SearchCooperationProjectExtQuery{ | 145 | q := &allied_creation_cooperation.SearchCooperationProjectExtQuery{ |
143 | ExtCompanyId: int64(u.Company.CompanyId), | 146 | ExtCompanyId: int64(u.Company.CompanyId), |
144 | //ExtOrgId: int64(u.Org.OrgId), | 147 | //ExtOrgId: int64(u.Org.OrgId), |
@@ -41,7 +41,7 @@ func (srv PersonStatisticsService) IndexStatistics(cmd *command.IndexStatisticsC | @@ -41,7 +41,7 @@ func (srv PersonStatisticsService) IndexStatistics(cmd *command.IndexStatisticsC | ||
41 | users, err := gatewayUser.UserSearch(allied_creation_user.ReqUserSearch{ | 41 | users, err := gatewayUser.UserSearch(allied_creation_user.ReqUserSearch{ |
42 | Limit: 1, | 42 | Limit: 1, |
43 | Offset: 0, | 43 | Offset: 0, |
44 | - //UserType: domain.UserTypeCooperation, | 44 | + UserType: domain.UserTypeCooperation | domain.UserTypeEmployee, |
45 | UserBaseId: cmd.Operator.UserBaseId, | 45 | UserBaseId: cmd.Operator.UserBaseId, |
46 | }) | 46 | }) |
47 | if err != nil { | 47 | if err != nil { |
@@ -114,6 +114,9 @@ func (srv PersonStatisticsService) CompanyStatistics(cmd *command.CooperationPer | @@ -114,6 +114,9 @@ func (srv PersonStatisticsService) CompanyStatistics(cmd *command.CooperationPer | ||
114 | var companyList []int | 114 | var companyList []int |
115 | for i := range users.Users { | 115 | for i := range users.Users { |
116 | user := users.Users[i] | 116 | user := users.Users[i] |
117 | + if user.Org == nil || user.Org.OrgId == 0 { | ||
118 | + continue | ||
119 | + } | ||
117 | companyList = append(companyList, user.Org.OrgId) | 120 | companyList = append(companyList, user.Org.OrgId) |
118 | } | 121 | } |
119 | 122 | ||
@@ -145,13 +148,16 @@ func (srv PersonStatisticsService) CompanyStatistics(cmd *command.CooperationPer | @@ -145,13 +148,16 @@ func (srv PersonStatisticsService) CompanyStatistics(cmd *command.CooperationPer | ||
145 | if err := json.UnmarshalFromString(json.MarshalToString(result), &cooperationCompanyStatisticsResponses); err != nil { | 148 | if err := json.UnmarshalFromString(json.MarshalToString(result), &cooperationCompanyStatisticsResponses); err != nil { |
146 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 149 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
147 | } | 150 | } |
148 | - if len(cooperationCompanyStatisticsResponses) != len(users.Users) { | ||
149 | - return nil, application.ThrowError(application.BUSINESS_ERROR, "数据不匹配") | ||
150 | - } | 151 | + //if len(cooperationCompanyStatisticsResponses) != len(users.Users) { |
152 | + // return nil, application.ThrowError(application.BUSINESS_ERROR, "数据不匹配") | ||
153 | + //} | ||
151 | 154 | ||
152 | var values = make([]interface{}, 0) | 155 | var values = make([]interface{}, 0) |
153 | for i := range users.Users { | 156 | for i := range users.Users { |
154 | user := users.Users[i] | 157 | user := users.Users[i] |
158 | + if user.Company == nil { | ||
159 | + continue | ||
160 | + } | ||
155 | cooperationCompanyStatisticsResponses[i].Company = domain.Company{ | 161 | cooperationCompanyStatisticsResponses[i].Company = domain.Company{ |
156 | CompanyID: user.Org.OrgId, | 162 | CompanyID: user.Org.OrgId, |
157 | CompanyName: user.Org.OrgName, | 163 | CompanyName: user.Org.OrgName, |
@@ -593,7 +593,7 @@ func (usersService *UsersService) SelectorCooperationProjectUsers(q *query.Coope | @@ -593,7 +593,7 @@ func (usersService *UsersService) SelectorCooperationProjectUsers(q *query.Coope | ||
593 | for i := range resultApplication.Grid.List { | 593 | for i := range resultApplication.Grid.List { |
594 | item := resultApplication.Grid.List[i] | 594 | item := resultApplication.Grid.List[i] |
595 | user := map[string]interface{}{ | 595 | user := map[string]interface{}{ |
596 | - "userId": item.CooperationApplicationApplicant.UserID, | 596 | + "userId": fmt.Sprintf("%v", item.CooperationApplicationApplicant.UserID), |
597 | "userCode": item.CooperationApplicationApplicant.UserInfo.UserCode, | 597 | "userCode": item.CooperationApplicationApplicant.UserInfo.UserCode, |
598 | "userInfo": map[string]interface{}{ | 598 | "userInfo": map[string]interface{}{ |
599 | "userName": item.CooperationApplicationApplicant.UserInfo.UserName, | 599 | "userName": item.CooperationApplicationApplicant.UserInfo.UserName, |
@@ -39,6 +39,37 @@ func (gateway HttplibAlliedCreationUser) AuthCompanySignUp(param ReqAuthCompanyS | @@ -39,6 +39,37 @@ func (gateway HttplibAlliedCreationUser) AuthCompanySignUp(param ReqAuthCompanyS | ||
39 | return &data, err | 39 | return &data, err |
40 | } | 40 | } |
41 | 41 | ||
42 | +// AuthUserSignUp 用户注册 | ||
43 | +func (gateway HttplibAlliedCreationUser) AuthUserSignUp(param ReqAuthUserSignUp) (*DataAuthUserSignUp, error) { | ||
44 | + url := gateway.baseUrL + "/auth/user-sign-up" | ||
45 | + method := "POST" | ||
46 | + req := gateway.CreateRequest(url, method) | ||
47 | + log.Logger.Debug("向用户模块请求数据:用户注册。", map[string]interface{}{ | ||
48 | + "api": method + ":" + url, | ||
49 | + "param": param, | ||
50 | + }) | ||
51 | + req, err := req.JSONBody(param) | ||
52 | + if err != nil { | ||
53 | + return nil, fmt.Errorf("请求用户注册失败:%w", err) | ||
54 | + } | ||
55 | + | ||
56 | + byteResult, err := req.Bytes() | ||
57 | + if err != nil { | ||
58 | + return nil, fmt.Errorf("获取用户注册失败:%w", err) | ||
59 | + } | ||
60 | + log.Logger.Debug("获取用户模块请求数据:用户注册。", map[string]interface{}{ | ||
61 | + "result": string(byteResult), | ||
62 | + }) | ||
63 | + var result service_gateway.GatewayResponse | ||
64 | + err = json.Unmarshal(byteResult, &result) | ||
65 | + if err != nil { | ||
66 | + return nil, fmt.Errorf("解析用户注册:%w", err) | ||
67 | + } | ||
68 | + var data DataAuthUserSignUp | ||
69 | + err = gateway.GetResponseData(result, &data) | ||
70 | + return &data, err | ||
71 | +} | ||
72 | + | ||
42 | //AuthChangePassword 修改密码 | 73 | //AuthChangePassword 修改密码 |
43 | func (gateway HttplibAlliedCreationUser) AuthChangePassword(param ReqAuthChangePassword) (*DataAuthChangePassword, error) { | 74 | func (gateway HttplibAlliedCreationUser) AuthChangePassword(param ReqAuthChangePassword) (*DataAuthChangePassword, error) { |
44 | url := gateway.baseUrL + "/auth/change-password" | 75 | url := gateway.baseUrL + "/auth/change-password" |
@@ -15,6 +15,21 @@ type ( | @@ -15,6 +15,21 @@ type ( | ||
15 | } | 15 | } |
16 | ) | 16 | ) |
17 | 17 | ||
18 | +//企业注册 | ||
19 | +type ( | ||
20 | + ReqAuthUserSignUp struct { | ||
21 | + // 企业名称 | ||
22 | + Name string `cname:"用户姓名" json:"name" valid:"Required"` | ||
23 | + // 手机号码 | ||
24 | + Phone string `cname:"手机号码" json:"phone" valid:"Required"` | ||
25 | + // 密码 | ||
26 | + Password string `cname:"密码" json:"password" valid:"Required"` | ||
27 | + } | ||
28 | + | ||
29 | + DataAuthUserSignUp struct { | ||
30 | + } | ||
31 | +) | ||
32 | + | ||
18 | //修改密码 | 33 | //修改密码 |
19 | type ( | 34 | type ( |
20 | ReqAuthChangePassword struct { | 35 | ReqAuthChangePassword struct { |
@@ -99,6 +114,7 @@ type ( | @@ -99,6 +114,7 @@ type ( | ||
99 | Account string `cname:"账号" json:"account" valid:"Required"` | 114 | Account string `cname:"账号" json:"account" valid:"Required"` |
100 | } | 115 | } |
101 | DataAuthUserBase struct { | 116 | DataAuthUserBase struct { |
117 | + UserID int `json:"userId"` | ||
102 | UserBaseID int `json:"userBaseId"` | 118 | UserBaseID int `json:"userBaseId"` |
103 | UserInfo struct { | 119 | UserInfo struct { |
104 | UserName string `json:"userName"` | 120 | UserName string `json:"userName"` |
@@ -137,6 +137,18 @@ func (controller *AuthController) CompanySignUp() { | @@ -137,6 +137,18 @@ func (controller *AuthController) CompanySignUp() { | ||
137 | controller.Response(data, err) | 137 | controller.Response(data, err) |
138 | } | 138 | } |
139 | 139 | ||
140 | +func (controller *AuthController) UserSignUp() { | ||
141 | + authService := service.AuthService{} | ||
142 | + cmd := &command.UserSignUpCommand{} | ||
143 | + err := controller.Unmarshal(cmd) | ||
144 | + if err != nil { | ||
145 | + controller.Response(nil, err) | ||
146 | + return | ||
147 | + } | ||
148 | + data, err := authService.UserSignUp(cmd) | ||
149 | + controller.Response(data, err) | ||
150 | +} | ||
151 | + | ||
140 | func (controller *AuthController) ResetPassword() { | 152 | func (controller *AuthController) ResetPassword() { |
141 | authService := service.AuthService{} | 153 | authService := service.AuthService{} |
142 | userOrgCommand := &command.ResetPasswordCommand{} | 154 | userOrgCommand := &command.ResetPasswordCommand{} |
@@ -18,6 +18,7 @@ func init() { | @@ -18,6 +18,7 @@ func init() { | ||
18 | //web.Router("/v1/auth/access-token", &controllers.AuthController{}, "Post:GetAuthAccessToken") | 18 | //web.Router("/v1/auth/access-token", &controllers.AuthController{}, "Post:GetAuthAccessToken") |
19 | web.Router("/v1/auth/refresh-token", &controllers.AuthController{}, "Post:RefreshAuthAccessToken") | 19 | web.Router("/v1/auth/refresh-token", &controllers.AuthController{}, "Post:RefreshAuthAccessToken") |
20 | web.Router("/v1/auth/company-sign-up", &controllers.AuthController{}, "Post:CompanySignUp") //公司用户注册 | 20 | web.Router("/v1/auth/company-sign-up", &controllers.AuthController{}, "Post:CompanySignUp") //公司用户注册 |
21 | + web.Router("/v1/auth/user-sign-up", &controllers.AuthController{}, "Post:UserSignUp") | ||
21 | web.Router("/v1/auth/reset-password", &controllers.AuthController{}, "Post:ResetPassword") //公司重置密码 | 22 | web.Router("/v1/auth/reset-password", &controllers.AuthController{}, "Post:ResetPassword") //公司重置密码 |
22 | web.Router("/v1/auth/org-switch", &controllers.AuthController{}, "Post:OrgSwitch") | 23 | web.Router("/v1/auth/org-switch", &controllers.AuthController{}, "Post:OrgSwitch") |
23 | } | 24 | } |
-
请 注册 或 登录 后发表评论