Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (!phone) {
throw new Meteor.Error(403, "accounts_phone_invalid");
}
var userId = this.userId;
if (!userId) {
// Get user by phone number
var userOptions = {
'phone.number': phone
};
if (checkVerified) {
userOptions['phone.verified'] = true;
}
var existingUser = Meteor.users.findOne(userOptions, {
fields: {
'_id': 1
}
});
if (existingUser) {
userId = existingUser && existingUser._id;
} else {
// Create new user with phone number
// userId = createUser({phone:phone});
// 暂时不允许通过手机创建新账户,因为可能会跟没有配置手机号的老账户冲突
var errMsg = TAPi18n.__('accounts_phone_user_not_found', {}, locale);
var newNumber;
db.users.validatePhone(userId, doc, modifier);
if (modifier.$unset && modifier.$unset.steedos_id === "") {
throw new Meteor.Error(400, "users_error_steedos_id_required");
}
modifier.$set = modifier.$set || {};
if (modifier.$set.username) {
db.users.validateUsername(modifier.$set.username, doc._id);
}
// if doc.steedos_id && modifier.$set.steedos_id
// if modifier.$set.steedos_id != doc.steedos_id
// throw new Meteor.Error(400, "users_error_steedos_id_readonly");
if (userId) {
modifier.$set.modified_by = userId;
}
if (modifier.$set['phone.verified'] === true) {
newNumber = modifier.$set['phone.mobile'];
if (!newNumber) {
newNumber = doc.phone.mobile;
}
modifier.$set.mobile = newNumber;
}
return modifier.$set.modified = new Date();
});
db.users.after.update(function (userId, doc, fieldNames, modifier, options) {
phone = normalizePhone(phone);
}
if (!phone) {
throw new Meteor.Error(403, "accounts_phone_invalid");
}
var userId = this.userId;
if (!userId) {
// Get user by phone number
var userOptions = {
'phone.number': phone,
};
if(checkVerified){
userOptions['phone.verified'] = true;
}
var existingUser = Meteor.users.findOne(userOptions, {
fields: {
'_id': 1
}
});
if (existingUser) {
userId = existingUser && existingUser._id;
} else {
// Create new user with phone number
// userId = createUser({phone:phone});
// 暂时不允许通过手机创建新账户,因为可能会跟没有配置手机号的老账户冲突
var errMsg = TAPi18n.__('accounts_phone_user_not_found', {}, locale);
throw new Meteor.Error(403, errMsg);
}
db.users.validatePhone = function (userId, doc, modifier) {
modifier.$set = modifier.$set || {};
if (doc._id !== userId && modifier.$set["phone.number"]) {
if (doc["phone.verified"] === true && doc["phone.number"] !== modifier.$set["phone.number"]) {
throw new Meteor.Error(400, "用户已验证手机,不能修改");
}
}
};
db.users.before.insert(function (userId, doc) {