mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-07 16:37:04 +08:00
feat: support admin api bind address to user (#630)
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
- fix: |CleanUP| 修复清理邮件时,清理时间超过 30 天报错的 bug
|
- fix: |CleanUP| 修复清理邮件时,清理时间超过 30 天报错的 bug
|
||||||
- feat: admin 用户管理页面: 增加 用户地址查看功能
|
- feat: admin 用户管理页面: 增加 用户地址查看功能
|
||||||
- feat: | S3 附件| 增加 S3 附件删除功能
|
- feat: | S3 附件| 增加 S3 附件删除功能
|
||||||
|
- feat: | Admin API| 增加 admin 绑定用户和地址的 api
|
||||||
|
|
||||||
## v0.9.0
|
## v0.9.0
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { getJsonSetting, saveSetting, checkUserPassword, getDomains, getUserRole
|
|||||||
import { UserSettings, GeoData, UserInfo } from "../models";
|
import { UserSettings, GeoData, UserInfo } from "../models";
|
||||||
import { handleListQuery } from '../common'
|
import { handleListQuery } from '../common'
|
||||||
import { HonoCustomType } from '../types';
|
import { HonoCustomType } from '../types';
|
||||||
|
import UserBindAddressModule from '../user_api/bind_address';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getSetting: async (c: Context<HonoCustomType>) => {
|
getSetting: async (c: Context<HonoCustomType>) => {
|
||||||
@@ -144,22 +145,12 @@ export default {
|
|||||||
}
|
}
|
||||||
return c.json({ success: true })
|
return c.json({ success: true })
|
||||||
},
|
},
|
||||||
|
bindAddress: async (c: Context<HonoCustomType>) => {
|
||||||
|
const { user_id, address_id } = await c.req.json();
|
||||||
|
return await UserBindAddressModule.bindByID(c, user_id, address_id);
|
||||||
|
},
|
||||||
getBindedAddresses: async (c: Context<HonoCustomType>) => {
|
getBindedAddresses: async (c: Context<HonoCustomType>) => {
|
||||||
const { user_id } = c.req.param();
|
const { user_id } = c.req.param();
|
||||||
if (!user_id) return c.text("Invalid user_id", 400);
|
return await UserBindAddressModule.getBindedAddressesById(c, user_id);
|
||||||
// select binded address
|
|
||||||
const { results } = await c.env.DB.prepare(
|
|
||||||
`SELECT a.*,`
|
|
||||||
+ ` (SELECT COUNT(*) FROM raw_mails WHERE address = a.name) AS mail_count,`
|
|
||||||
+ ` (SELECT COUNT(*) FROM sendbox WHERE address = a.name) AS send_count`
|
|
||||||
+ ` FROM address a `
|
|
||||||
+ ` JOIN users_address ua `
|
|
||||||
+ ` ON ua.address_id = a.id `
|
|
||||||
+ ` WHERE ua.user_id = ?`
|
|
||||||
+ ` ORDER BY a.id DESC`
|
|
||||||
).bind(user_id).all();
|
|
||||||
return c.json({
|
|
||||||
results: results,
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -328,6 +328,7 @@ api.post('/admin/users/:user_id/reset_password', admin_user_api.resetPassword)
|
|||||||
api.get('/admin/user_roles', async (c) => c.json(getUserRoles(c)))
|
api.get('/admin/user_roles', async (c) => c.json(getUserRoles(c)))
|
||||||
api.post('/admin/user_roles', admin_user_api.updateUserRoles)
|
api.post('/admin/user_roles', admin_user_api.updateUserRoles)
|
||||||
api.get('/admin/users/bind_address/:user_id', admin_user_api.getBindedAddresses)
|
api.get('/admin/users/bind_address/:user_id', admin_user_api.getBindedAddresses)
|
||||||
|
api.post('/admin/users/bind_address', admin_user_api.bindAddress)
|
||||||
|
|
||||||
// user oauth2 settings
|
// user oauth2 settings
|
||||||
api.get('/admin/user_oauth2_settings', oauth2_settings.getUserOauth2Settings)
|
api.get('/admin/user_oauth2_settings', oauth2_settings.getUserOauth2Settings)
|
||||||
|
|||||||
@@ -7,10 +7,16 @@ import { getJsonSetting } from "../utils"
|
|||||||
import { CONSTANTS } from "../constants";
|
import { CONSTANTS } from "../constants";
|
||||||
import { unbindTelegramByAddress } from '../telegram_api/common';
|
import { unbindTelegramByAddress } from '../telegram_api/common';
|
||||||
|
|
||||||
export default {
|
const UserBindAddressModule = {
|
||||||
bind: async (c: Context<HonoCustomType>) => {
|
bind: async (c: Context<HonoCustomType>) => {
|
||||||
const { user_id } = c.get("userPayload");
|
const { user_id } = c.get("userPayload");
|
||||||
const { address_id } = c.get("jwtPayload");
|
const { address_id } = c.get("jwtPayload");
|
||||||
|
return await UserBindAddressModule.bindByID(c, user_id, address_id)
|
||||||
|
},
|
||||||
|
bindByID: async (
|
||||||
|
c: Context<HonoCustomType>,
|
||||||
|
user_id: number | string, address_id: number | string
|
||||||
|
) => {
|
||||||
if (!address_id || !user_id) {
|
if (!address_id || !user_id) {
|
||||||
return c.text("No address or user token", 400)
|
return c.text("No address or user token", 400)
|
||||||
}
|
}
|
||||||
@@ -96,6 +102,11 @@ export default {
|
|||||||
},
|
},
|
||||||
getBindedAddresses: async (c: Context<HonoCustomType>) => {
|
getBindedAddresses: async (c: Context<HonoCustomType>) => {
|
||||||
const { user_id } = c.get("userPayload");
|
const { user_id } = c.get("userPayload");
|
||||||
|
return await UserBindAddressModule.getBindedAddressesById(c, user_id);
|
||||||
|
},
|
||||||
|
getBindedAddressesById: async (
|
||||||
|
c: Context<HonoCustomType>, user_id: number | string
|
||||||
|
) => {
|
||||||
if (!user_id) {
|
if (!user_id) {
|
||||||
return c.text("No user token", 400)
|
return c.text("No user token", 400)
|
||||||
}
|
}
|
||||||
@@ -229,3 +240,5 @@ export default {
|
|||||||
return c.json({ success: true })
|
return c.json({ success: true })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default UserBindAddressModule;
|
||||||
|
|||||||
Reference in New Issue
Block a user