Delete Account with Social Auth (#8796)

* feat(accounts): delete social accts

* test(integration): social auth delete
This commit is contained in:
Sabe Jones
2017-07-21 10:55:53 -07:00
committed by GitHub
parent 88fece1422
commit e6dd0d5e82
6 changed files with 312 additions and 232 deletions

View File

@@ -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'));
}