chore: 🤖 cleanup password reset

This commit is contained in:
Randall Morey committed 2020-09-16 12:13:16 -04:00
1 parent 2e3b044ae9
commit b1230a4b3f
2 files changed
+35 -7

No files matched your search

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