作者 yangfu

app auth 流程

@@ -88,7 +88,7 @@ func (srv AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke @@ -88,7 +88,7 @@ func (srv AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke
88 if err := accessTokenCommand.ValidateCommand(); err != nil { 88 if err := accessTokenCommand.ValidateCommand(); err != nil {
89 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 89 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
90 } 90 }
91 - ltoken := domain.LoginToken{} 91 + ltoken := &domain.LoginToken{}
92 err := ltoken.ParseToken(accessTokenCommand.AuthCode) 92 err := ltoken.ParseToken(accessTokenCommand.AuthCode)
93 if err != nil { 93 if err != nil {
94 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 94 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -96,6 +96,7 @@ func (srv AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke @@ -96,6 +96,7 @@ func (srv AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke
96 phone := ltoken.Account 96 phone := ltoken.Account
97 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{}) 97 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
98 userSeachResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{ 98 userSeachResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
  99 + CompanyId: ltoken.CompanyId,
99 Phone: phone, 100 Phone: phone,
100 }) 101 })
101 if err != nil { 102 if err != nil {
@@ -137,7 +138,7 @@ func (srv AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke @@ -137,7 +138,7 @@ func (srv AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke
137 UserId: int64(userSeachResult.Users[0].UserId), 138 UserId: int64(userSeachResult.Users[0].UserId),
138 Account: userSeachResult.Users[0].UserInfo.Phone, 139 Account: userSeachResult.Users[0].UserInfo.Phone,
139 Platform: domain.LoginPlatformApp, 140 Platform: domain.LoginPlatformApp,
140 - CompanyId: int64(userSeachResult.Users[0].Company.CompanyId), 141 + //CompanyId: int64(userSeachResult.Users[0].Company.CompanyId),
141 OrganizationId: int64(userSeachResult.Users[0].Org.OrgId), 142 OrganizationId: int64(userSeachResult.Users[0].Org.OrgId),
142 AccessToken: "", 143 AccessToken: "",
143 RefreshToken: "", 144 RefreshToken: "",
@@ -146,6 +147,9 @@ func (srv AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke @@ -146,6 +147,9 @@ func (srv AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke
146 CreatedTime: time.Now(), 147 CreatedTime: time.Now(),
147 UpdatedTime: time.Now(), 148 UpdatedTime: time.Now(),
148 } 149 }
  150 + if userSeachResult.Users[0].Company != nil {
  151 + currentAccess.CompanyId = int64(userSeachResult.Users[0].Company.CompanyId)
  152 + }
149 } 153 }
150 //判定当前凭证的companyId,OrganizationId 是否在用户列表中 154 //判定当前凭证的companyId,OrganizationId 是否在用户列表中
151 var currentOrgIsOK bool 155 var currentOrgIsOK bool
@@ -3,7 +3,9 @@ package service @@ -3,7 +3,9 @@ package service
3 import ( 3 import (
4 "github.com/linmadan/egglib-go/core/application" 4 "github.com/linmadan/egglib-go/core/application"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/command" 5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/command"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
  8 + "strconv"
7 ) 9 )
8 10
9 // CooperationProjectService 共创项目服务 11 // CooperationProjectService 共创项目服务
@@ -11,18 +13,31 @@ type CooperationProjectService struct { @@ -11,18 +13,31 @@ type CooperationProjectService struct {
11 } 13 }
12 14
13 // CreateCooperationProject TODO:创建共创项目 15 // CreateCooperationProject TODO:创建共创项目
14 -func (srv CooperationProjectService) CreateCooperationProject(userMenusCommand *command.CreateCooperationProjectCommand) (interface{}, error) {  
15 - creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(  
16 - userMenusCommand.Operator)  
17 - resultMenu, err := creationUserGateway.UserAccessMenus(allied_creation_user.ReqUserAccessMenus{  
18 - UserId: int(userMenusCommand.Operator.UserId), 16 +func (srv CooperationProjectService) CreateCooperationProject(createCooperationProjectCommand *command.CreateCooperationProjectCommand) (interface{}, error) {
  17 + if err := createCooperationProjectCommand.ValidateCommand(); err != nil {
  18 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  19 + }
  20 + creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(createCooperationProjectCommand.Operator)
  21 + result, err := creationCooperationGateway.CooperationProjectAdd(allied_creation_cooperation.ReqCooperationProjectAdd{
  22 + CooperationProjectDescription: createCooperationProjectCommand.CooperationProjectDescription,
  23 + CooperationProjectName: createCooperationProjectCommand.CooperationProjectName,
  24 + PublisherUid: strconv.Itoa(int(createCooperationProjectCommand.Operator.UserId)),
  25 + SponsorUid: createCooperationProjectCommand.CooperationProjectSponsor,
  26 + CooperationProjectUndertakerType: createCooperationProjectCommand.CooperationProjectUndertakerType,
  27 + Images: createCooperationProjectCommand.Images,
19 }) 28 })
  29 +
20 if err != nil { 30 if err != nil {
21 - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 31 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
22 } 32 }
23 - return map[string]interface{}{  
24 - "accessMenus": resultMenu.Menus,  
25 - }, nil 33 + data := struct {
  34 + CooperationProjectId int `json:"cooperationProjectId"`
  35 + command.CreateCooperationProjectCommand
  36 + }{
  37 + CooperationProjectId: result.CooperationProjectId,
  38 + CreateCooperationProjectCommand: *createCooperationProjectCommand,
  39 + }
  40 + return data, nil
26 } 41 }
27 42
28 // GetCooperationProject TODO:返回共创项目明细 43 // GetCooperationProject TODO:返回共创项目明细
@@ -13,7 +13,7 @@ type Department struct { @@ -13,7 +13,7 @@ type Department struct {
13 } 13 }
14 type User struct { 14 type User struct {
15 UserID int `json:"userId"` 15 UserID int `json:"userId"`
16 - UserName string `json:"userName"` 16 + UserInfo map[string]interface{} `json:"userInfo"`
17 } 17 }
18 18
19 func (dto *DepartmentUsersDto) LoadDto(subDepartment *allied_creation_user.DataOrgGetSubDepartment, userSearch *allied_creation_user.DataUserSearch) error { 19 func (dto *DepartmentUsersDto) LoadDto(subDepartment *allied_creation_user.DataOrgGetSubDepartment, userSearch *allied_creation_user.DataUserSearch) error {
@@ -38,7 +38,9 @@ func (dto *DepartmentUsersDto) LoadDto(subDepartment *allied_creation_user.DataO @@ -38,7 +38,9 @@ func (dto *DepartmentUsersDto) LoadDto(subDepartment *allied_creation_user.DataO
38 if v, ok := mapDepartment[int64(user.Department.DepartmentId)]; ok { 38 if v, ok := mapDepartment[int64(user.Department.DepartmentId)]; ok {
39 v.Users = append(v.Users, User{ 39 v.Users = append(v.Users, User{
40 UserID: user.UserId, 40 UserID: user.UserId,
41 - UserName: user.UserInfo.UserName, 41 + UserInfo: map[string]interface{}{
  42 + "userName": user.UserInfo.UserName,
  43 + },
42 }) 44 })
43 } 45 }
44 } 46 }
@@ -25,9 +25,9 @@ type CompanyUserAddCommand struct { @@ -25,9 +25,9 @@ type CompanyUserAddCommand struct {
25 // 邮箱 25 // 邮箱
26 Email string `json:"email" valid:"Required"` 26 Email string `json:"email" valid:"Required"`
27 // 关联的组织机构 27 // 关联的组织机构
28 - UsersOrg []string `json:"userOrg"`  
29 - // 关联的用户  
30 - UsersRole []string `json:"userRole"` 28 + UserOrg []Org `json:"userOrg,omitempty"`
  29 + // 关联的组织结构
  30 + UserRole []Role `json:"userRole,omitempty"`
31 // 头像 31 // 头像
32 Avatar string `json:"avatar" valid:"Required"` 32 Avatar string `json:"avatar" valid:"Required"`
33 } 33 }
@@ -102,14 +102,14 @@ func (usersService *UsersService) CompanyUserAdd(companyUserAddCommand *command. @@ -102,14 +102,14 @@ func (usersService *UsersService) CompanyUserAdd(companyUserAddCommand *command.
102 orgId, _ := strconv.Atoi(companyUserAddCommand.OrgId) 102 orgId, _ := strconv.Atoi(companyUserAddCommand.OrgId)
103 userOrg := []int64{} 103 userOrg := []int64{}
104 userRole := []int64{} 104 userRole := []int64{}
105 - for _, v := range companyUserAddCommand.UsersOrg {  
106 - id, err := strconv.Atoi(v) 105 + for _, v := range companyUserAddCommand.UserOrg {
  106 + id, err := strconv.Atoi(v.OrgId)
107 if err == nil { 107 if err == nil {
108 userOrg = append(userOrg, int64(id)) 108 userOrg = append(userOrg, int64(id))
109 } 109 }
110 } 110 }
111 - for _, v := range companyUserAddCommand.UsersRole {  
112 - id, err := strconv.Atoi(v) 111 + for _, v := range companyUserAddCommand.UserRole {
  112 + id, err := strconv.Atoi(v.RoleId)
113 if err == nil { 113 if err == nil {
114 userRole = append(userRole, int64(id)) 114 userRole = append(userRole, int64(id))
115 } 115 }
@@ -128,7 +128,7 @@ func (usersService *UsersService) CompanyUserAdd(companyUserAddCommand *command. @@ -128,7 +128,7 @@ func (usersService *UsersService) CompanyUserAdd(companyUserAddCommand *command.
128 UserName: companyUserAddCommand.UsersName, 128 UserName: companyUserAddCommand.UsersName,
129 Phone: companyUserAddCommand.Phone, 129 Phone: companyUserAddCommand.Phone,
130 Avatar: companyUserAddCommand.Avatar, 130 Avatar: companyUserAddCommand.Avatar,
131 - Email: companyUserAddCommand.Avatar, 131 + Email: companyUserAddCommand.Email,
132 Password: "123456", //TODO 填充密码 132 Password: "123456", //TODO 填充密码
133 }) 133 })
134 if err != nil { 134 if err != nil {
@@ -13,7 +13,7 @@ var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" @@ -13,7 +13,7 @@ var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080"
13 var ALLIED_CREATION_USER_HOST = "http://localhost:8081" 13 var ALLIED_CREATION_USER_HOST = "http://localhost:8081"
14 14
15 //天联共创业务模块 15 //天联共创业务模块
16 -var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8081" 16 +var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082"
17 17
18 //通用模块短信服务 18 //通用模块短信服务
19 var SMS_SERVE_HOST = "http://localhost:8081" 19 var SMS_SERVE_HOST = "http://localhost:8081"
@@ -53,24 +53,23 @@ func (t *LoginToken) GenerateRefreshToken() (string, error) { @@ -53,24 +53,23 @@ func (t *LoginToken) GenerateRefreshToken() (string, error) {
53 53
54 func (t *LoginToken) GenerateAuthCode() (string, error) { 54 func (t *LoginToken) GenerateAuthCode() (string, error) {
55 nowTime := time.Now().Unix() 55 nowTime := time.Now().Unix()
56 - claims := LoginToken{  
57 - StandardClaims: jwt.StandardClaims{ 56 + t.StandardClaims = jwt.StandardClaims{
58 NotBefore: nowTime, 57 NotBefore: nowTime,
59 IssuedAt: nowTime, 58 IssuedAt: nowTime,
60 ExpiresAt: nowTime + authCodeExpire, 59 ExpiresAt: nowTime + authCodeExpire,
61 Issuer: "allied_creation_gateway", 60 Issuer: "allied_creation_gateway",
62 - },  
63 } 61 }
64 - token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) 62 +
  63 + token := jwt.NewWithClaims(jwt.SigningMethodHS256, *t)
65 return token.SignedString([]byte(loginTokenSecret)) 64 return token.SignedString([]byte(loginTokenSecret))
66 } 65 }
67 66
68 func (t *LoginToken) ParseToken(str string) error { 67 func (t *LoginToken) ParseToken(str string) error {
69 tokenClaims, err := jwt.ParseWithClaims( 68 tokenClaims, err := jwt.ParseWithClaims(
70 str, 69 str,
71 - &LoginToken{}, 70 + t,
72 func(token *jwt.Token) (interface{}, error) { 71 func(token *jwt.Token) (interface{}, error) {
73 - return loginTokenSecret, nil 72 + return []byte(loginTokenSecret), nil
74 }) 73 })
75 if err != nil { 74 if err != nil {
76 return err 75 return err
@@ -3,7 +3,7 @@ package models @@ -3,7 +3,7 @@ package models
3 import "time" 3 import "time"
4 4
5 type LoginAccess struct { 5 type LoginAccess struct {
6 - tableName string `pg:"login_accesss,alias:login_access"` 6 + tableName string `pg:"login_access,alias:login_access"`
7 7
8 LoginAccessId int64 `pg:",pk"` 8 LoginAccessId int64 `pg:",pk"`
9 // 账号 9 // 账号
@@ -138,8 +138,8 @@ func (repository *LoginAccessRepository) Find(queryOptions map[string]interface{ @@ -138,8 +138,8 @@ func (repository *LoginAccessRepository) Find(queryOptions map[string]interface{
138 query := sqlbuilder.BuildQuery(tx.Model(&loginAccessModels), queryOptions) 138 query := sqlbuilder.BuildQuery(tx.Model(&loginAccessModels), queryOptions)
139 query.SetOffsetAndLimit(20) 139 query.SetOffsetAndLimit(20)
140 query.SetOrderDirect("login_access_id", "DESC") 140 query.SetOrderDirect("login_access_id", "DESC")
141 - query.SetWhereByQueryOption("account", "account")  
142 - query.SetWhereByQueryOption("platform", "platform") 141 + query.SetWhereByQueryOption("account = ?", "account")
  142 + query.SetWhereByQueryOption("platform = ?", "platform")
143 if count, err := query.SelectAndCount(); err != nil { 143 if count, err := query.SelectAndCount(); err != nil {
144 return 0, loginAccesss, err 144 return 0, loginAccesss, err
145 } else { 145 } else {
@@ -23,6 +23,6 @@ func NewHttplibAlliedCreationCooperation(operator domain.Operator) *HttplibAllie @@ -23,6 +23,6 @@ func NewHttplibAlliedCreationCooperation(operator domain.Operator) *HttplibAllie
23 UserId: operator.UserId, 23 UserId: operator.UserId,
24 UserBaseId: operator.UserBaseId, 24 UserBaseId: operator.UserBaseId,
25 }, 25 },
26 - baseUrL: constant.ALLIED_CREATION_USER_HOST, 26 + baseUrL: constant.ALLIED_CREATION_COOPERATION_HOST,
27 } 27 }
28 } 28 }
@@ -153,6 +153,8 @@ func (controller *CooperationController) GetCooperationProject() { @@ -153,6 +153,8 @@ func (controller *CooperationController) GetCooperationProject() {
153 return 153 return
154 } 154 }
155 cmd.Operator = controller.GetOperator() 155 cmd.Operator = controller.GetOperator()
  156 + projectId, _ := controller.GetInt(":projectId")
  157 + cmd.CooperationProjectId = projectId
156 data, err := svr.GetCooperationProject(cmd) 158 data, err := svr.GetCooperationProject(cmd)
157 controller.Response(data, err) 159 controller.Response(data, err)
158 } 160 }
@@ -18,6 +18,7 @@ func (controller *CooperationProjectController) CreateCooperationProject() { @@ -18,6 +18,7 @@ func (controller *CooperationProjectController) CreateCooperationProject() {
18 if err != nil { 18 if err != nil {
19 log.Logger.Debug("json err:" + err.Error()) 19 log.Logger.Debug("json err:" + err.Error())
20 } 20 }
  21 + createCooperationProjectCommand.Operator = controller.GetOperator()
21 data, err := cooperationProjectService.CreateCooperationProject(createCooperationProjectCommand) 22 data, err := cooperationProjectService.CreateCooperationProject(createCooperationProjectCommand)
22 controller.Response(data, err) 23 controller.Response(data, err)
23 } 24 }
@@ -31,6 +32,7 @@ func (controller *CooperationProjectController) UpdateCooperationProject() { @@ -31,6 +32,7 @@ func (controller *CooperationProjectController) UpdateCooperationProject() {
31 } 32 }
32 projectId := controller.GetString(":projectId") 33 projectId := controller.GetString(":projectId")
33 updateCooperationProjectCommand.CooperationProjectId = projectId 34 updateCooperationProjectCommand.CooperationProjectId = projectId
  35 + updateCooperationProjectCommand.Operator = controller.GetOperator()
34 data, err := cooperationProjectService.UpdateCooperationProject(updateCooperationProjectCommand) 36 data, err := cooperationProjectService.UpdateCooperationProject(updateCooperationProjectCommand)
35 controller.Response(data, err) 37 controller.Response(data, err)
36 } 38 }
@@ -40,6 +42,7 @@ func (controller *CooperationProjectController) GetCooperationProject() { @@ -40,6 +42,7 @@ func (controller *CooperationProjectController) GetCooperationProject() {
40 getCooperationProjectQuery := &query.GetCooperationProjectQuery{} 42 getCooperationProjectQuery := &query.GetCooperationProjectQuery{}
41 projectId, _ := controller.GetInt(":projectId") 43 projectId, _ := controller.GetInt(":projectId")
42 getCooperationProjectQuery.CooperationProjectId = projectId 44 getCooperationProjectQuery.CooperationProjectId = projectId
  45 + getCooperationProjectQuery.Operator = controller.GetOperator()
43 data, err := cooperationProjectService.GetCooperationProject(getCooperationProjectQuery) 46 data, err := cooperationProjectService.GetCooperationProject(getCooperationProjectQuery)
44 controller.Response(data, err) 47 controller.Response(data, err)
45 } 48 }
@@ -51,6 +54,7 @@ func (controller *CooperationProjectController) ListCooperationProject() { @@ -51,6 +54,7 @@ func (controller *CooperationProjectController) ListCooperationProject() {
51 if err != nil { 54 if err != nil {
52 log.Logger.Debug("json err:" + err.Error()) 55 log.Logger.Debug("json err:" + err.Error())
53 } 56 }
  57 + listCooperationProjectQuery.Operator = controller.GetOperator()
54 cnt, data, err := cooperationProjectService.ListCooperationProject(listCooperationProjectQuery) 58 cnt, data, err := cooperationProjectService.ListCooperationProject(listCooperationProjectQuery)
55 controller.returnPageListData(cnt, data, err, listCooperationProjectQuery.PageNumber) 59 controller.returnPageListData(cnt, data, err, listCooperationProjectQuery.PageNumber)
56 } 60 }
@@ -60,6 +64,7 @@ func (controller *CooperationProjectController) EndCooperationProject() { @@ -60,6 +64,7 @@ func (controller *CooperationProjectController) EndCooperationProject() {
60 endCooperationProjectCommand := &command.EndCooperationProjectCommand{} 64 endCooperationProjectCommand := &command.EndCooperationProjectCommand{}
61 controller.Unmarshal(endCooperationProjectCommand) 65 controller.Unmarshal(endCooperationProjectCommand)
62 //TODO 66 //TODO
  67 + endCooperationProjectCommand.Operator = controller.GetOperator()
63 data, err := cooperationProjectService.EndCooperationProject(endCooperationProjectCommand) 68 data, err := cooperationProjectService.EndCooperationProject(endCooperationProjectCommand)
64 controller.Response(data, err) 69 controller.Response(data, err)
65 } 70 }
@@ -2,6 +2,7 @@ package routers @@ -2,6 +2,7 @@ package routers
2 2
3 import ( 3 import (
4 "github.com/beego/beego/v2/server/web" 4 "github.com/beego/beego/v2/server/web"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/mobile_client"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/web_client" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/web_client"
6 ) 7 )
7 8
@@ -12,4 +13,5 @@ func init() { @@ -12,4 +13,5 @@ func init() {
12 web.Router("/v1/web/orgs/:orgId", &web_client.OrgsController{}, "Get:OrgGet") 13 web.Router("/v1/web/orgs/:orgId", &web_client.OrgsController{}, "Get:OrgGet")
13 web.Router("/v1/web/orgs/enable", &web_client.OrgsController{}, "Post:OrgEnable") 14 web.Router("/v1/web/orgs/enable", &web_client.OrgsController{}, "Post:OrgEnable")
14 web.Router("/v1/web/orgs/departments", &web_client.OrgsController{}, "Post:OrgGetSubDepartment") 15 web.Router("/v1/web/orgs/departments", &web_client.OrgsController{}, "Post:OrgGetSubDepartment")
  16 + web.Router("/v1/web/orgs/department-users", &mobile_client.OrgController{}, "Post:DepartmentUsers")
15 } 17 }