修复注册码权限无效bug

This commit is contained in:
eoao
2025-07-22 23:33:46 +08:00
parent bbcff4908d
commit 7267f03482
23 changed files with 115 additions and 112 deletions

View File

@@ -66,8 +66,8 @@ export async function email(message, env, ctx) {
if (banEmailType === roleConst.banEmailType.ALL) return
if (banEmailType === roleConst.banEmailType.CONTENT) {
email.html = 'removed'
email.text = 'removed'
email.html = 'messageRemoved'
email.text = 'messageRemoved'
email.attachments = []
}
@@ -80,8 +80,8 @@ export async function email(message, env, ctx) {
if (banEmailType === roleConst.banEmailType.ALL) return
if (banEmailType === roleConst.banEmailType.CONTENT) {
email.html = 'removed'
email.text = 'removed'
email.html = 'messageRemoved'
email.text = 'messageRemoved'
email.attachments = []
}

View File

@@ -1,23 +1,22 @@
const en = {
IncorrectPwd: 'Incorrect password',
addAccountDisabled: 'Add email account function is disabled',
addAccountDisabled: 'Add account feature is disabled',
regDisabled: 'Sign up is disabled',
emptyEmail: 'Email cannot be empty',
notEmail: 'Invalid email',
notExistDomain: 'Email domain does not exist',
isDelAccount: 'This Email has been deleted',
isRegAccount: 'This Email is already signed up',
accountLimit: 'Email account limit reached',
delMyAccount: 'Cannot delete your own email account',
accountLimit: 'Account limit reached',
delMyAccount: 'Cannot delete your own account',
noUserAccount: 'This email does not belong to the current user',
usernameLengthLimit: 'Username length exceeds the limit',
noOsDomainSendPic: 'Cannot send body images: R2 domain not configured',
noOsSendPic: 'Cannot send body images: R2 object storage not configured',
noOsDomainSendAtt: 'Cannot send attachments: R2 domain not configured',
noOsSendAtt: 'Cannot send attachments: R2 object storage not configured',
disabledSend: 'Email sending is disabled',
disabledSend: 'Email sending feature is disabled',
noSeparateSend: 'Attachments are not supported in separate sending',
userNoSendTotal: 'User has no remaining sends',
daySendLimit: 'Daily send limit reached',
totalSendLimit: 'Total send limit reached',
daySendLack: 'Not enough remaining sends today',
@@ -53,6 +52,7 @@ const en = {
botVerifyFail: 'Bot verification failed, please try again',
authExpired: 'Authentication expired, please log in again',
unauthorized: 'Unauthorized',
bannedSend: 'You are banned from sending emails',
perms: {
"邮件": "Email",
"邮件发送": "Send email",

View File

@@ -4,7 +4,7 @@ import en from './en.js'
import app from '../hono/hono';
app.use('*', async (c, next) => {
const lang = c.req.header('accept-language').split('-')[0]
const lang = c.req.header('accept-language')?.split('-')[0]
i18next.init({
lng: lang,
});

View File

@@ -17,7 +17,6 @@ const zh = {
noOsSendAtt: 'r2对象存储未配置不能发送附件',
disabledSend: '邮件发送功能已停用',
noSeparateSend: '分别发送暂时不支持附件',
userNoSendTotal: '用户无发送次数',
daySendLimit: '发送次数已到达每日限制',
totalSendLimit: '发送次数已到达限制',
daySendLack: '当日剩余发送次数不足',
@@ -53,6 +52,7 @@ const zh = {
botVerifyFail: '人机验证失败,请重试',
authExpired: '身份认证失效,请重新登录',
unauthorized: '权限不足',
bannedSend: '你已被禁止发送邮件',
perms: {
"邮件": "邮件",
"邮件发送": "邮件发送",
@@ -65,7 +65,7 @@ const zh = {
"用户注销": "用户注销",
"分析页": "分析页",
"数据查看": "数据查看",
"用户信息": "用户信息",
"用户信息": "用户列表",
"用户查看": "用户查看",
"用户添加": "用户添加",
"密码修改": "密码修改",

View File

@@ -237,8 +237,8 @@ const init = {
(25, '用户添加', 'user:add', 6, 2, 1),
(26, '发件重置', 'user:reset-send', 6, 2, 6),
(27, '邮件列表', '', 0, 1, 4),
(28, '邮件查看', 'sys-email:query', 27, 2, 0),
(29, '邮件删除', 'sys-email:delete', 27, 2, 0),
(28, '邮件查看', 'all-email:query', 27, 2, 0),
(29, '邮件删除', 'all-email:delete', 27, 2, 0),
(30, '身份添加', 'role:add', 13, 2, -1)
`).run();
}
@@ -385,7 +385,7 @@ const init = {
INSERT INTO setting (
register, receive, add_email, many_email, title, auto_refresh_time, register_verify, add_email_verify
)
SELECT 0, 0, 0, 1, 'Cloud 邮箱', 0, 1, 1
SELECT 0, 0, 0, 1, 'Cloud Mail', 0, 1, 1
WHERE NOT EXISTS (SELECT 1 FROM setting)
`).run();
},

View File

@@ -74,9 +74,9 @@ const premKey = {
'setting:set': ['/setting/set', '/setting/setBackground'],
'setting:clean': ['/setting/physicsDeleteAll'],
'analysis:query': ['/analysis/echarts'],
'role-key:add': ['/regKey/add'],
'role-key:query': ['/regKey/list','/regKey/history'],
'role-key:delete': ['/regKey/delete','/regKey/clearNotUse'],
'reg-key:add': ['/regKey/add'],
'reg-key:query': ['/regKey/list','/regKey/history'],
'reg-key:delete': ['/regKey/delete','/regKey/clearNotUse'],
};
app.use('*', async (c, next) => {
@@ -126,6 +126,7 @@ app.use('*', async (c, next) => {
const userPaths = permKeyToPaths(permKeys);
const userPermIndex = userPaths.findIndex(item => {
console.log(item)
return path.startsWith(item);
});

View File

@@ -134,6 +134,31 @@ const emailService = {
let { attDataList, html } = await attService.toImageUrlHtml(c, content, r2Domain);
if (send === settingConst.send.CLOSE) {
throw new BizError(t('disabledSend'), 403);
}
const userRow = await userService.selectById(c, userId);
const roleRow = await roleService.selectById(c, userRow.type);
if (roleRow.sendType === 'ban') {
throw new BizError(t('bannedSend'), 403);
}
if (c.env.admin !== userRow.email && roleRow.sendCount) {
if (userRow.sendCount >= roleRow.sendCount) {
if (roleRow.sendType === 'day') throw new BizError(t('daySendLimit'), 403);
if (roleRow.sendType === 'count') throw new BizError(t('totalSendLimit'), 403);
}
if (userRow.sendCount + receiveEmail.length > roleRow.sendCount) {
if (roleRow.sendType === 'day') throw new BizError(t('daySendLack'), 403);
if (roleRow.sendType === 'count') throw new BizError(t('totalSendLack'), 403);
}
}
if (attDataList.length > 0 && !r2Domain) {
throw new BizError(t('noOsDomainSendPic'));
}
@@ -150,37 +175,11 @@ const emailService = {
throw new BizError(t('noOsSendAtt'));
}
if (send === settingConst.send.CLOSE) {
throw new BizError(t('disabledSend'), 403);
}
if (attachments.length > 0 && manyType === 'divide') {
throw new BizError(t('noSeparateSend'));
}
const userRow = await userService.selectById(c, userId);
const roleRow = await roleService.selectById(c, userRow.type);
if (c.env.admin !== userRow.email && roleRow.sendCount) {
if (roleRow.sendCount < 0) {
throw new BizError(t('userNoSendTotal'), 403);
}
if (userRow.sendCount >= roleRow.sendCount) {
if (roleRow.sendType === 'day') throw new BizError(t('daySendLimit'), 403);
if (roleRow.sendType === 'count') throw new BizError(t('totalSendLimit'), 403);
}
if (userRow.sendCount + receiveEmail.length > roleRow.sendCount) {
if (roleRow.sendType === 'day') throw new BizError(t('daySendLack'), 403);
if (roleRow.sendType === 'count') throw new BizError(t('totalSendLack'), 403);
}
}
const accountRow = await accountService.selectById(c, accountId);
if (!accountRow) {
@@ -272,8 +271,7 @@ const emailService = {
if (error) {
console.error(error);
throw new BizError(error.message);
throw new BizError(error.error);
}
html = this.imgReplace(html, null, r2Domain);

View File

@@ -7,7 +7,7 @@ const resendService = {
async webhooks(c, body) {
const params = {}
console.error(body)
if (body.type === 'email.delivered') {
params.status = emailConst.status.DELIVERED
params.resendEmailId = body.data.email_id