25/09/24 10:00~11:30 停机维护
This commit is contained in:
@@ -8,7 +8,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
const email = document.getElementById('email').value;
|
||||
const password = document.getElementById('password').value;
|
||||
const confirmPassword = document.getElementById('confirm-password').value;
|
||||
|
||||
const u = validateLinuxUsername(username);
|
||||
if (!u.ok) {
|
||||
alert(u.error);
|
||||
return;
|
||||
}
|
||||
if (password !== confirmPassword) {
|
||||
alert('密码和确认密码不一致');
|
||||
return;
|
||||
@@ -36,4 +40,36 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
alert('注册失败');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// 校验 Linux 用户名
|
||||
function validateLinuxUsername(name) {
|
||||
// 基本字符规则:^[a-z_][a-z0-9_-]*[$]?$
|
||||
const basic = /^[a-z_][a-z0-9_-]*[$]?$/;
|
||||
|
||||
if (typeof name !== 'string' || name.length === 0) {
|
||||
return { ok: false, error: '用户名不能为空' };
|
||||
}
|
||||
// 长度限制(常见系统为 <= 32)
|
||||
if (name.length > 32) {
|
||||
return { ok: false, error: '用户名长度不能超过 32 个字符' };
|
||||
}
|
||||
if (!basic.test(name)) {
|
||||
return {
|
||||
ok: false,
|
||||
error:
|
||||
'用户名需以小写字母或下划线开头,仅包含小写字母、数字、下划线、连字符,允许以 $ 结尾'
|
||||
};
|
||||
}
|
||||
// 可选:避免纯数字用户名(多数系统不推荐)
|
||||
if (/^[0-9]+$/.test(name)) {
|
||||
return { ok: false, error: '用户名不能为纯数字' };
|
||||
}
|
||||
// 可选:避免使用保留名
|
||||
const reserved = new Set(['root', 'daemon', 'bin', 'sys', 'sync', 'games', 'man']);
|
||||
if (reserved.has(name)) {
|
||||
return { ok: false, error: '该用户名为系统保留名,请更换' };
|
||||
}
|
||||
|
||||
return { ok: true };
|
||||
}
|
||||
27
Html/apps/static/js/register_field_tip.js
Normal file
27
Html/apps/static/js/register_field_tip.js
Normal file
@@ -0,0 +1,27 @@
|
||||
(function () {
|
||||
let usernameInput = document.getElementById('username');
|
||||
if (!usernameInput){
|
||||
usernameInput = document.getElementById('teacher-username');
|
||||
}
|
||||
const tip = document.getElementById('username-tip');
|
||||
|
||||
function showTip() {
|
||||
tip.classList.add('is-visible');
|
||||
tip.setAttribute('aria-hidden', 'false');
|
||||
}
|
||||
function hideTip() {
|
||||
tip.classList.remove('is-visible');
|
||||
tip.setAttribute('aria-hidden', 'true');
|
||||
}
|
||||
|
||||
usernameInput.addEventListener('focus', showTip);
|
||||
usernameInput.addEventListener('blur', hideTip);
|
||||
|
||||
// 当用户点击提示框自身时不影响(比如复制文本)
|
||||
tip.addEventListener('mousedown', e => e.preventDefault());
|
||||
|
||||
// 可选:输入时也显示(防止因某些浏览器失焦导致闪烁)
|
||||
usernameInput.addEventListener('input', () => {
|
||||
if (document.activeElement === usernameInput) showTip();
|
||||
});
|
||||
})();
|
||||
@@ -8,7 +8,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
const email = document.getElementById('teacher-email').value;
|
||||
const password = document.getElementById('teacher-password').value;
|
||||
const confirmPassword = document.getElementById('teacher-confirm-password').value;
|
||||
|
||||
const u = validateLinuxUsername(username);
|
||||
if (!u.ok) {
|
||||
alert(u.error);
|
||||
return;
|
||||
}
|
||||
// 检查密码和确认密码是否一致
|
||||
if (password !== confirmPassword) {
|
||||
alert('密码和确认密码不一致');
|
||||
@@ -39,3 +43,35 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// 校验 Linux 用户名
|
||||
function validateLinuxUsername(name) {
|
||||
// 基本字符规则:^[a-z_][a-z0-9_-]*[$]?$
|
||||
const basic = /^[a-z_][a-z0-9_-]*[$]?$/;
|
||||
|
||||
if (typeof name !== 'string' || name.length === 0) {
|
||||
return { ok: false, error: '用户名不能为空' };
|
||||
}
|
||||
// 长度限制(常见系统为 <= 32)
|
||||
if (name.length > 32) {
|
||||
return { ok: false, error: '用户名长度不能超过 32 个字符' };
|
||||
}
|
||||
if (!basic.test(name)) {
|
||||
return {
|
||||
ok: false,
|
||||
error:
|
||||
'用户名需以小写字母或下划线开头,仅包含小写字母、数字、下划线、连字符,允许以 $ 结尾'
|
||||
};
|
||||
}
|
||||
// 可选:避免纯数字用户名(多数系统不推荐)
|
||||
if (/^[0-9]+$/.test(name)) {
|
||||
return { ok: false, error: '用户名不能为纯数字' };
|
||||
}
|
||||
// 可选:避免使用保留名
|
||||
const reserved = new Set(['root', 'daemon', 'bin', 'sys', 'sync', 'games', 'man']);
|
||||
if (reserved.has(name)) {
|
||||
return { ok: false, error: '该用户名为系统保留名,请更换' };
|
||||
}
|
||||
|
||||
return { ok: true };
|
||||
}
|
||||
Reference in New Issue
Block a user