66 lines
2.4 KiB
JavaScript
66 lines
2.4 KiB
JavaScript
/*
|
|
Copyright (C) 2025 QuantumNous
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
|
|
// 企业管理员(Owner)登录名的前置校验,与后端 controller.normalizeOrgOwnerLoginName /
|
|
// common.OrgDirectLoginNameDenylist 保持一致。管理员登录名不再默认 admin——默认名让所有企业的
|
|
// 管理员账号高度可预测(扩大撞库面),且 admin 命中直登黑名单,管理员反而用不了「账号直登」。
|
|
// 前端只做同款前置提示,后端仍是唯一裁决方。
|
|
|
|
/** 3-32 位,字母开头,仅字母/数字/下划线/点/短横线。 */
|
|
export const LOGIN_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_.-]{2,31}$/;
|
|
|
|
/** 保留登录名黑名单(与后端 common.OrgDirectLoginNameDenylist 逐项对齐)。 */
|
|
export const RESERVED_LOGIN_NAMES = [
|
|
'admin',
|
|
'administrator',
|
|
'root',
|
|
'test',
|
|
'user',
|
|
'guest',
|
|
'system',
|
|
'manager',
|
|
'owner',
|
|
'operator',
|
|
'sa',
|
|
'superadmin',
|
|
];
|
|
|
|
/** 是否命中保留名(大小写不敏感、去空格,与后端同口径)。 */
|
|
export function isReservedLoginName(name) {
|
|
return RESERVED_LOGIN_NAMES.includes(
|
|
String(name || '')
|
|
.trim()
|
|
.toLowerCase(),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 校验企业管理员登录名,返回 null 表示通过,否则返回未翻译的错误文案 key。
|
|
* 调用方自行 t() —— 文案与 OrgRegister 表单规则、后端错误文案三处一致。
|
|
*/
|
|
export function validateOrgOwnerLoginName(name) {
|
|
const value = String(name || '').trim();
|
|
if (!value) return '请设置管理员登录名';
|
|
if (!LOGIN_NAME_PATTERN.test(value))
|
|
return '登录名需为 3-32 位,以字母开头,仅可包含字母、数字、下划线、点或短横线';
|
|
if (isReservedLoginName(value))
|
|
return '该登录名为系统保留名称,请换一个登录名';
|
|
return null;
|
|
}
|