diff --git a/server/.env b/server/.env index 0a54d33..be470c9 100644 --- a/server/.env +++ b/server/.env @@ -1,3 +1,4 @@ MONGODB_URI=mongodb://mongo_3y6JyM:mongo_iNySJ5@119.8.35.41:27017/license-manager?authSource=admin&retryWrites=true&w=majority PORT=3000 ENCRYPTION_KEY=f1e2d3c4b5a6978899aabbccddeeff00112233445566778899aabbccddeeff00 +MAX_USAGE_COUNT=10 \ No newline at end of file diff --git a/server/README.md b/server/README.md new file mode 100644 index 0000000..482c7c2 --- /dev/null +++ b/server/README.md @@ -0,0 +1,2 @@ +docker build --platform linux/amd64 -t ccz2/cursor-auth-server:latest . +docker push ccz2/cursor-auth-server:latest \ No newline at end of file diff --git a/server/models/License.js b/server/models/License.js index 0cf823e..5ca9230 100644 --- a/server/models/License.js +++ b/server/models/License.js @@ -22,6 +22,15 @@ const licenseSchema = new mongoose.Schema({ isActive: { type: Boolean, default: true + }, + maxUsageCount: { + type: Number, + required: true, + default: process.env.MAX_USAGE_COUNT || 10 // 默认允许使用100次 + }, + currentUsageCount: { + type: Number, + default: 0 } }); diff --git a/server/server.js b/server/server.js index cb68442..20bb512 100644 --- a/server/server.js +++ b/server/server.js @@ -76,7 +76,7 @@ mongoose.connection.on('disconnected', () => { }); // 定义一个复杂的路径,可以放在环境变量中 -const GENERATE_PATH = process.env.GENERATE_PATH || crypto.randomBytes(16).toString('hex'); +const GENERATE_PATH = process.env.GENERATE_PATH || 'xx-zz-yy-dd'; // 在应用启动时输出生成路径(仅在控制台显示一次) console.log('License generation path:', GENERATE_PATH); @@ -156,6 +156,16 @@ app.post('/activate', async (req, res) => { // 创建新的许可证并标记许可证密钥为已使用 const expiryDate = moment().add(1, 'month').toDate(); + + await License.create([{ + licenseKey: license_key, + machineCode: machine_code, + activationDate: activation_date || new Date(), + expiryDate: expiryDate, + isActive: true, + maxUsageCount: process.env.MAX_USAGE_COUNT || 10, // 如果未指定,默认为100次 + currentUsageCount: 0 + }]); // 更新许可证密钥状态为已使用 @@ -233,10 +243,26 @@ app.post('/verify', async (req, res) => { }); } + // 检查使用次数 + if (license.currentUsageCount >= license.maxUsageCount) { + return res.status(400).json({ + success: false, + message: '许可证使用次数已达到上限' + }); + } + + // 更新使用次数 + license.currentUsageCount += 1; + await license.save(); + return res.json({ success: true, message: '许可证有效', - expiry_date: license.expiryDate.toISOString().split('T')[0] + expiry_date: license.expiryDate.toISOString().split('T')[0], + usage_count: { + current: license.currentUsageCount, + max: license.maxUsageCount + } }); } catch (error) { console.error('验证错误:', error);