mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 21:49:25 +08:00
chore(auth): change char length limit of username to 1-50 (#4502)
This commit is contained in:
parent
02ebede15a
commit
0adf5fb6b7
@ -17,7 +17,6 @@ describe('base-auth', () => {
|
||||
} as any);
|
||||
|
||||
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);
|
||||
@ -26,8 +25,8 @@ describe('base-auth', () => {
|
||||
expect(auth.validateUsername('a/')).toBe(false);
|
||||
expect(auth.validateUsername("a'")).toBe(false);
|
||||
expect(auth.validateUsername('ab')).toBe(true);
|
||||
// 16 characters
|
||||
expect(auth.validateUsername('12345678910111213')).toBe(false);
|
||||
// 50 characters
|
||||
expect(auth.validateUsername('01234567890123456789012345678901234567890123456789a')).toBe(false);
|
||||
});
|
||||
|
||||
it('check: should return null when no token', async () => {
|
||||
|
@ -60,7 +60,7 @@ export class BaseAuth extends Auth {
|
||||
* @internal
|
||||
*/
|
||||
validateUsername(username: string) {
|
||||
return /^[^@.<>"'/]{2,16}$/.test(username);
|
||||
return /^[^@.<>"'/]{1,50}$/.test(username);
|
||||
}
|
||||
|
||||
async check() {
|
||||
|
@ -15,7 +15,7 @@ import { CollectionFieldInterface } from '../../data-source/collection-field-int
|
||||
|
||||
registerValidateRules({
|
||||
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 @.<>"\'/)');
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -480,7 +480,7 @@
|
||||
"Verification code": "인증 코드",
|
||||
"Send code": "코드 전송",
|
||||
"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": "역할",
|
||||
"Add role": "역할 추가",
|
||||
"Role name": "역할 이름",
|
||||
|
@ -483,7 +483,7 @@
|
||||
"Verification code": "验证码",
|
||||
"Send code": "发送验证码",
|
||||
"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": "角色",
|
||||
"Add role": "添加角色",
|
||||
"Role name": "角色名称",
|
||||
|
@ -480,7 +480,7 @@
|
||||
"Verification code": "驗證碼",
|
||||
"Send code": "傳送驗證碼",
|
||||
"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": "角色",
|
||||
"Add role": "新增角色",
|
||||
"Role name": "角色名稱",
|
||||
|
@ -56,7 +56,7 @@ const passwordForm: ISchema = {
|
||||
return t("Please enter a valid email");
|
||||
}
|
||||
} 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',
|
||||
|
@ -59,7 +59,7 @@ export class BasicAuth extends BaseAuth {
|
||||
const User = ctx.db.getRepository('users');
|
||||
const { values } = ctx.action.params;
|
||||
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 }));
|
||||
}
|
||||
if (!password) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user