|
|
@ -248,23 +248,22 @@ User.addInterstitials = function (callback) {
|
|
|
|
data: { email },
|
|
|
|
data: { email },
|
|
|
|
callback: async (userData, formData) => {
|
|
|
|
callback: async (userData, formData) => {
|
|
|
|
// Validate and send email confirmation
|
|
|
|
// Validate and send email confirmation
|
|
|
|
if (formData.email && formData.email.length) {
|
|
|
|
if (userData.uid) {
|
|
|
|
if (!utils.isEmailValid(formData.email)) {
|
|
|
|
const [isAdminOrGlobalMod, canEdit] = await Promise.all([
|
|
|
|
throw new Error('[[error:invalid-email]]');
|
|
|
|
User.isAdminOrGlobalMod(data.req.uid),
|
|
|
|
}
|
|
|
|
privileges.users.canEdit(data.req.uid, userData.uid),
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (formData.email && formData.email.length) {
|
|
|
|
|
|
|
|
if (!utils.isEmailValid(formData.email)) {
|
|
|
|
|
|
|
|
throw new Error('[[error:invalid-email]]');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (userData.uid) {
|
|
|
|
|
|
|
|
const current = await User.getUserField(userData.uid, 'email');
|
|
|
|
const current = await User.getUserField(userData.uid, 'email');
|
|
|
|
if (formData.email === current) {
|
|
|
|
if (formData.email === current) {
|
|
|
|
throw new Error('[[error:email-nochange]]');
|
|
|
|
throw new Error('[[error:email-nochange]]');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const [isAdminOrGlobalMod, canEdit] = await Promise.all([
|
|
|
|
|
|
|
|
User.isAdminOrGlobalMod(data.req.uid),
|
|
|
|
|
|
|
|
privileges.users.canEdit(data.req.uid, userData.uid),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Admins editing will auto-confirm, unless editing their own email
|
|
|
|
// Admins editing will auto-confirm, unless editing their own email
|
|
|
|
if (isAdminOrGlobalMod && userData.uid !== data.req.uid) {
|
|
|
|
if (isAdminOrGlobalMod && userData.uid !== data.req.uid) {
|
|
|
|
await User.setUserField(userData.uid, 'email', formData.email);
|
|
|
|
await User.setUserField(userData.uid, 'email', formData.email);
|
|
|
@ -279,9 +278,12 @@ User.addInterstitials = function (callback) {
|
|
|
|
throw new Error('[[error:no-privileges]]');
|
|
|
|
throw new Error('[[error:no-privileges]]');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// New registrants have the confirm email sent from user.create()
|
|
|
|
// User explicitly clearing their email
|
|
|
|
userData.email = formData.email;
|
|
|
|
await User.email.remove(userData.uid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// New registrants have the confirm email sent from user.create()
|
|
|
|
|
|
|
|
userData.email = formData.email;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete userData.updateEmail;
|
|
|
|
delete userData.updateEmail;
|
|
|
|