From 0b4ba2769b7661445a604b00b29fc47670b47c7a Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 11 Jan 2021 14:27:38 -0500 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20move=20authenticate?= =?UTF-8?q?=20forms=20to=20core=20and=20use=20in=20desktop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/form/authenticate/index.hbs | 0 .../form/authenticate/password/index.hbs | 0 .../form/authenticate/password/index.js | 0 .../core/app/components/form/authenticate.js | 1 + .../components/form/authenticate/password.js | 1 + .../scopes/scope/authenticate/method.js | 40 ++++++------------- .../scopes/scope/authenticate/method.hbs | 32 ++------------- 7 files changed, 19 insertions(+), 55 deletions(-) rename {ui/admin/app => addons/core/addon}/components/form/authenticate/index.hbs (100%) rename {ui/admin/app => addons/core/addon}/components/form/authenticate/password/index.hbs (100%) rename {ui/admin/app => addons/core/addon}/components/form/authenticate/password/index.js (100%) create mode 100644 addons/core/app/components/form/authenticate.js create mode 100644 addons/core/app/components/form/authenticate/password.js diff --git a/ui/admin/app/components/form/authenticate/index.hbs b/addons/core/addon/components/form/authenticate/index.hbs similarity index 100% rename from ui/admin/app/components/form/authenticate/index.hbs rename to addons/core/addon/components/form/authenticate/index.hbs diff --git a/ui/admin/app/components/form/authenticate/password/index.hbs b/addons/core/addon/components/form/authenticate/password/index.hbs similarity index 100% rename from ui/admin/app/components/form/authenticate/password/index.hbs rename to addons/core/addon/components/form/authenticate/password/index.hbs diff --git a/ui/admin/app/components/form/authenticate/password/index.js b/addons/core/addon/components/form/authenticate/password/index.js similarity index 100% rename from ui/admin/app/components/form/authenticate/password/index.js rename to addons/core/addon/components/form/authenticate/password/index.js diff --git a/addons/core/app/components/form/authenticate.js b/addons/core/app/components/form/authenticate.js new file mode 100644 index 000000000..f471115c1 --- /dev/null +++ b/addons/core/app/components/form/authenticate.js @@ -0,0 +1 @@ +export { default } from 'core/components/form/authenticate'; \ No newline at end of file diff --git a/addons/core/app/components/form/authenticate/password.js b/addons/core/app/components/form/authenticate/password.js new file mode 100644 index 000000000..ec54f0464 --- /dev/null +++ b/addons/core/app/components/form/authenticate/password.js @@ -0,0 +1 @@ +export { default } from 'core/components/form/authenticate/password'; \ No newline at end of file diff --git a/ui/desktop/app/routes/scopes/scope/authenticate/method.js b/ui/desktop/app/routes/scopes/scope/authenticate/method.js index c9a6adacd..f1547b90b 100644 --- a/ui/desktop/app/routes/scopes/scope/authenticate/method.js +++ b/ui/desktop/app/routes/scopes/scope/authenticate/method.js @@ -2,6 +2,7 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; import { action } from '@ember/object'; import loading from 'ember-loading/decorator'; +import { notifyError } from 'core/decorators/notify'; export default class ScopesScopeAuthenticateMethodRoute extends Route { // =services @@ -22,41 +23,26 @@ 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 /** - * Delegates authentication to the `password` authenticator. - * If authentication fails, notifies with an alert. + * Delegates authentication to an authenticator of type matching the current + * auth method. If authentication fails, notifies with an alert. */ @action @loading + @notifyError(() => 'errors.authentication-failed.title', { catch: true }) async authenticate(creds) { - this.resetCredentials(); - const authenticatorName = 'authenticator:password'; const scope = this.modelFor('scopes.scope'); - const authMethod = this.currentModel; + const authMethod = this.modelFor('scopes.scope.authenticate.method'); + const authenticatorName = `authenticator:${authMethod.type}`; const requestCookies = false; - try { - await this.session.authenticate( - authenticatorName, - creds, - requestCookies, - { scope, authMethod } - ); - this.replaceWith('index'); - } catch (e) { - const errorMessage = this.intl.t('errors.authentication-failed.title'); - this.notify.error(errorMessage, { closeAfter: null }); - } + await this.session.authenticate( + authenticatorName, + creds, + requestCookies, + { scope, authMethod } + ); + this.replaceWith('index'); } } diff --git a/ui/desktop/app/templates/scopes/scope/authenticate/method.hbs b/ui/desktop/app/templates/scopes/scope/authenticate/method.hbs index 8cdf94c64..6428c8118 100644 --- a/ui/desktop/app/templates/scopes/scope/authenticate/method.hbs +++ b/ui/desktop/app/templates/scopes/scope/authenticate/method.hbs @@ -1,29 +1,5 @@ - - - - - - - - - +/>