切换导航条
此项目
正在载入...
登录
allied-creation
/
performance
·
提交
转到一个项目
GitLab
转到群组
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
tangxvhui
2 years ago
提交
b01c9dae42d866a9b252e043566276a5cd70cbfe
1 个父辈
32f22cb6
添加手机端登录接口
隐藏空白字符变更
内嵌
并排对比
正在显示
7 个修改的文件
包含
83 行增加
和
16 行删除
pkg/application/auth/command/login.go
pkg/application/auth/command/mobile_login.go
pkg/application/auth/service/auth.go
pkg/constant/common.go
pkg/domain/business_admin.go
pkg/port/beego/controllers/auth_controller.go
pkg/port/beego/routers/auth.go
pkg/application/auth/command/login.go
查看文件 @
b01c9da
...
...
@@ -2,5 +2,5 @@ package command
type
LoginCommand
struct
{
Code
string
`json:"code" valid:"Required"`
//授权code
PlatformId
int
`json:"platformId" valid:"Required"`
//登录平台ID,
28-绩效管理后台 29-
员工绩效
PlatformId
int
`json:"platformId" valid:"Required"`
//登录平台ID,
constant.IdPlatformAdmin=28 绩效管理后台 constant.IdPlatformUser=29
员工绩效
}
...
...
pkg/application/auth/command/mobile_login.go
查看文件 @
b01c9da
...
...
@@ -8,19 +8,19 @@ import (
"github.com/beego/beego/validation"
)
type
AuthorizeCommand
struct
{
Token
string
`json:"credentials" valid:"Required;"`
//登录凭证
type
MobileLoginCommand
struct
{
Credentials
string
`json:"credentials" valid:"Required;"`
//登录凭证
Cuid
int
`json:"cuid,string" valid:"Required;"`
//统一用户中心用户 UID
Cid
int
`json:"cid,string" valid:"Required;"`
//统一用户中心公司 ID
Muid
int
`json:"muid,string" valid:"Required;"`
//企业平台中的用户 UID
//ClientId string `json:"clientId"` //客户端密钥
Cuid
int64
`json:"cuid" valid:"Required;"`
//统一用户中心用户 UID
Cid
int64
`json:"cid" valid:"Required;"`
//统一用户中心公司 ID
Muid
int64
`json:"muid" valid:"Required;"`
//企业平台中的用户 UID
}
func
(
authorizeCommand
*
Authorize
Command
)
Valid
(
validation
*
validation
.
Validation
)
{
func
(
authorizeCommand
*
MobileLogin
Command
)
Valid
(
validation
*
validation
.
Validation
)
{
}
func
(
authorizeCommand
*
Authorize
Command
)
ValidateCommand
()
error
{
func
(
authorizeCommand
*
MobileLogin
Command
)
ValidateCommand
()
error
{
valid
:=
validation
.
Validation
{}
b
,
err
:=
valid
.
Valid
(
authorizeCommand
)
if
err
!=
nil
{
...
...
pkg/application/auth/service/auth.go
查看文件 @
b01c9da
...
...
@@ -4,6 +4,7 @@ import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
...
...
@@ -53,7 +54,7 @@ func (service *AuthService) Login(loginCommand *command.LoginCommand) (interface
"companyId"
:
company
.
Id
,
})
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
"获取
公司
数据失败"
)
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
"获取
用户
数据失败"
)
}
if
user
.
Status
!=
domain
.
UserStatusEnable
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
"用户被禁用"
)
...
...
@@ -81,9 +82,8 @@ func (service *AuthService) Login(loginCommand *command.LoginCommand) (interface
},
nil
}
//手机端登录 ,来源于能力展示app
func
(
service
*
AuthService
)
MobileLogin
(
param
command
.
AuthorizeCommand
)
(
map
[
string
]
interface
{},
error
)
{
// 员工绩效 手机端登录,来源于能力展示app
func
(
service
*
AuthService
)
MobileLogin
(
param
*
command
.
MobileLoginCommand
)
(
map
[
string
]
interface
{},
error
)
{
transactionContext
,
err
:=
factory
.
CreateTransactionContext
(
nil
)
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
...
...
@@ -94,13 +94,61 @@ func (service *AuthService) MobileLogin(param command.AuthorizeCommand) (map[str
defer
func
()
{
_
=
transactionContext
.
RollbackTransaction
()
}()
// 统一用户中心登录
authCodeReply
,
err
:=
factory
.
UCenterApi
()
.
AppAuthCode
(
param
.
Credentials
,
param
.
Cuid
,
param
.
Cid
)
if
err
!=
nil
||
!
authCodeReply
.
IsOk
()
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
"统一用户中心认证失败"
)
}
// 用户权限校验
// 登录平台ID,28-绩效管理后台 29-员工绩效
userAuthReply
,
err
:=
factory
.
BusinessAdminApi
()
.
GetUserAuth
(
authCodeReply
.
Data
.
MUid
,
constant
.
IdPlatformUser
)
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
"用户鉴权失败"
)
}
if
!
userAuthReply
.
IsOk
()
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
userAuthReply
.
Message
())
}
//获取公司数据
companyRepository
:=
factory
.
CreateCompanyRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
,
})
company
,
err
:=
companyRepository
.
FindOne
(
map
[
string
]
interface
{}{
"id"
:
authCodeReply
.
Data
.
CompanyId
,
})
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
"获取公司数据失败"
)
}
userRepository
:=
factory
.
CreateUserRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
,
})
user
,
err
:=
userRepository
.
FindOne
(
map
[
string
]
interface
{}{
"id"
:
authCodeReply
.
Data
.
MUid
,
"companyId"
:
company
.
Id
,
})
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
"获取用户数据失败"
)
}
if
user
.
Status
!=
domain
.
UserStatusEnable
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
"用户被禁用"
)
}
userAuth
:=
&
domain
.
UserAuth
{
UserId
:
user
.
Id
,
CompanyId
:
user
.
CompanyId
,
Phone
:
user
.
Account
,
PlatformId
:
constant
.
IdPlatformUser
,
Name
:
user
.
Name
,
AdminType
:
user
.
AdminType
,
}
accessToken
,
err
:=
userAuth
.
CreateAccessToken
()
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
if
err
:=
transactionContext
.
CommitTransaction
();
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
}
result
:=
map
[
string
]
interface
{}{
"access"
:
map
[
string
]
interface
{}{
"accessToken"
:
""
,
"accessToken"
:
accessToken
,
"expiresIn"
:
domain
.
JWTExpiresSecond
,
},
}
...
...
pkg/constant/common.go
查看文件 @
b01c9da
...
...
@@ -4,9 +4,15 @@ import "os"
const
SERVICE_NAME
=
"performance"
// 登录平台ID,28-绩效管理后台 29-员工绩效
const
(
IdPlatformAdmin
int
=
28
IdPlatformUser
int
=
29
)
var
LOG_LEVEL
=
"debug"
//过期时间 7天时间
//
过期时间 7天时间
var
AdminJwtExpiresIn
=
int64
(
3600
*
24
*
7
)
var
AdminJWTSecretKey
=
"sg-storage"
...
...
pkg/domain/business_admin.go
查看文件 @
b01c9da
...
...
@@ -4,7 +4,10 @@ import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/se
// UCenterApi 统一用户中心
type
UCenterApi
interface
{
// pc 端
AuthCode
(
code
string
)
(
*
reply
.
UCenterAuthCode
,
error
)
//手机app端
AppAuthCode
(
tokenCode
string
,
uid
int
,
companyId
int
)
(
*
reply
.
UCenterAuthCode
,
error
)
}
// BusinessAdminApi 企业平台
...
...
pkg/port/beego/controllers/auth_controller.go
查看文件 @
b01c9da
...
...
@@ -21,9 +21,17 @@ func (controller *AuthController) Login() {
}
func
(
controller
*
AuthController
)
User
()
{
userAuth
:=
controller
.
Ctx
.
Input
.
GetData
(
domain
.
UserAuth
{})
.
(
*
domain
.
UserAuth
)
controller
.
Response
(
map
[
string
]
interface
{}{
"user"
:
userAuth
,
},
nil
)
}
// Login PC端登录
func
(
controller
*
AuthController
)
MobileLogin
()
{
authService
:=
&
service
.
AuthService
{}
loginCommand
:=
&
command
.
MobileLoginCommand
{}
_
=
controller
.
Unmarshal
(
loginCommand
)
resp
,
err
:=
authService
.
MobileLogin
(
loginCommand
)
controller
.
Response
(
resp
,
err
)
}
...
...
pkg/port/beego/routers/auth.go
查看文件 @
b01c9da
...
...
@@ -9,6 +9,8 @@ import (
func
init
()
{
web
.
Router
(
"/login"
,
&
controllers
.
AuthController
{},
"Post:Login"
)
web
.
Router
(
"/login/mobile"
,
&
controllers
.
AuthController
{},
"Post:MobileLogin"
)
//
web
.
InsertFilter
(
"/auth/admin/*"
,
web
.
BeforeExec
,
middlewares
.
CheckAdminToken
())
web
.
Router
(
"/auth/admin/user"
,
&
controllers
.
AuthController
{},
"Get:User"
)
...
...
请
注册
或
登录
后发表评论