From b1230a4b3fe5f5848864bdbda725cccf67ba11a1 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 16 Sep 2020 12:13:16 -0400 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20cleanup=20password=20re?= =?UTF-8?q?set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/form/account/password/index.js | 22 ++++++++++++++++--- .../account/password/set-password/index.js | 20 +++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/ui/core/app/components/form/account/password/index.js b/ui/core/app/components/form/account/password/index.js index caf239d17..02f208746 100644 --- a/ui/core/app/components/form/account/password/index.js +++ b/ui/core/app/components/form/account/password/index.js @@ -1,4 +1,5 @@ import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; import { action } from '@ember/object'; export default class FormAccountPasswordIndexComponent extends Component { @@ -9,7 +10,16 @@ export default class FormAccountPasswordIndexComponent extends Component { * Account password property * @type {string} */ - password; + @tracked password; + + // =methods + + /** + * Unsets the password field. + */ + resetPassword() { + this.password = null; + } // =actions @@ -20,7 +30,13 @@ export default class FormAccountPasswordIndexComponent extends Component { */ @action submit(fn) { - this.args.model.isNew ? fn(this.password) : fn(); - delete this.password; + try { + this.args.model.isNew ? fn(this.password) : fn(); + } catch (e) { + // We want to guarantee password is unset + this.resetPassword(); + // But we don't want to silence the error + throw e; + } } } diff --git a/ui/core/app/components/form/account/password/set-password/index.js b/ui/core/app/components/form/account/password/set-password/index.js index a4039b76d..2449d4c6f 100644 --- a/ui/core/app/components/form/account/password/set-password/index.js +++ b/ui/core/app/components/form/account/password/set-password/index.js @@ -39,8 +39,14 @@ export default class FormAccountPasswordSetPasswordIndexComponent extends Compon */ @action submit(fn) { - fn(this.password); - this.resetPassword(); + try { + fn(this.password); + } catch (e) { + // We want to guarantee password is unset + this.resetPassword(); + // But we don't want to silence the error + throw e; + } } /** @@ -49,8 +55,14 @@ export default class FormAccountPasswordSetPasswordIndexComponent extends Compon */ @action cancel(fn) { - fn(); - this.resetPassword(); + try { + fn(); + } catch (e) { + // We want to guarantee password is unset + this.resetPassword(); + // But we don't want to silence the error + throw e; + } } }