- 创建统一的下载错误处理模块 (lib/download-errors.ts) - 实现13种错误类型分类和中文错误消息 - 后端统一使用 createDownloadError 创建标准化错误响应 - 前端统一使用 parseDownloadError 解析错误并显示 - 修复正式系统数据库Schema,添加产品全案相关字段和表 - 执行数据库迁移:添加 task_no, task_status, task_fetched_at 字段 - 创建 material_assets, api_keys, api_call_logs 表
88 lines
2.4 KiB
TypeScript
88 lines
2.4 KiB
TypeScript
/**
|
||
* 激活用户账户的脚本
|
||
* 使用方法: npx tsx scripts/activate-user.ts <用户名或邮箱>
|
||
*/
|
||
|
||
import { PrismaClient } from '@prisma/client';
|
||
|
||
const prisma = new PrismaClient();
|
||
|
||
async function activateUser(identifier: string) {
|
||
console.log(`\n=== 激活用户: ${identifier} ===\n`);
|
||
|
||
try {
|
||
// 查找用户(支持用户名或邮箱)
|
||
const user = await prisma.user.findFirst({
|
||
where: {
|
||
OR: [
|
||
{ username: identifier },
|
||
{ email: identifier },
|
||
],
|
||
},
|
||
select: {
|
||
id: true,
|
||
username: true,
|
||
email: true,
|
||
realName: true,
|
||
isActive: true,
|
||
role: true,
|
||
department: true,
|
||
createdAt: true,
|
||
},
|
||
});
|
||
|
||
if (!user) {
|
||
console.error(`❌ 未找到用户: ${identifier}`);
|
||
console.log('\n提示: 请检查用户名或邮箱是否正确');
|
||
return;
|
||
}
|
||
|
||
console.log('📋 用户信息:');
|
||
console.log(' - ID:', user.id);
|
||
console.log(' - 用户名:', user.username);
|
||
console.log(' - 邮箱:', user.email);
|
||
console.log(' - 真实姓名:', user.realName || '(未设置)');
|
||
console.log(' - 当前状态:', user.isActive ? '✅ 已激活' : '❌ 未激活');
|
||
console.log(' - 角色:', user.role);
|
||
console.log(' - 部门:', user.department || '(未设置)');
|
||
console.log(' - 创建时间:', user.createdAt.toLocaleString('zh-CN'));
|
||
|
||
if (user.isActive) {
|
||
console.log('\n✅ 用户已经是激活状态,无需操作');
|
||
return;
|
||
}
|
||
|
||
// 确认激活
|
||
console.log('\n⚠️ 准备激活该用户...');
|
||
|
||
// 更新用户状态
|
||
await prisma.user.update({
|
||
where: { id: user.id },
|
||
data: { isActive: true },
|
||
});
|
||
|
||
console.log('\n✅ 用户已成功激活!');
|
||
console.log(' 现在该用户可以使用钉钉登录系统了');
|
||
|
||
} catch (error) {
|
||
console.error('\n❌ 激活用户时出错:', error);
|
||
if (error instanceof Error) {
|
||
console.error('错误信息:', error.message);
|
||
}
|
||
} finally {
|
||
await prisma.$disconnect();
|
||
}
|
||
}
|
||
|
||
// 执行激活
|
||
const identifier = process.argv[2];
|
||
if (!identifier) {
|
||
console.error('❌ 请提供用户名或邮箱');
|
||
console.log('\n使用方法: npx tsx scripts/activate-user.ts <用户名或邮箱>');
|
||
console.log('示例: npx tsx scripts/activate-user.ts 玄女');
|
||
process.exit(1);
|
||
}
|
||
|
||
activateUser(identifier);
|
||
|