mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-25 09:38:11 +00:00
retain $ post method for ajax request. rewrites login controller as ts file
This commit is contained in:
parent
39fff3e182
commit
264052f01a
@ -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<IAuthenticationData>}
|
||||
*/
|
||||
authenticate: async (username: string, password: string): Promise<IAuthenticationData> => {
|
||||
const { data } = await postJSON<IAuthenticateResponse>({
|
||||
// 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 (<JQuery.jqXHR<IAuthenticateResponse>>post({
|
||||
url: '/authenticate',
|
||||
data: { username, password }
|
||||
});
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({ username, password })
|
||||
}));
|
||||
|
||||
return { ...data };
|
||||
},
|
||||
|
@ -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 }));
|
||||
}
|
||||
}
|
||||
});
|
49
wherehows-web/app/controllers/login.ts
Normal file
49
wherehows-web/app/controllers/login.ts
Normal file
@ -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<Session>}
|
||||
* @memberof Login
|
||||
*/
|
||||
session: ComputedProperty<Session> = inject();
|
||||
|
||||
/**
|
||||
* Aliases the name property on the component
|
||||
* @type {ComputedProperty<string>}
|
||||
* @memberof Login
|
||||
*/
|
||||
username = computed.alias('name');
|
||||
|
||||
/**
|
||||
* Aliases the password computed property on the component
|
||||
* @type {ComputedProperty<string>}
|
||||
* @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 }));
|
||||
}
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user