mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Delete Account with Social Auth (#8796)
* feat(accounts): delete social accts * test(integration): social auth delete
This commit is contained in:
@@ -22,6 +22,7 @@ import nconf from 'nconf';
|
||||
import get from 'lodash/get';
|
||||
|
||||
const TECH_ASSISTANCE_EMAIL = nconf.get('EMAILS:TECH_ASSISTANCE_EMAIL');
|
||||
const DELETE_CONFIRMATION = 'DELETE';
|
||||
|
||||
/**
|
||||
* @apiDefine UserNotFound
|
||||
@@ -303,15 +304,16 @@ api.deleteUser = {
|
||||
let password = req.body.password;
|
||||
if (!password) throw new BadRequest(res.t('missingPassword'));
|
||||
|
||||
if (user.auth.local.hashed_password && user.auth.local.email) {
|
||||
let isValidPassword = await passwordUtils.compare(user, password);
|
||||
if (!isValidPassword) throw new NotAuthorized(res.t('wrongPassword'));
|
||||
} else if ((user.auth.facebook.id || user.auth.google.id) && password !== DELETE_CONFIRMATION) {
|
||||
throw new NotAuthorized(res.t('incorrectDeletePhrase'));
|
||||
}
|
||||
|
||||
let feedback = req.body.feedback;
|
||||
if (feedback && feedback.length > 10000) throw new BadRequest(`Account deletion feedback is limited to 10,000 characters. For lengthy feedback, email ${TECH_ASSISTANCE_EMAIL}.`);
|
||||
|
||||
let validationErrors = req.validationErrors();
|
||||
if (validationErrors) throw validationErrors;
|
||||
|
||||
let isValidPassword = await passwordUtils.compare(user, password);
|
||||
if (!isValidPassword) throw new NotAuthorized(res.t('wrongPassword'));
|
||||
|
||||
if (plan && plan.customerId && !plan.dateTerminated) {
|
||||
throw new NotAuthorized(res.t('cannotDeleteActiveAccount'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user