Merge branch 'feature_sign_up' into test
正在显示
10 个修改的文件
包含
167 行增加
和
28 行删除
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:"userName" 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 | +} |
@@ -413,6 +413,27 @@ func (svr AuthService) CompanySignUp(companySignUpCommand *command.CompanySignUp | @@ -413,6 +413,27 @@ func (svr AuthService) CompanySignUp(companySignUpCommand *command.CompanySignUp | ||
413 | return companySignUpCommand, err | 413 | return companySignUpCommand, err |
414 | } | 414 | } |
415 | 415 | ||
416 | +func (svr AuthService) UserSignUp(signUpCommand *command.UserSignUpCommand) (interface{}, error) { | ||
417 | + if err := signUpCommand.ValidateCommand(); err != nil { | ||
418 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
419 | + } | ||
420 | + smsServeGateway := sms_serve.NewHttplibHttplibSmsServe() | ||
421 | + err := smsServeGateway.CheckSmsCode(signUpCommand.Phone, signUpCommand.SmsCode) | ||
422 | + if err != nil { | ||
423 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
424 | + } | ||
425 | + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{}) | ||
426 | + _, err = creationUserGateway.AuthUserSignUp(allied_creation_user.ReqAuthUserSignUp{ | ||
427 | + Name: signUpCommand.Name, | ||
428 | + Phone: signUpCommand.Phone, | ||
429 | + Password: signUpCommand.Password, | ||
430 | + }) | ||
431 | + if err != nil { | ||
432 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
433 | + } | ||
434 | + return signUpCommand, err | ||
435 | +} | ||
436 | + | ||
416 | // ResetPassword 重置密码(找回密码) | 437 | // ResetPassword 重置密码(找回密码) |
417 | func (svr AuthService) ResetPassword(resetPasswordCommand *command.ResetPasswordCommand) (interface{}, error) { | 438 | func (svr AuthService) ResetPassword(resetPasswordCommand *command.ResetPasswordCommand) (interface{}, error) { |
418 | if err := resetPasswordCommand.ValidateCommand(); err != nil { | 439 | if err := resetPasswordCommand.ValidateCommand(); err != nil { |
@@ -482,15 +503,9 @@ func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error | @@ -482,15 +503,9 @@ func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error | ||
482 | if err != nil { | 503 | if err != nil { |
483 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 504 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
484 | } | 505 | } |
485 | - resultOrg, err := creationUserGateway.OrgGet(allied_creation_user.ReqOrgGet{ | ||
486 | - OrgId: int(operator.OrgId), | ||
487 | - }) | ||
488 | - if err != nil { | ||
489 | - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
490 | - } | 506 | + |
491 | var user = map[string]interface{}{ | 507 | var user = map[string]interface{}{ |
492 | - "userId": resultUser.UserBaseId, | ||
493 | - //"publicUserId":fmt.Sprintf("%v",resultUser.UserBaseId), | 508 | + "userId": resultUser.UserBaseId, |
494 | "userType": resultUser.UserType, | 509 | "userType": resultUser.UserType, |
495 | "userCode": resultUser.UserCode, | 510 | "userCode": resultUser.UserCode, |
496 | "userInfo": map[string]interface{}{ | 511 | "userInfo": map[string]interface{}{ |
@@ -500,23 +515,32 @@ func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error | @@ -500,23 +515,32 @@ func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error | ||
500 | "userCode": resultUser.UserInfo.UserCode, | 515 | "userCode": resultUser.UserInfo.UserCode, |
501 | "email": resultUser.UserInfo.Email, | 516 | "email": resultUser.UserInfo.Email, |
502 | }, | 517 | }, |
503 | - "department": resultUser.Department, | ||
504 | - "company": map[string]interface{}{ | 518 | + "department": resultUser.Department, |
519 | + "im": resultUser.IM, | ||
520 | + "favoriteMenus": resultUser.FavoriteMenus, | ||
521 | + } | ||
522 | + if operator.OrgId > 0 { | ||
523 | + resultOrg, err := creationUserGateway.OrgGet(allied_creation_user.ReqOrgGet{ | ||
524 | + OrgId: int(operator.OrgId), | ||
525 | + }) | ||
526 | + if err != nil { | ||
527 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
528 | + } | ||
529 | + user["org"] = map[string]interface{}{ | ||
530 | + "orgId": resultOrg.OrgID, | ||
531 | + "orgName": resultOrg.OrgName, | ||
532 | + "orgCode": resultOrg.OrgCode, | ||
533 | + "companyId": resultOrg.CompanyID, | ||
534 | + } | ||
535 | + } | ||
536 | + if resultUser.Company != nil { | ||
537 | + user["company"] = map[string]interface{}{ | ||
505 | "companyId": resultUser.Company.CompanyId, | 538 | "companyId": resultUser.Company.CompanyId, |
506 | "companyName": resultUser.Company.CompanyName, | 539 | "companyName": resultUser.Company.CompanyName, |
507 | "logo": resultUser.Company.Logo, | 540 | "logo": resultUser.Company.Logo, |
508 | "systemName": resultUser.Company.SystemName, | 541 | "systemName": resultUser.Company.SystemName, |
509 | "address": resultUser.Company.Address, | 542 | "address": resultUser.Company.Address, |
510 | - }, | ||
511 | - "im": resultUser.IM, | ||
512 | - "org": map[string]interface{}{ | ||
513 | - "orgId": resultOrg.OrgID, | ||
514 | - "orgName": resultOrg.OrgName, | ||
515 | - "orgCode": resultOrg.OrgCode, | ||
516 | - "companyId": resultOrg.CompanyID, | ||
517 | - }, | ||
518 | - //"currentLoginOrg": resultUser.Org, | ||
519 | - "favoriteMenus": resultUser.FavoriteMenus, | 543 | + } |
520 | } | 544 | } |
521 | return user, nil | 545 | return user, nil |
522 | } | 546 | } |
@@ -644,6 +668,7 @@ loopUser1: | @@ -644,6 +668,7 @@ loopUser1: | ||
644 | if err != nil { | 668 | if err != nil { |
645 | return nil, application.ThrowError(application.TRANSACTION_ERROR, "账号不存在") | 669 | return nil, application.ThrowError(application.TRANSACTION_ERROR, "账号不存在") |
646 | } | 670 | } |
671 | + loginToken.UserId = int64(userBase.UserID) | ||
647 | loginToken.UserBaseId = int64(userBase.UserBaseID) | 672 | loginToken.UserBaseId = int64(userBase.UserBaseID) |
648 | if userBase.UserBaseID > 0 { | 673 | if userBase.UserBaseID > 0 { |
649 | cooperationUsers, _ := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{ | 674 | cooperationUsers, _ := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{ |
@@ -140,6 +140,9 @@ func extQuires(operator domain.Operator) []*allied_creation_cooperation.SearchCo | @@ -140,6 +140,9 @@ func extQuires(operator domain.Operator) []*allied_creation_cooperation.SearchCo | ||
140 | } | 140 | } |
141 | for i := range users.Users { | 141 | for i := range users.Users { |
142 | u := users.Users[i] | 142 | u := users.Users[i] |
143 | + if u.UserType == domain.UserTypeVisitor { | ||
144 | + continue | ||
145 | + } | ||
143 | q := &allied_creation_cooperation.SearchCooperationProjectExtQuery{ | 146 | q := &allied_creation_cooperation.SearchCooperationProjectExtQuery{ |
144 | ExtCompanyId: int64(u.Company.CompanyId), | 147 | ExtCompanyId: int64(u.Company.CompanyId), |
145 | //ExtOrgId: int64(u.Org.OrgId), | 148 | //ExtOrgId: int64(u.Org.OrgId), |
@@ -39,9 +39,9 @@ func (srv PersonStatisticsService) IndexStatistics(cmd *command.IndexStatisticsC | @@ -39,9 +39,9 @@ func (srv PersonStatisticsService) IndexStatistics(cmd *command.IndexStatisticsC | ||
39 | gatewayUser := allied_creation_user.NewHttplibAlliedCreationUser( | 39 | gatewayUser := allied_creation_user.NewHttplibAlliedCreationUser( |
40 | cmd.Operator) | 40 | cmd.Operator) |
41 | users, err := gatewayUser.UserSearch(allied_creation_user.ReqUserSearch{ | 41 | users, err := gatewayUser.UserSearch(allied_creation_user.ReqUserSearch{ |
42 | - Limit: 1, | ||
43 | - Offset: 0, | ||
44 | - //UserType: domain.UserTypeCooperation, | 42 | + Limit: 1, |
43 | + Offset: 0, | ||
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, |
@@ -594,7 +594,7 @@ func (usersService *UsersService) SelectorCooperationProjectUsers(q *query.Coope | @@ -594,7 +594,7 @@ func (usersService *UsersService) SelectorCooperationProjectUsers(q *query.Coope | ||
594 | for i := range resultApplication.Grid.List { | 594 | for i := range resultApplication.Grid.List { |
595 | item := resultApplication.Grid.List[i] | 595 | item := resultApplication.Grid.List[i] |
596 | user := map[string]interface{}{ | 596 | user := map[string]interface{}{ |
597 | - "userId": item.CooperationApplicationApplicant.UserID, | 597 | + "userId": fmt.Sprintf("%v", item.CooperationApplicationApplicant.UserID), |
598 | "userCode": item.CooperationApplicationApplicant.UserInfo.UserCode, | 598 | "userCode": item.CooperationApplicationApplicant.UserInfo.UserCode, |
599 | "userInfo": map[string]interface{}{ | 599 | "userInfo": map[string]interface{}{ |
600 | "userName": item.CooperationApplicationApplicant.UserInfo.UserName, | 600 | "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/reset-password", &controllers.AuthController{}, "Post:ResetPassword") //公司重置密码 | 21 | + web.Router("/v1/auth/user-sign-up", &controllers.AuthController{}, "Post:UserSignUp") |
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 | } |
-
请 注册 或 登录 后发表评论