This commit is contained in:
张成
2025-12-19 23:02:15 +08:00
parent 10aff2f266
commit 8f6e7e7a97
3 changed files with 171 additions and 39 deletions

View File

@@ -339,6 +339,7 @@ module.exports = {
try {
const body = ctx.getBody();
const { email, password, email_code, invite_code } = body;
const { hashPassword, maskEmail } = require('../utils/crypto_utils');
// 验证必填参数
if (!email || !password || !email_code) {
@@ -352,8 +353,8 @@ module.exports = {
}
// 验证密码长度
if (password.length < 6) {
return ctx.fail('密码长度不能少于6位');
if (password.length < 6 || password.length > 50) {
return ctx.fail('密码长度必须在6-50位之间');
}
// 统一邮箱地址为小写
@@ -403,14 +404,17 @@ module.exports = {
// 生成设备SN码基于邮箱和时间戳
const sn_code = `SN${Date.now()}${Math.random().toString(36).substr(2, 6).toUpperCase()}`;
// 创建新用户(使用统一的小写邮箱)
// 加密密码
const hashedPassword = await hashPassword(password);
// 创建新用户(使用统一的小写邮箱和加密密码)
const newUser = await pla_account.create({
name: email_normalized.split('@')[0], // 默认使用邮箱用户名作为名称
sn_code: sn_code,
device_id: '', // 设备ID由客户端登录时提供
platform_type: 'boss', // 默认平台类型
login_name: email_normalized,
pwd: password,
pwd: hashedPassword, // 使用加密后的密码
keyword: '',
is_enabled: 1,
is_delete: 0,
@@ -465,9 +469,9 @@ module.exports = {
is_delete: 0
});
console.log(`[邀请注册] 用户 ${email_normalized} 通过邀请码 ${invite_code} 注册成功,邀请人 ${inviter.sn_code} 获得3天试用期`);
console.log(`[邀请注册] 用户 ${maskEmail(email_normalized)} 通过邀请码 ${invite_code} 注册成功,邀请人 ${inviter.sn_code} 获得3天试用期`);
} else {
console.log(`[邀请注册] 用户 ${email_normalized} 注册成功(无邀请码)`);
console.log(`[邀请注册] 用户 ${maskEmail(email_normalized)} 注册成功(无邀请码)`);
}
return ctx.success({