feat: 添加数据库资产、命令拦截器、授权资产等功能,修复GitHub Actions工作流
This commit is contained in:
+45
-30
@@ -118,13 +118,18 @@ func (api AccountApi) LoginEndpoint(c echo.Context) error {
|
||||
}
|
||||
|
||||
info := AccountInfo{
|
||||
Id: user.ID,
|
||||
Username: user.Username,
|
||||
Nickname: user.Nickname,
|
||||
Type: user.Type,
|
||||
EnableTotp: user.TOTPSecret != "" && user.TOTPSecret != "-",
|
||||
Roles: user.Roles,
|
||||
Menus: menus,
|
||||
Id: user.ID,
|
||||
Username: user.Username,
|
||||
Nickname: user.Nickname,
|
||||
Type: user.Type,
|
||||
EnabledTotp: user.TOTPSecret != "" && user.TOTPSecret != "-",
|
||||
MfaEnabled: user.TOTPSecret != "" && user.TOTPSecret != "-",
|
||||
Roles: user.Roles,
|
||||
Menus: menus,
|
||||
Language: "zh-CN",
|
||||
ForceTotpEnabled: false,
|
||||
NeedChangePassword: false,
|
||||
Dev: config.GlobalCfg.Debug,
|
||||
}
|
||||
|
||||
return Success(c, maps.Map{
|
||||
@@ -269,13 +274,18 @@ func (api AccountApi) ChangePasswordEndpoint(c echo.Context) error {
|
||||
}
|
||||
|
||||
type AccountInfo struct {
|
||||
Id string `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Nickname string `json:"nickname"`
|
||||
Type string `json:"type"`
|
||||
EnableTotp bool `json:"enableTotp"`
|
||||
Roles []string `json:"roles"`
|
||||
Menus []UserMenu `json:"menus"`
|
||||
Id string `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Nickname string `json:"nickname"`
|
||||
Type string `json:"type"`
|
||||
EnabledTotp bool `json:"enabledTotp"`
|
||||
MfaEnabled bool `json:"mfaEnabled"`
|
||||
Roles []string `json:"roles"`
|
||||
Menus []UserMenu `json:"menus"`
|
||||
Language string `json:"language"`
|
||||
ForceTotpEnabled bool `json:"forceTotpEnabled"`
|
||||
NeedChangePassword bool `json:"needChangePassword"`
|
||||
Dev bool `json:"dev"`
|
||||
}
|
||||
|
||||
type UserMenu struct {
|
||||
@@ -317,13 +327,18 @@ func (api AccountApi) InfoEndpoint(c echo.Context) error {
|
||||
}
|
||||
|
||||
info := AccountInfo{
|
||||
Id: user.ID,
|
||||
Username: user.Username,
|
||||
Nickname: user.Nickname,
|
||||
Type: user.Type,
|
||||
EnableTotp: user.TOTPSecret != "" && user.TOTPSecret != "-",
|
||||
Roles: user.Roles,
|
||||
Menus: menus,
|
||||
Id: user.ID,
|
||||
Username: user.Username,
|
||||
Nickname: user.Nickname,
|
||||
Type: user.Type,
|
||||
EnabledTotp: user.TOTPSecret != "" && user.TOTPSecret != "-",
|
||||
MfaEnabled: user.TOTPSecret != "" && user.TOTPSecret != "-",
|
||||
Roles: user.Roles,
|
||||
Menus: menus,
|
||||
Language: "zh-CN",
|
||||
ForceTotpEnabled: false,
|
||||
NeedChangePassword: false,
|
||||
Dev: config.GlobalCfg.Debug,
|
||||
}
|
||||
return Success(c, info)
|
||||
}
|
||||
@@ -409,39 +424,39 @@ func (api AccountApi) SecurityTokenSupportTypesEndpoint(c echo.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
var types []string
|
||||
if user.TOTPSecret != "" && user.TOTPSecret != "-" {
|
||||
types = append(types, "otp")
|
||||
}
|
||||
|
||||
|
||||
if len(types) == 0 {
|
||||
types = []string{}
|
||||
}
|
||||
|
||||
|
||||
return Success(c, types)
|
||||
}
|
||||
|
||||
func (api AccountApi) SecurityTokenMfaEndpoint(c echo.Context) error {
|
||||
account, _ := GetCurrentAccount(c)
|
||||
passcode := c.QueryParam("passcode")
|
||||
|
||||
|
||||
user, err := repository.UserRepository.FindById(context.TODO(), account.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
if user.TOTPSecret == "" || user.TOTPSecret == "-" {
|
||||
return Fail(c, -1, "MFA not enabled")
|
||||
}
|
||||
|
||||
|
||||
if !common.Validate(passcode, user.TOTPSecret) {
|
||||
return Fail(c, -1, "Invalid passcode")
|
||||
}
|
||||
|
||||
|
||||
token := utils.UUID()
|
||||
cache.TokenManager.Set(token, account.ID, cache.NotRememberExpiration)
|
||||
|
||||
|
||||
return Success(c, maps.Map{"token": token})
|
||||
}
|
||||
|
||||
@@ -450,7 +465,7 @@ func (api AccountApi) SecurityTokenValidateEndpoint(c echo.Context) error {
|
||||
if token == "" {
|
||||
return Success(c, maps.Map{"ok": false})
|
||||
}
|
||||
|
||||
|
||||
_, ok := cache.TokenManager.Get(token)
|
||||
return Success(c, maps.Map{"ok": ok})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user