main
gzy 4 weeks ago
parent 07298bf405
commit 6ec58f694e

@ -6,7 +6,7 @@ export function login(username, password, captchaCode, uuid) {
let newPassword = encrypt(password)
const data = {
username,
newPassword,
password:newPassword,
captchaCode,
uuid
}

@ -18,8 +18,58 @@ const service = axios.create({
timeout: 30000
})
function stripObjectOfSpecialCharsAndCheck(obj,url) {
if(url == 'backendApi/login/doLogin'){
return true
}
// 定义要检查的特殊字符正则表达式
// const specialCharsRegex = /[<>"'%;()&+]/;
const specialCharsRegex = /[`~!@#$^&*()=|{}':;',\[\].<>/?~@#¥……&*()——|{}【】‘;:”“'。,、?]/
// 检查数组
if (Array.isArray(obj)) {
for (const item of obj) {
// 如果元素是字符串且包含特殊字符
if (typeof item === 'string' && specialCharsRegex.test(item)) {
return false; // 发现特殊字符立即返回false
}
// 如果元素是对象非null则递归检查
if (typeof item === 'object' && item !== null) {
if (!stripObjectOfSpecialCharsAndCheck(item)) {
return false; // 递归调用返回false则当前调用也返回false
}
}
}
// 数组中没有发现特殊字符,继续检查其他类型(尽管在这个函数中不会执行到这里,但为了清晰性)
} else if (typeof obj === 'object' && obj !== null) {
// 检查对象的每个属性
for (const key in obj) {
if (obj.hasOwnProperty(key)) { // 确保属性是对象自身的属性
const value = obj[key];
// 如果值是字符串且包含特殊字符
if (typeof value === 'string' && specialCharsRegex.test(value)) {
return false; // 发现特殊字符立即返回false
}
// 如果值是对象非null则递归检查
if (typeof value === 'object' && value !== null) {
if (!stripObjectOfSpecialCharsAndCheck(value)) {
return false; // 递归调用返回false则当前调用也返回false
}
}
}
}
// 对象中没有发现特殊字符
}
// 如果没有发现特殊字符包括所有嵌套的对象和数组则返回true
return true;
}
// request拦截器
service.interceptors.request.use(config => {
let isHave = stripObjectOfSpecialCharsAndCheck(config.data,config.url)
if(!isHave){
alert('禁止输入特殊符号')
return
}else{
// 是否需要防止数据重复提交
const isRepeatSubmit = (config.headers || {}).repeatSubmit === false
@ -60,6 +110,7 @@ service.interceptors.request.use(config => {
}
}
return config
}
}, error => {
console.log(error)
Promise.reject(error)

@ -83,8 +83,8 @@ export default {
codeUrl: "",
systemName : process.env.VUE_APP_TITLE,
loginForm: {
username: "fuint",
password: "123456",
username: "",
password: "",
rememberMe: false,
captchaCode: "",
uuid: ""

Loading…
Cancel
Save