diff --git a/src/plugins/profile/password-reset.js b/src/plugins/profile/password-reset.js index e338fc9d62..cda575250c 100644 --- a/src/plugins/profile/password-reset.js +++ b/src/plugins/profile/password-reset.js @@ -11,12 +11,14 @@ class PasswordReset extends CustomElement { static get properties () { return { passwords_mismatched: { type: Boolean }, + current_password_error: { type: Boolean }, alert_message: { type: String } } } initialize () { this.passwords_mismatched = false; + this.current_password_error = false; this.alert_message = ''; } @@ -33,9 +35,22 @@ class PasswordReset extends CustomElement { return this.passwords_mismatched } + checkCurrentPassword (ev) { + const form_data = new FormData(ev.target.form ?? ev.target); + const current_password = form_data.get('current_password'); + const connection = api.connection.get(); + if (connection?.pass && current_password !== connection.pass) { + this.current_password_error = true; + } else { + this.current_password_error = false; + } + return this.current_password_error; + } + async onSubmit (ev) { ev.preventDefault(); + if (this.checkCurrentPassword(ev)) return; if (this.checkPasswordsMatch(ev)) return; const domain = _converse.session.get('domain'); diff --git a/src/plugins/profile/templates/password-reset.js b/src/plugins/profile/templates/password-reset.js index 3b724b6200..d202db6cf2 100644 --- a/src/plugins/profile/templates/password-reset.js +++ b/src/plugins/profile/templates/password-reset.js @@ -4,12 +4,29 @@ import { html } from 'lit'; export default el => { const i18n_submit = __('Submit'); const i18n_passwords_must_match = __('The new passwords must match'); + const i18n_current_password = __('Current password'); + const i18n_current_password_wrong = __('Incorrect current password'); const i18n_new_password = __('New password'); const i18n_confirm_password = __('Confirm new password'); return html`