diff --git a/backend/app/dto/setting.go b/backend/app/dto/setting.go index b23dd39d1..8f5f7ef4f 100644 --- a/backend/app/dto/setting.go +++ b/backend/app/dto/setting.go @@ -4,14 +4,14 @@ type SettingInfo struct { UserName string `json:"userName"` Email string `json:"email"` - SessionTimeout string `json:"sessionTimeout"` + SessionTimeout int `json:"sessionTimeout"` LocalTime string `json:"localTime"` PanelName string `json:"panelName"` Theme string `json:"theme"` Language string `json:"language"` - ServerPort string `json:"serverPort"` + ServerPort int `json:"serverPort"` SecurityEntrance string `json:"securityEntrance"` PasswordTimeOut string `json:"passwordTimeOut"` ComplexityVerification string `json:"complexityVerification"` @@ -19,7 +19,7 @@ type SettingInfo struct { MFASecret string `json:"mfaSecret"` MonitorStatus string `json:"monitorStatus"` - MonitorStoreDays string `json:"monitorStoreDays"` + MonitorStoreDays int `json:"monitorStoreDays"` MessageType string `json:"messageType"` EmailVars string `json:"emailVars"` diff --git a/backend/app/service/setting.go b/backend/app/service/setting.go index 723e7f5c7..e1893df3e 100644 --- a/backend/app/service/setting.go +++ b/backend/app/service/setting.go @@ -2,6 +2,7 @@ package service import ( "encoding/json" + "strconv" "time" "github.com/1Panel-dev/1Panel/app/dto" @@ -37,9 +38,10 @@ func (u *SettingService) GetSettingInfo() (*dto.SettingInfo, error) { if err != nil { return nil, err } - if err := json.Unmarshal(arr, &info); err != nil { - return nil, err - } + _ = json.Unmarshal(arr, &info) + info.MonitorStoreDays, _ = strconv.Atoi(settingMap["MonitorStoreDays"]) + info.ServerPort, _ = strconv.Atoi(settingMap["ServerPort"]) + info.SessionTimeout, _ = strconv.Atoi(settingMap["SessionTimeout"]) info.LocalTime = time.Now().Format("2006-01-02 15:04:05") return &info, err } diff --git a/frontend/src/api/interface/setting.ts b/frontend/src/api/interface/setting.ts index cdd6de13d..8df2285ab 100644 --- a/frontend/src/api/interface/setting.ts +++ b/frontend/src/api/interface/setting.ts @@ -4,14 +4,14 @@ export namespace Setting { password: string; email: string; - sessionTimeout: string; + sessionTimeout: number; localTime: string; panelName: string; theme: string; language: string; - serverPort: string; + serverPort: number; securityEntrance: string; passwordTimeOut: string; complexityVerification: string; @@ -19,7 +19,7 @@ export namespace Setting { mfaSecret: string; monitorStatus: string; - monitorStoreDays: string; + monitorStoreDays: number; messageType: string; emailVars: string; @@ -33,7 +33,6 @@ export namespace Setting { export interface PasswordUpdate { oldPassword: string; newPassword: string; - retryPassword: string; } export interface MFAInfo { secret: string; diff --git a/frontend/src/global/form-rues.ts b/frontend/src/global/form-rules.ts similarity index 60% rename from frontend/src/global/form-rues.ts rename to frontend/src/global/form-rules.ts index 5b70c4ec0..9bc07cc3d 100644 --- a/frontend/src/global/form-rues.ts +++ b/frontend/src/global/form-rules.ts @@ -15,10 +15,37 @@ const checkIp = (rule: any, value: any, callback: any) => { } }; +const complexityPassword = (rule: any, value: any, callback: any) => { + if (value === '' || typeof value === 'undefined' || value == null) { + callback(new Error(i18n.global.t('commons.rule.complexityPassword'))); + } else { + const reg = /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[~!@#$%^&*.])[\da-zA-Z~!@#$%^&*.]{8,}$/; + if (!reg.test(value) && value !== '') { + callback(new Error(i18n.global.t('commons.rule.complexityPassword'))); + } else { + callback(); + } + } +}; + +const checkName = (rule: any, value: any, callback: any) => { + if (value === '' || typeof value === 'undefined' || value == null) { + callback(new Error(i18n.global.t('commons.rule.commonName'))); + } else { + const reg = /^[a-zA-Z0-9\u4e00-\u9fa5]{1}[a-zA-Z0-9_.\u4e00-\u9fa5-]{0,30}$/; + if (!reg.test(value) && value !== '') { + callback(new Error(i18n.global.t('commons.rule.commonName'))); + } else { + callback(); + } + } +}; + interface CommonRule { requiredInput: FormItemRule; requiredSelect: FormItemRule; name: FormItemRule; + password: FormItemRule; email: FormItemRule; number: FormItemRule; ip: FormItemRule; @@ -37,14 +64,15 @@ export const Rules: CommonRule = { trigger: 'change', }, name: { - type: 'regexp', - min: 1, - max: 30, - message: i18n.global.t('commons.rule.commonName'), + validator: checkName, + trigger: 'blur', + }, + password: { + validator: complexityPassword, trigger: 'blur', - pattern: '/^[a-zA-Z0-9\u4e00-\u9fa5]{1}[a-zA-Z0-9_.\u4e00-\u9fa5-]{0,30}$/', }, email: { + required: true, type: 'email', message: i18n.global.t('commons.rule.email'), trigger: 'blur', diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index fbadcf38e..4ff612025 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -68,6 +68,9 @@ export default { requiredInput: 'Please enter the required fields', requiredSelect: 'Please select the required fields', commonName: 'Support English, Chinese, numbers, .-_, length 1-30', + complexityPassword: + 'Please enter a password with more than 8 characters and must contain letters, digits, and special symbols', + commonPassword: 'Please enter a password with more than 6 characters', email: 'Email format error', ip: 'Please enter the correct IP address', port: 'Please enter the correct port', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index ba2ad9788..a7e622b8d 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -77,6 +77,8 @@ export default { requiredInput: '请填写必填项', requiredSelect: '请选择必选项', commonName: '支持英文、中文、数字、.-_,长度1-30', + complexityPassword: '请输入 8 位以上、必须含有字母、数字、特殊符号的密码', + commonPassword: '请输入 6 位以上长度密码', email: '请输入正确的邮箱', number: '请输入正确的数字', ip: '请输入正确的 IP 地址', @@ -298,7 +300,7 @@ export default { passwordTimeout: '密码过期时间', timeoutHelper: '【 {0} 天后 】面板密码即将过期,过期后需要重新设置密码', complexity: '密码复杂度验证', - complexityHelper: '密码必须满足密码长度大于8位且大写字母、小写字母、数字、特殊字符至少3项组合', + complexityHelper: '密码必须满足密码长度大于 8 位且包含字母、数字及特殊字符', mfa: '两步验证', mfaHelper1: '下载两步验证手机应用 如:', mfaHelper2: '使用手机应用扫描以下二维码,获取 6 位验证码', diff --git a/frontend/src/views/host/file-management/compress/index.vue b/frontend/src/views/host/file-management/compress/index.vue index 65995a269..49bdf186d 100644 --- a/frontend/src/views/host/file-management/compress/index.vue +++ b/frontend/src/views/host/file-management/compress/index.vue @@ -41,7 +41,7 @@ import i18n from '@/lang'; import { computed, reactive, ref, toRefs } from 'vue'; import { File } from '@/api/interface/file'; import { ElMessage, FormInstance, FormRules } from 'element-plus'; -import { Rules } from '@/global/form-rues'; +import { Rules } from '@/global/form-rules'; import { CompressExtention, CompressType } from '@/enums/files'; import { CompressFile } from '@/api/modules/files'; import FileList from '@/components/file-list/index.vue'; diff --git a/frontend/src/views/host/file-management/create/index.vue b/frontend/src/views/host/file-management/create/index.vue index d0534fc46..09f647894 100644 --- a/frontend/src/views/host/file-management/create/index.vue +++ b/frontend/src/views/host/file-management/create/index.vue @@ -56,7 +56,7 @@ import { ElMessage, FormInstance, FormRules } from 'element-plus'; import { CreateFile } from '@/api/modules/files'; import i18n from '@/lang'; import FileRole from '@/components/file-role/index.vue'; -import { Rules } from '@/global/form-rues'; +import { Rules } from '@/global/form-rules'; import FileList from '@/components/file-list/index.vue'; const fileForm = ref(); diff --git a/frontend/src/views/host/file-management/decompress/index.vue b/frontend/src/views/host/file-management/decompress/index.vue index 5e281ec41..f1794bc2b 100644 --- a/frontend/src/views/host/file-management/decompress/index.vue +++ b/frontend/src/views/host/file-management/decompress/index.vue @@ -33,7 +33,7 @@ import i18n from '@/lang'; import { reactive, ref, toRefs } from 'vue'; import { File } from '@/api/interface/file'; import { ElMessage, FormInstance, FormRules } from 'element-plus'; -import { Rules } from '@/global/form-rues'; +import { Rules } from '@/global/form-rules'; import { DeCompressFile } from '@/api/modules/files'; import { Mimetypes } from '@/global/mimetype'; import FileList from '@/components/file-list/index.vue'; diff --git a/frontend/src/views/host/file-management/download/index.vue b/frontend/src/views/host/file-management/download/index.vue index 1692de641..344b52738 100644 --- a/frontend/src/views/host/file-management/download/index.vue +++ b/frontend/src/views/host/file-management/download/index.vue @@ -36,7 +36,7 @@ import { CompressExtention, CompressType } from '@/enums/files'; import { computed, PropType, reactive, ref, toRefs } from 'vue'; import { DownloadFile } from '@/api/modules/files'; import { File } from '@/api/interface/file'; -import { Rules } from '@/global/form-rues'; +import { Rules } from '@/global/form-rules'; const props = defineProps({ open: { diff --git a/frontend/src/views/host/file-management/move/index.vue b/frontend/src/views/host/file-management/move/index.vue index ec7169ade..01cf0035b 100644 --- a/frontend/src/views/host/file-management/move/index.vue +++ b/frontend/src/views/host/file-management/move/index.vue @@ -27,7 +27,7 @@ diff --git a/frontend/src/views/setting/tabs/safe.vue b/frontend/src/views/setting/tabs/safe.vue index d35f5fafd..c5ad3783a 100644 --- a/frontend/src/views/setting/tabs/safe.vue +++ b/frontend/src/views/setting/tabs/safe.vue @@ -1,6 +1,6 @@