chore(auth): change char length limit of username to 1-50 (#4502)

This commit is contained in:
YANG QIA 2024-05-27 17:39:39 +08:00 committed by GitHub
parent 02ebede15a
commit 0adf5fb6b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 18 additions and 19 deletions

View File

@ -17,7 +17,6 @@ describe('base-auth', () => {
} as any); } as any);
expect(auth.validateUsername('')).toBe(false); expect(auth.validateUsername('')).toBe(false);
expect(auth.validateUsername('a')).toBe(false);
expect(auth.validateUsername('a@')).toBe(false); expect(auth.validateUsername('a@')).toBe(false);
expect(auth.validateUsername('a.')).toBe(false); expect(auth.validateUsername('a.')).toBe(false);
expect(auth.validateUsername('a<')).toBe(false); expect(auth.validateUsername('a<')).toBe(false);
@ -26,8 +25,8 @@ describe('base-auth', () => {
expect(auth.validateUsername('a/')).toBe(false); expect(auth.validateUsername('a/')).toBe(false);
expect(auth.validateUsername("a'")).toBe(false); expect(auth.validateUsername("a'")).toBe(false);
expect(auth.validateUsername('ab')).toBe(true); expect(auth.validateUsername('ab')).toBe(true);
// 16 characters // 50 characters
expect(auth.validateUsername('12345678910111213')).toBe(false); expect(auth.validateUsername('01234567890123456789012345678901234567890123456789a')).toBe(false);
}); });
it('check: should return null when no token', async () => { it('check: should return null when no token', async () => {

View File

@ -60,7 +60,7 @@ export class BaseAuth extends Auth {
* @internal * @internal
*/ */
validateUsername(username: string) { validateUsername(username: string) {
return /^[^@.<>"'/]{2,16}$/.test(username); return /^[^@.<>"'/]{1,50}$/.test(username);
} }
async check() { async check() {

View File

@ -15,7 +15,7 @@ import { CollectionFieldInterface } from '../../data-source/collection-field-int
registerValidateRules({ registerValidateRules({
username(value) { username(value) {
return /^[^@.<>"'/]{2,16}$/.test(value) || i18n.t('Must be 2-16 characters in length (excluding @.<>"\'/)'); return /^[^@.<>"'/]{1,50}$/.test(value) || i18n.t('Must be 1-50 characters in length (excluding @.<>"\'/)');
}, },
}); });

View File

@ -480,7 +480,7 @@
"Verification code": "인증 코드", "Verification code": "인증 코드",
"Send code": "코드 전송", "Send code": "코드 전송",
"Retry after {{count}} seconds": "{{count}} 초 후 재시도", "Retry after {{count}} seconds": "{{count}} 초 후 재시도",
"Must be 2-16 characters in length (excluding @.<>\"'/)": "2~16자여야 합니다 ( @.<>\"'/ 제외)", "Must be 1-50 characters in length (excluding @.<>\"'/)": "1~50자여야 합니다 ( @.<>\"'/ 제외)",
"Roles": "역할", "Roles": "역할",
"Add role": "역할 추가", "Add role": "역할 추가",
"Role name": "역할 이름", "Role name": "역할 이름",

View File

@ -483,7 +483,7 @@
"Verification code": "验证码", "Verification code": "验证码",
"Send code": "发送验证码", "Send code": "发送验证码",
"Retry after {{count}} seconds": "{{count}} 秒后重试", "Retry after {{count}} seconds": "{{count}} 秒后重试",
"Must be 2-16 characters in length (excluding @.<>\"'/)": "长度为2到16个字符(不能包含@.<>\"'/", "Must be 1-50 characters in length (excluding @.<>\"'/)": "长度为1到50个字符(不能包含@.<>\"'/",
"Roles": "角色", "Roles": "角色",
"Add role": "添加角色", "Add role": "添加角色",
"Role name": "角色名称", "Role name": "角色名称",
@ -847,7 +847,7 @@
"Filter out a single piece or a group of records as a template": "筛选出一条或一组数据,作为模板", "Filter out a single piece or a group of records as a template": "筛选出一条或一组数据,作为模板",
"The title field is used to identify the template record": "用于识别模板数据", "The title field is used to identify the template record": "用于识别模板数据",
"Template fields": "模板字段", "Template fields": "模板字段",
"The selected fields will automatically populate the form":"用于自动填充到表单", "The selected fields will automatically populate the form": "用于自动填充到表单",
"Table selected records": "表格中选中的记录", "Table selected records": "表格中选中的记录",
"Tag": "标签", "Tag": "标签",
"Tag color field": "标签颜色字段", "Tag color field": "标签颜色字段",
@ -937,8 +937,8 @@
"This variable has been deprecated and can be replaced with \"Current form\"": "该变量已被弃用,可以使用“当前表单”替代", "This variable has been deprecated and can be replaced with \"Current form\"": "该变量已被弃用,可以使用“当前表单”替代",
"Unknown field type": "未知字段类型", "Unknown field type": "未知字段类型",
"The following field types are not compatible and do not support output and display": "以下字段类型未适配,不支持输出和显示", "The following field types are not compatible and do not support output and display": "以下字段类型未适配,不支持输出和显示",
"Not fixed":"不固定", "Not fixed": "不固定",
"Left fixed":"左固定", "Left fixed": "左固定",
"Right fixed":"右固定", "Right fixed": "右固定",
"Fixed":"固定列" "Fixed": "固定列"
} }

View File

@ -208,7 +208,7 @@
"Actions": "動作", "Actions": "動作",
"Update": "更新", "Update": "更新",
"Update record": "更新資料", "Update record": "更新資料",
"Unnamed":"未命名", "Unnamed": "未命名",
"View": "檢視", "View": "檢視",
"View record": "檢視資料", "View record": "檢視資料",
"Refresh": "重新整理", "Refresh": "重新整理",
@ -232,7 +232,7 @@
"General collection": "普通資料表", "General collection": "普通資料表",
"SQL collection": "SQL資料表", "SQL collection": "SQL資料表",
"Connect to database view": "連線資料庫檢視", "Connect to database view": "連線資料庫檢視",
"Sync from database":"從資料庫同步", "Sync from database": "從資料庫同步",
"Source collections": "來源資料表", "Source collections": "來源資料表",
"Field source": "來源欄位", "Field source": "來源欄位",
"Preview": "預覽", "Preview": "預覽",
@ -480,7 +480,7 @@
"Verification code": "驗證碼", "Verification code": "驗證碼",
"Send code": "傳送驗證碼", "Send code": "傳送驗證碼",
"Retry after {{count}} seconds": "{{count}} 秒後重試", "Retry after {{count}} seconds": "{{count}} 秒後重試",
"Must be 2-16 characters in length (excluding @.<>\"'/)": "長度為2到16個字元(不能包含@.<>\"'/", "Must be 1-50 characters in length (excluding @.<>\"'/)": "長度為1到50個字元(不能包含@.<>\"'/",
"Roles": "角色", "Roles": "角色",
"Add role": "新增角色", "Add role": "新增角色",
"Role name": "角色名稱", "Role name": "角色名稱",
@ -858,12 +858,12 @@
"Sign in with another account": "登入其他帳號", "Sign in with another account": "登入其他帳號",
"Return to the main application": "返回主App", "Return to the main application": "返回主App",
"Permission denied": "沒有權限", "Permission denied": "沒有權限",
"Allow add new":"允許新增", "Allow add new": "允許新增",
"The {{type}} \"{{name}}\" may have been deleted. Please remove this {{blockType}}.": "{{type}} \"{{name}}\" 可能已被刪除,請移除這個 {{blockType}}。", "The {{type}} \"{{name}}\" may have been deleted. Please remove this {{blockType}}.": "{{type}} \"{{name}}\" 可能已被刪除,請移除這個 {{blockType}}。",
"data source": "數據源", "data source": "數據源",
"Data source": "數據源", "Data source": "數據源",
"DataSource": "數據源", "DataSource": "數據源",
"Allow selection of existing records":"允許選擇已有資料", "Allow selection of existing records": "允許選擇已有資料",
"Home page": "主頁", "Home page": "主頁",
"Handbook": "使用手冊", "Handbook": "使用手冊",
"License": "許可證", "License": "許可證",

View File

@ -56,7 +56,7 @@ const passwordForm: ISchema = {
return t("Please enter a valid email"); return t("Please enter a valid email");
} }
} else { } else {
return /^[^@.<>"'/]{2,16}$/.test(value) || t("Please enter a valid username"); return /^[^@.<>"'/]{1,50}$/.test(value) || t("Please enter a valid username");
} }
}}}`, }}}`,
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',

View File

@ -59,7 +59,7 @@ export class BasicAuth extends BaseAuth {
const User = ctx.db.getRepository('users'); const User = ctx.db.getRepository('users');
const { values } = ctx.action.params; const { values } = ctx.action.params;
const { username, password, confirm_password } = values; const { username, password, confirm_password } = values;
if (!/^[^@.<>"'/]{2,16}$/.test(username)) { if (!this.validateUsername(username)) {
ctx.throw(400, ctx.t('Please enter a valid username', { ns: namespace })); ctx.throw(400, ctx.t('Please enter a valid username', { ns: namespace }));
} }
if (!password) { if (!password) {