新增设置注册邮箱前缀最小位数

This commit is contained in:
eoao
2025-11-08 22:25:00 +08:00
parent a343a4a08f
commit 56b42d29b3
18 changed files with 192 additions and 43 deletions

View File

@@ -45,6 +45,7 @@ export const setting = sqliteTable('setting', {
customDomain: text('custom_domain').default('').notNull(),
tgMsgFrom: text('tg_msg_from').default('only-name').notNull(),
tgMsgTo: text('tg_msg_to').default('show').notNull(),
tgMsgText: text('tg_msg_text').default('hide').notNull()
tgMsgText: text('tg_msg_text').default('hide').notNull(),
minEmailPrefix: integer('min_email_prefix').default(0).notNull()
});
export default setting

View File

@@ -27,7 +27,8 @@ const en = {
notExistEmailReply: 'Mail does not exist and cannot be replied to',
pwdLengthLimit: 'Password length exceeds the limit',
emailLengthLimit: 'Email length exceeds the limit',
pwdMinLengthLimit: 'Password must be at least 6 characters',
minEmailPrefix: 'Email must be at least {{msg}} characters',
pwdMinLength: 'Password must be at least 6 characters',
notEmailDomain: 'Invalid email domain',
emptyRegKey: 'Invite code cannot be empty',
notExistRegKey: 'Invite code does not exist',

View File

@@ -25,6 +25,6 @@ i18next.init({
resources,
});
export const t = (key) => i18next.t(key)
export const t = (key, values) => i18next.t(key, values)
export default i18next;

View File

@@ -27,7 +27,8 @@ const zh = {
notExistEmailReply: '邮件不存在无法回复',
pwdLengthLimit: '密码长度超出限制',
emailLengthLimit: '邮箱长度超出限制',
pwdMinLengthLimit: '密码不能小于6位',
minEmailPrefix: '邮箱名不能小于{{msg}}位',
pwdMinLength: '密码不能小于6位',
notEmailDomain: '非法邮箱域名',
emptyRegKey: '注册码不能为空',
notExistRegKey: '注册码不存在',

View File

@@ -29,20 +29,31 @@ const init = {
},
async v2_4DB(c) {
await c.env.db.prepare(`
CREATE TABLE IF NOT EXISTS oauth (
oauth_id INTEGER PRIMARY KEY AUTOINCREMENT,
oauth_user_id TEXT,
username TEXT,
name TEXT,
avatar TEXT,
active INTEGER,
trust_level INTEGER,
silenced INTEGER,
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
user_id INTEGER NOT NULL DEFAULT 0
)
`).run();
try {
await c.env.db.prepare(`
CREATE TABLE IF NOT EXISTS oauth (
oauth_id INTEGER PRIMARY KEY AUTOINCREMENT,
oauth_user_id TEXT,
username TEXT,
name TEXT,
avatar TEXT,
active INTEGER,
trust_level INTEGER,
silenced INTEGER,
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
platform INTEGER NOT NULL DEFAULT 0,
user_id INTEGER NOT NULL DEFAULT 0
)
`).run();
} catch (e) {
console.error(e)
}
try {
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN min_email_prefix INTEGER NOT NULL DEFAULT 1;`).run();
} catch (e) {
console.error(e)
}
},
async v2_3DB(c) {
@@ -59,7 +70,7 @@ const init = {
}
try {
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN tg_msg_text TEXT NOT NULL DEFAULT 'hide';`).run();
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN tg_msg_text TEXT NOT NULL DEFAULT 'show';`).run();
} catch (e) {
console.error(e)
}

View File

@@ -17,7 +17,7 @@ const accountService = {
async add(c, params, userId) {
const {addEmailVerify , addEmail, manyEmail, addVerifyCount} = await settingService.query(c);
const {addEmailVerify , addEmail, manyEmail, addVerifyCount, minEmailPrefix} = await settingService.query(c);
let { email, token } = params;
@@ -39,6 +39,9 @@ const accountService = {
throw new BizError(t('notExistDomain'));
}
if (emailUtils.getName(email).length < minEmailPrefix) {
throw new BizError(t('minEmailPrefix', { msg: minEmailPrefix } ));
}
let accountRow = await this.selectByEmailIncludeDel(c, email);

View File

@@ -26,7 +26,7 @@ const loginService = {
const { email, password, token, code } = params;
let {regKey, register, registerVerify, regVerifyCount} = await settingService.query(c)
let {regKey, register, registerVerify, regVerifyCount, minEmailPrefix} = await settingService.query(c)
if (oauth) {
registerVerify = settingConst.registerVerify.CLOSE;
@@ -41,16 +41,20 @@ const loginService = {
throw new BizError(t('notEmail'));
}
if (emailUtils.getName(email).length < minEmailPrefix) {
throw new BizError(t('minEmailPrefix', { msg: minEmailPrefix } ));
}
if (emailUtils.getName(email).length > 64) {
throw new BizError(t('emailLengthLimit'));
}
if (password.length > 30) {
throw new BizError(t('pwdLengthLimit'));
}
if (emailUtils.getName(email).length > 30) {
throw new BizError(t('emailLengthLimit'));
}
if (password.length < 6) {
throw new BizError(t('pwdMinLengthLimit'));
throw new BizError(t('pwdMinLength'));
}
if (!c.env.domain.includes(emailUtils.getDomain(email))) {

View File

@@ -206,7 +206,8 @@ const settingService = {
loginDomain: settingRow.loginDomain,
linuxdoClientId: settingRow.linuxdoClientId,
linuxdoCallbackUrl: settingRow.linuxdoCallbackUrl,
linuxdoSwitch: settingRow.linuxdoSwitch
linuxdoSwitch: settingRow.linuxdoSwitch,
minEmailPrefix: settingRow.minEmailPrefix
};
}
};

View File

@@ -12,6 +12,7 @@ import emailMsgTemplate from '../template/email-msg';
import emailTextTemplate from '../template/email-text';
import emailHtmlTemplate from '../template/email-html';
import verifyUtils from '../utils/verify-utils';
import domainUtils from "../utils/domain-uitls";
const telegramService = {
@@ -50,7 +51,7 @@ const telegramService = {
const jwtToken = await jwtUtils.generateToken(c, { emailId: email.emailId })
const webAppUrl = verifyUtils.isDomain(customDomain) ? `https://${customDomain}/api/telegram/getEmail/${jwtToken}` : 'https://www.cloudflare.com/404'
const webAppUrl = customDomain ? `${domainUtils.toOssDomain(customDomain)}/api/telegram/getEmail/${jwtToken}` : 'https://www.cloudflare.com/404'
await Promise.all(tgChatIds.map(async chatId => {
try {

View File

@@ -53,7 +53,7 @@ const userService = {
const { password } = params;
if (password < 6) {
throw new BizError(t('pwdMinLengthLimit'));
throw new BizError(t('pwdMinLength'));
}
const { salt, hash } = await cryptoUtils.hashPassword(password);
await orm(c).update(user).set({ password: hash, salt: salt }).where(eq(user.userId, userId)).run();
@@ -304,7 +304,7 @@ const userService = {
}
if (password.length < 6) {
throw new BizError(t('pwdMinLengthLimit'));
throw new BizError(t('pwdMinLength'));
}
const accountRow = await accountService.selectByEmailIncludeDel(c, email);