diff --git a/wherehows-web/app/authenticators/custom-ldap.ts b/wherehows-web/app/authenticators/custom-ldap.ts index d8fcf4888b..a23b9dffc7 100644 --- a/wherehows-web/app/authenticators/custom-ldap.ts +++ b/wherehows-web/app/authenticators/custom-ldap.ts @@ -1,6 +1,8 @@ import Base from 'ember-simple-auth/authenticators/base'; import { IAuthenticateResponse, IAuthenticationData } from 'wherehows-web/typings/api/authentication/user'; -import { postJSON } from 'wherehows-web/utils/api/fetcher'; +import JQuery from 'jquery'; + +const { post } = JQuery; export default Base.extend({ /** @@ -11,10 +13,13 @@ export default Base.extend({ * @return {Promise} */ authenticate: async (username: string, password: string): Promise => { - const { data } = await postJSON({ + // retaining usage of jquery post method as opposed to fetch, since api currently fails with string response + // TODO: update mid-tier exception handling + const { data } = await (>post({ url: '/authenticate', - data: { username, password } - }); + contentType: 'application/json', + data: JSON.stringify({ username, password }) + })); return { ...data }; }, diff --git a/wherehows-web/app/controllers/login.js b/wherehows-web/app/controllers/login.js deleted file mode 100644 index ba8c878bdd..0000000000 --- a/wherehows-web/app/controllers/login.js +++ /dev/null @@ -1,26 +0,0 @@ -import Controller from '@ember/controller'; -import { computed, get, setProperties } from '@ember/object'; -import { inject } from '@ember/service'; - -export default Controller.extend({ - session: inject(), - - username: computed.alias('name'), - - password: computed.alias('pass'), - - errorMessage: '', - - actions: { - /** - * Using the session service, authenticate using the custom ldap authenticator - */ - authenticateUser() { - const { username, password } = this.getProperties(['username', 'password']); - - get(this, 'session') - .authenticate('authenticator:custom-ldap', username, password) - .catch(({ responseText = 'Bad Credentials' }) => setProperties(this, { errorMessage: responseText })); - } - } -}); diff --git a/wherehows-web/app/controllers/login.ts b/wherehows-web/app/controllers/login.ts new file mode 100644 index 0000000000..a68b5fe438 --- /dev/null +++ b/wherehows-web/app/controllers/login.ts @@ -0,0 +1,49 @@ +import Controller from '@ember/controller'; +import { computed, get, setProperties, getProperties } from '@ember/object'; +import ComputedProperty from '@ember/object/computed'; +import { inject } from '@ember/service'; +import Session from 'ember-simple-auth/services/session'; + +export default class Login extends Controller { + /** + * References the application session service + * @type {ComputedProperty} + * @memberof Login + */ + session: ComputedProperty = inject(); + + /** + * Aliases the name property on the component + * @type {ComputedProperty} + * @memberof Login + */ + username = computed.alias('name'); + + /** + * Aliases the password computed property on the component + * @type {ComputedProperty} + * @memberof Login + */ + password = computed.alias('pass'); + + /** + * On instantiation, error message reference is an empty string value + * @type {string} + * @memberof Login + */ + errorMessage = ''; + + actions = { + /** + * Using the session service, authenticate using the custom ldap authenticator + * @return {void} + */ + authenticateUser(this: Login): void { + const { username, password } = getProperties(this, ['username', 'password']); + + get(this, 'session') + .authenticate('authenticator:custom-ldap', username, password) + .catch(({ responseText = 'Bad Credentials' }) => setProperties(this, { errorMessage: responseText })); + } + }; +}