|
|
|
@ -1,10 +1,8 @@
|
|
|
|
|
import DataUtils from './utils/DataUtils';
|
|
|
|
|
import Manager from './controllers/DashManager';
|
|
|
|
|
import request from 'request-promise';
|
|
|
|
|
import * as DataEvent from '../com/events/DataEvent';
|
|
|
|
|
//import DBUtils from '../../../../../brain/utils/tools/DBUtils';
|
|
|
|
|
const utils = new DataUtils();
|
|
|
|
|
const settings = require('../../site/settings.json');
|
|
|
|
|
import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from './utils/DataUtils';
|
|
|
|
|
import * as DataEvent from './events/DataEvent';
|
|
|
|
|
import DashManager from './controllers/DashManager';
|
|
|
|
|
|
|
|
|
|
const data = new DataUtils();
|
|
|
|
|
|
|
|
|
|
export default class Base {
|
|
|
|
|
//--------------------------
|
|
|
|
@ -23,7 +21,7 @@ export default class Base {
|
|
|
|
|
.getElementById('login-btn')
|
|
|
|
|
.addEventListener('click', e => this.handleLogin(e));
|
|
|
|
|
} else {
|
|
|
|
|
let manager = new Manager();
|
|
|
|
|
//let dm = new DashManager();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//--------------------------
|
|
|
|
@ -32,23 +30,32 @@ export default class Base {
|
|
|
|
|
handleLogin(e) {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
let authForm = utils.formDataToJSON(document.getElementById('login'));
|
|
|
|
|
|
|
|
|
|
request({
|
|
|
|
|
method: 'POST',
|
|
|
|
|
uri: settings.base_url + '/api/v1/auth/login',
|
|
|
|
|
body: authForm,
|
|
|
|
|
json: true
|
|
|
|
|
})
|
|
|
|
|
.then(res => {
|
|
|
|
|
if (res.type === DataEvent.REQUEST_LAME) {
|
|
|
|
|
e.target.innerHTML = res.message;
|
|
|
|
|
let authForm = data.formDataToJSON(document.getElementById('login'));
|
|
|
|
|
data.request(
|
|
|
|
|
'/api/v1/auth/login',
|
|
|
|
|
DataEvent.AUTH_STATUS,
|
|
|
|
|
REQUEST_TYPE_POST,
|
|
|
|
|
CONTENT_TYPE_JSON,
|
|
|
|
|
authForm
|
|
|
|
|
)
|
|
|
|
|
.then(r => {
|
|
|
|
|
let response = JSON.parse(r.request['response']);
|
|
|
|
|
if (response.type === DataEvent.REQUEST_LAME) {
|
|
|
|
|
e.target.innerHTML = response.message;
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
e.target.innerHTML = 'TRY IT AGAIN, HOMIE';
|
|
|
|
|
}, 1500);
|
|
|
|
|
//console.log('NOPE', response.message);
|
|
|
|
|
//self.dashManager = new DashManager();
|
|
|
|
|
} else {
|
|
|
|
|
window.location = '/@/dashboard';
|
|
|
|
|
e.target.innerHTML = response.message;
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
window.location = '/@/dashboard';
|
|
|
|
|
}, 500);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
//console.log('ERROR', err);
|
|
|
|
|
//console.log(err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|