作者 yangfu

app auth 流程

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