From 8e3551ddaec06b14cb7a85fd5e479ffa78b35647 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 6 Jan 2021 13:46:22 -0500 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20authenticate=20route?= =?UTF-8?q?=20and=20forms=20to=20be=20type=20agnostic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/form/authenticate/index.hbs | 7 ++++ .../form/authenticate/password/index.hbs | 28 ++++++++++++++ .../form/authenticate/password/index.js | 37 +++++++++++++++++++ .../scopes/scope/authenticate/method.js | 11 ------ .../scopes/scope/authenticate/method.hbs | 31 ++-------------- 5 files changed, 76 insertions(+), 38 deletions(-) create mode 100644 ui/admin/app/components/form/authenticate/index.hbs create mode 100644 ui/admin/app/components/form/authenticate/password/index.hbs create mode 100644 ui/admin/app/components/form/authenticate/password/index.js diff --git a/ui/admin/app/components/form/authenticate/index.hbs b/ui/admin/app/components/form/authenticate/index.hbs new file mode 100644 index 000000000..e7ca752c2 --- /dev/null +++ b/ui/admin/app/components/form/authenticate/index.hbs @@ -0,0 +1,7 @@ +{{#if @model.type}} + {{component (concat "form/authenticate/" @model.type) + submit=@submit + cancel=false + disabled=@disabled + }} +{{/if}} diff --git a/ui/admin/app/components/form/authenticate/password/index.hbs b/ui/admin/app/components/form/authenticate/password/index.hbs new file mode 100644 index 000000000..ee47910d8 --- /dev/null +++ b/ui/admin/app/components/form/authenticate/password/index.hbs @@ -0,0 +1,28 @@ + + + + + + + + + diff --git a/ui/admin/app/components/form/authenticate/password/index.js b/ui/admin/app/components/form/authenticate/password/index.js new file mode 100644 index 000000000..d6336f382 --- /dev/null +++ b/ui/admin/app/components/form/authenticate/password/index.js @@ -0,0 +1,37 @@ +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import { action } from '@ember/object'; +import { run } from '@ember/runloop'; + +export default class FormAuthenticatePasswordComponent extends Component { + // =properties + + /** + * New password property + * @type {string} + */ + @tracked password; + + // =methods + + /** + * Unsets the password field. + */ + resetPassword() { + this.password = null; + } + + // =actions + + /** + * Submit credentials, but reset the password first in case of failure. + * Callback with no arguments otherwise. + * @param {function} fn + * @param {object} creds + */ + @action + submit(fn, creds) { + run(() => this.resetPassword()); + run(() => fn(creds)); + } +} diff --git a/ui/admin/app/routes/scopes/scope/authenticate/method.js b/ui/admin/app/routes/scopes/scope/authenticate/method.js index 1caa35d95..cfb2c5acf 100644 --- a/ui/admin/app/routes/scopes/scope/authenticate/method.js +++ b/ui/admin/app/routes/scopes/scope/authenticate/method.js @@ -23,16 +23,6 @@ export default class ScopesScopeAuthenticateMethodRoute extends Route { return this.store.findRecord('auth-method', id, adapterOptions); } - /** - * Resets the password field on the controller so it is not - * inadvertantly retained in memory. - */ - resetCredentials() { - this.controller.setProperties({ - password: null, - }); - } - // =actions /** @@ -43,7 +33,6 @@ export default class ScopesScopeAuthenticateMethodRoute extends Route { @loading @notifyError(() => 'errors.authentication-failed.title', { catch: true }) async authenticate(creds) { - this.resetCredentials(); const scope = this.modelFor('scopes.scope'); const authMethod = this.modelFor('scopes.scope.authenticate.method'); const authenticatorName = `authenticator:${authMethod.type}`; diff --git a/ui/admin/app/templates/scopes/scope/authenticate/method.hbs b/ui/admin/app/templates/scopes/scope/authenticate/method.hbs index 709c1f491..6428c8118 100644 --- a/ui/admin/app/templates/scopes/scope/authenticate/method.hbs +++ b/ui/admin/app/templates/scopes/scope/authenticate/method.hbs @@ -1,28 +1,5 @@ - - - - - - - - - +/>