diff --git a/backend/app/api/v1/setting.go b/backend/app/api/v1/setting.go index 146b22788..5c09a500f 100644 --- a/backend/app/api/v1/setting.go +++ b/backend/app/api/v1/setting.go @@ -65,6 +65,33 @@ func (b *BaseApi) UpdateSetting(c *gin.Context) { helper.SuccessWithData(c, nil) } +// @Tags System Setting +// @Summary Update system entrance +// @Description 更新系统安全入口 +// @Accept json +// @Param request body dto.SettingUpdate true "request" +// @Success 200 +// @Security ApiKeyAuth +// @Router /settings/entrance/enable [post] +// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFuntions":[],"formatZH":"修改系统配置 [SecurityEntranceStatus] => [打开]","formatEN":"update system setting [SecurityEntranceStatus] => [Enable]"} +func (b *BaseApi) UpdateEntrance(c *gin.Context) { + var req dto.SettingUpdate + if err := c.ShouldBindJSON(&req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + return + } + if err := global.VALID.Struct(req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + return + } + + if err := settingService.UpdateEntrance(req.Value); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, nil) +} + // @Tags System Setting // @Summary Update system password // @Description 更新系统登录密码 diff --git a/backend/app/service/setting.go b/backend/app/service/setting.go index 15ec6cfba..e645787ec 100644 --- a/backend/app/service/setting.go +++ b/backend/app/service/setting.go @@ -20,6 +20,7 @@ type SettingService struct{} type ISettingService interface { GetSettingInfo() (*dto.SettingInfo, error) Update(key, value string) error + UpdateEntrance(value string) error UpdatePassword(c *gin.Context, old, new string) error UpdatePort(port uint) error HandlePasswordExpired(c *gin.Context, old, new string) error @@ -76,6 +77,16 @@ func (u *SettingService) Update(key, value string) error { return nil } +func (u *SettingService) UpdateEntrance(value string) error { + if err := settingRepo.Update("SecurityEntranceStatus", "enable"); err != nil { + return err + } + if err := settingRepo.Update("SecurityEntrance", value); err != nil { + return err + } + return nil +} + func (u *SettingService) UpdatePort(port uint) error { if common.ScanPort(int(port)) { return buserr.WithDetail(constant.ErrPortInUsed, port, nil) diff --git a/backend/router/ro_setting.go b/backend/router/ro_setting.go index 1493acca1..cb2220c87 100644 --- a/backend/router/ro_setting.go +++ b/backend/router/ro_setting.go @@ -22,6 +22,7 @@ func (s *SettingRouter) InitSettingRouter(Router *gin.RouterGroup) { router.POST("/expired/handle", baseApi.HandlePasswordExpired) settingRouter.GET("/search/available", baseApi.GetSystemAvailable) settingRouter.POST("/update", baseApi.UpdateSetting) + settingRouter.POST("/entrance/enable", baseApi.UpdateEntrance) settingRouter.POST("/port/update", baseApi.UpdatePort) settingRouter.POST("/password/update", baseApi.UpdatePassword) settingRouter.POST("/time/sync", baseApi.SyncTime) diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index e943bb767..467f419bb 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -827,6 +827,34 @@ var doc = `{ } } }, + "/auth/isfirst": { + "get": { + "description": "判断是否为首次登录", + "tags": [ + "Auth" + ], + "summary": "Check is First login", + "responses": { + "200": { + "description": "" + } + } + } + }, + "/auth/issafety": { + "get": { + "description": "获取系统安全登录状态", + "tags": [ + "Auth" + ], + "summary": "Load safety status", + "responses": { + "200": { + "description": "" + } + } + } + }, "/auth/login": { "post": { "description": "用户登录", @@ -6806,6 +6834,46 @@ var doc = `{ } } }, + "/settings/entrance/enable": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "更新系统安全入口", + "consumes": [ + "application/json" + ], + "tags": [ + "System Setting" + ], + "summary": "Update system entrance", + "parameters": [ + { + "description": "request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.SettingUpdate" + } + } + ], + "responses": { + "200": { + "description": "" + } + }, + "x-panel-log": { + "BeforeFuntions": [], + "bodyKeys": [], + "formatEN": "update system setting [SecurityEntranceStatus] =\u003e [Enable]", + "formatZH": "修改系统配置 [SecurityEntranceStatus] =\u003e [打开]", + "paramKeys": [] + } + } + }, "/settings/expired/handle": { "post": { "security": [ @@ -11524,6 +11592,9 @@ var doc = `{ "securityEntrance": { "type": "string" }, + "securityEntranceStatus": { + "type": "string" + }, "serverPort": { "type": "string" }, diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index e30d0ebfe..e5bf19d11 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -813,6 +813,34 @@ } } }, + "/auth/isfirst": { + "get": { + "description": "判断是否为首次登录", + "tags": [ + "Auth" + ], + "summary": "Check is First login", + "responses": { + "200": { + "description": "" + } + } + } + }, + "/auth/issafety": { + "get": { + "description": "获取系统安全登录状态", + "tags": [ + "Auth" + ], + "summary": "Load safety status", + "responses": { + "200": { + "description": "" + } + } + } + }, "/auth/login": { "post": { "description": "用户登录", @@ -6792,6 +6820,46 @@ } } }, + "/settings/entrance/enable": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "更新系统安全入口", + "consumes": [ + "application/json" + ], + "tags": [ + "System Setting" + ], + "summary": "Update system entrance", + "parameters": [ + { + "description": "request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.SettingUpdate" + } + } + ], + "responses": { + "200": { + "description": "" + } + }, + "x-panel-log": { + "BeforeFuntions": [], + "bodyKeys": [], + "formatEN": "update system setting [SecurityEntranceStatus] =\u003e [Enable]", + "formatZH": "修改系统配置 [SecurityEntranceStatus] =\u003e [打开]", + "paramKeys": [] + } + } + }, "/settings/expired/handle": { "post": { "security": [ @@ -11510,6 +11578,9 @@ "securityEntrance": { "type": "string" }, + "securityEntranceStatus": { + "type": "string" + }, "serverPort": { "type": "string" }, diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index 2fe04f709..3636005d7 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -1453,6 +1453,8 @@ definitions: type: string securityEntrance: type: string + securityEntranceStatus: + type: string serverPort: type: string sessionTimeout: @@ -3410,6 +3412,24 @@ paths: summary: Init user tags: - Auth + /auth/isfirst: + get: + description: 判断是否为首次登录 + responses: + "200": + description: "" + summary: Check is First login + tags: + - Auth + /auth/issafety: + get: + description: 获取系统安全登录状态 + responses: + "200": + description: "" + summary: Load safety status + tags: + - Auth /auth/login: post: consumes: @@ -7208,6 +7228,32 @@ paths: summary: Load local backup dir tags: - System Setting + /settings/entrance/enable: + post: + consumes: + - application/json + description: 更新系统安全入口 + parameters: + - description: request + in: body + name: request + required: true + schema: + $ref: '#/definitions/dto.SettingUpdate' + responses: + "200": + description: "" + security: + - ApiKeyAuth: [] + summary: Update system entrance + tags: + - System Setting + x-panel-log: + BeforeFuntions: [] + bodyKeys: [] + formatEN: update system setting [SecurityEntranceStatus] => [Enable] + formatZH: 修改系统配置 [SecurityEntranceStatus] => [打开] + paramKeys: [] /settings/expired/handle: post: consumes: diff --git a/frontend/src/api/modules/setting.ts b/frontend/src/api/modules/setting.ts index 96c1c25e6..d075cf659 100644 --- a/frontend/src/api/modules/setting.ts +++ b/frontend/src/api/modules/setting.ts @@ -16,6 +16,10 @@ export const updateSetting = (param: Setting.SettingUpdate) => { return http.post(`/settings/update`, param); }; +export const updateEntrance = (param: Setting.SettingUpdate) => { + return http.post(`/settings/entrance/enable`, param); +}; + export const updatePassword = (param: Setting.PasswordUpdate) => { return http.post(`/settings/password/update`, param); }; diff --git a/frontend/src/views/setting/safe/index.vue b/frontend/src/views/setting/safe/index.vue index f2fa3ad7f..fa31fdd01 100644 --- a/frontend/src/views/setting/safe/index.vue +++ b/frontend/src/views/setting/safe/index.vue @@ -33,6 +33,8 @@ @@ -164,7 +166,15 @@ import { ElForm, ElMessageBox } from 'element-plus'; import { Setting } from '@/api/interface/setting'; import LayoutContent from '@/layout/layout-content.vue'; import DrawerHeader from '@/components/drawer-header/index.vue'; -import { updateSetting, getMFA, bindMFA, getSettingInfo, updatePort, getSystemAvailable } from '@/api/modules/setting'; +import { + updateSetting, + getMFA, + bindMFA, + getSettingInfo, + updatePort, + getSystemAvailable, + updateEntrance, +} from '@/api/modules/setting'; import i18n from '@/lang'; import { Rules, checkNumberRange } from '@/global/form-rules'; import { dateFormatSimple } from '@/utils/util'; @@ -320,7 +330,7 @@ const onSaveEntrance = async () => { return; } loading.value = true; - await updateSetting({ key: 'SecurityEntrance', value: form.securityEntrance }) + await updateEntrance({ key: 'SecurityEntrance', value: form.securityEntrance }) .then(() => { globalStore.entrance = form.securityEntrance; loading.value = false;