Merge pull request #426 from hashicorp/refactor-desktop-typed-auth

refactor: 💡 move authenticate forms to core and use in desktop
This commit is contained in:
Randall Morey authored and GitHub committed 2021-01-11 16:31:10 -05:00
commit 31a9d4c1a3
7 files changed
+19 -55

No files matched your search

@@ -0,0 +1 @@
export { default } from 'core/components/form/authenticate';
@@ -0,0 +1 @@
export { default } from 'core/components/form/authenticate/password';
@@ -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');
}
}
@@ -1,29 +1,5 @@
<Rose::Form
class="full-width"
@onSubmit={{route-action "authenticate" (hash
identification=this.identification
password=this.password
)}}
@cancel={{false}}
<Form::Authenticate
@model={{@model}}
@submit={{route-action "authenticate"}}
@disabled={{is-loading}}
as |form|
>
<form.input
@name="identification"
@type="text"
@value={{this.identification}}
@label={{t "form.login_name.label"}}
{{autofocus}} />
<form.input
@name="password"
@type="password"
@value={{this.password}}
@label={{t "form.password.label"}} />
<form.actions
@submitText={{t "actions.authenticate"}}
@showCancel={{false}} />
</Rose::Form>
/>