Skip to content

Commit

Permalink
Fix #3284
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Dec 5, 2021
1 parent 0de9c2f commit 6ecc1a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/client/app/common/views/components/settings/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,12 @@ export default Vue.extend({
},
async deleteAccount() {
const { canceled: canceled2 } = await this.$root.dialog({
title: this.$t('delete-account-confirm'),
showCancelButton: true
});
if (canceled2) return;
const { canceled: canceled, result: password } = await this.$root.dialog({
title: this.$t('enter-password'),
input: {
Expand All @@ -492,12 +498,6 @@ export default Vue.extend({
});
if (canceled) return;
const { canceled: canceled2 } = await this.$root.dialog({
title: this.$t('delete-account-confirm'),
showCancelButton: true
});
if (canceled2) return;
this.$root.api('i/delete-account', {
password
}).then(() => {
Expand Down
13 changes: 11 additions & 2 deletions src/server/api/endpoints/i/delete-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Message from '../../../../models/messaging-message';
import Signin from '../../../../models/signin';
import { doPostSuspend } from '../../../../services/suspend-user';
import { publishTerminate } from '../../../../services/server-event';
import { ApiError } from '../../error';

export const meta = {
requireCredential: true,
Expand All @@ -17,15 +18,23 @@ export const meta = {
password: {
validator: $.str
},
}
},

errors: {
incorrectPassword: {
message: 'Incorrect password',
code: 'INCORRECT_PASSWORD',
id: 'c6c69c2d-1f58-4850-bb05-40db158b9de2'
},
},
};

export default define(meta, async (ps, user) => {
// Compare password
const same = await bcrypt.compare(ps.password, user.password);

if (!same) {
throw new Error('incorrect password');
throw new ApiError(meta.errors.incorrectPassword);
}

await User.update({ _id: user._id }, {
Expand Down

0 comments on commit 6ecc1a7

Please sign in to comment.