fix: token 改用 CSPRNG,手机号唯一,微信接口加超时
genToken 由 sha256(uid+时间+Math.random) 改为 randomBytes(32);profile.mobile 加唯一索引并在撞号时给出明确提示;注册并发改为依赖唯一索引兜底;登录失败文案不再区分账号是否存在;微信接口统一 8 秒超时;服务器错误只回通用文案。
This commit is contained in:
+9
-10
@@ -15,7 +15,9 @@ const UserSchema = mongoose.Schema(
|
||||
name: { type: String, comment: '用户姓名' },
|
||||
pinyin: { type: String, default: '', comment: '姓名的拼音,用于搜索' },
|
||||
pinyinFL: { type: String, default: '', comment: '姓名拼音的首字母,用于搜索' },
|
||||
mobile: { type: String, index: true, trim: true, comment: '手机号码' },
|
||||
// 手机号既用于登录,也是账号识别键:必须全局唯一,
|
||||
// 否则并发注册可能产生两个同号账号,登录结果不确定
|
||||
mobile: { type: String, index: true, unique: true, sparse: true, trim: true, comment: '手机号码' },
|
||||
email: { type: String, index: true, trim: true, unique: true, sparse: true, comment: '电子邮箱' },
|
||||
idnumber: { type: String, index: true, trim: true, unique: true, sparse: true, comment: '身份证号码' },
|
||||
ssn: { type: String, index: true, trim: true, unique: true, sparse: true, comment: '社保卡号' },
|
||||
@@ -172,15 +174,12 @@ UserSchema.statics.updateFromUserInfo = async function (userId, userInfo) {
|
||||
updateData['addresses'] = userInfo.addresses;
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.findOneAndUpdate(
|
||||
{ _id: userId },
|
||||
{ $set: updateData },
|
||||
{ new: true, upsert: false }
|
||||
);
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
// 保留原有异常:唯一索引冲突(手机号撞号)需要由 handler 给出明确提示
|
||||
return await this.findOneAndUpdate(
|
||||
{ _id: userId },
|
||||
{ $set: updateData },
|
||||
{ new: true, upsert: false, runValidators: true }
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user