|
|
|
@ -28,8 +28,8 @@ export const TASK_PAGE_DELETE = "deletePage";
|
|
|
|
|
export const TASK_SEND_MAIL = "sendMail";
|
|
|
|
|
export const TASK_REINDEX_PAGE = "reIndexPages";
|
|
|
|
|
//** API STATUS **//
|
|
|
|
|
export const API_ACCESS_GOOD = "apiConnected";
|
|
|
|
|
export const API_ACCESS_BAD = "apiNotConnected";
|
|
|
|
|
export const API_ACCESS_GOOD = "apiUseAuthorized";
|
|
|
|
|
export const API_ACCESS_BAD = "apiUseNotAuthorized";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A can of methods used to edit install settings, navigation pages.
|
|
|
|
@ -48,29 +48,30 @@ class FipamoAdminAPI {
|
|
|
|
|
this.key = null;
|
|
|
|
|
if (key) this.key = key;
|
|
|
|
|
if (baseURL) this.baseURL = baseURL;
|
|
|
|
|
//checks backend to see if user is logged in and requests encrypted token for api calls
|
|
|
|
|
this._request(API_STATUS).then((response) => {
|
|
|
|
|
//if key is valid, checks to see if a session is active and returns
|
|
|
|
|
this._request(
|
|
|
|
|
this.baseURL
|
|
|
|
|
? this.baseURL + API_STATUS + "?key=" + this.key
|
|
|
|
|
: API_STATUS + "?key=" + this.key
|
|
|
|
|
).then((response) => {
|
|
|
|
|
if (response.type === API_ACCESS_GOOD) {
|
|
|
|
|
this.token = response.token;
|
|
|
|
|
} else {
|
|
|
|
|
//don't set token
|
|
|
|
|
//console.log("NO TOKEN");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Method for retrieving user authorizing user login
|
|
|
|
|
* Promise method for checking credentials. Must login to use Admin API.
|
|
|
|
|
* @param {object} data - json object that contains data for set up
|
|
|
|
|
* @property {string} handle - handle for site user
|
|
|
|
|
* @property {string} password - password for site user
|
|
|
|
|
*/
|
|
|
|
|
login(data) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
if (this.baseURL) {
|
|
|
|
|
data.key = this.key;
|
|
|
|
|
data.remote = true;
|
|
|
|
|
} else {
|
|
|
|
|
data.remote = false;
|
|
|
|
|
}
|
|
|
|
|
this.baseURL ? (data.remote = true) : (data.remote = false);
|
|
|
|
|
this.key ? (data.key = this.key) : (data.key = null);
|
|
|
|
|
this._request(
|
|
|
|
|
this.baseURL ? this.baseURL + API_LOGIN : API_LOGIN,
|
|
|
|
|
AUTH_STATUS,
|
|
|
|
@ -109,7 +110,9 @@ class FipamoAdminAPI {
|
|
|
|
|
syncSettings(data) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(
|
|
|
|
|
this.baseURL ? this.baseURL + API_SETTINGS_SYNC : API_SETTINGS_SYNC,
|
|
|
|
|
this.baseURL
|
|
|
|
|
? this.baseURL + API_SETTINGS_SYNC + "?key=" + this.key
|
|
|
|
|
: API_SETTINGS_SYNC + "?key=" + this.key,
|
|
|
|
|
TASK_SETTINGS_WRITE,
|
|
|
|
|
REQUEST_TYPE_POST,
|
|
|
|
|
CONTENT_TYPE_JSON,
|
|
|
|
@ -190,6 +193,13 @@ class FipamoAdminAPI {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.baseURL) {
|
|
|
|
|
data.key = this.key;
|
|
|
|
|
data.remote = true;
|
|
|
|
|
} else {
|
|
|
|
|
data.remote = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(
|
|
|
|
|
this.baseURL ? this.baseURL + url : url,
|
|
|
|
@ -292,7 +302,6 @@ class FipamoAdminAPI {
|
|
|
|
|
request.open(requestType, requestURL, true);
|
|
|
|
|
request.onload = () => {
|
|
|
|
|
if (request.status == 200) {
|
|
|
|
|
//console.log("RESPONSE", request);
|
|
|
|
|
let response = JSON.parse(request["response"]);
|
|
|
|
|
resolve(response);
|
|
|
|
|
} else {
|
|
|
|
|