This commit is contained in:
2018-11-14 22:30:03 +00:00
parent 6f6b49a793
commit 2f92d587e4
5 changed files with 36 additions and 13 deletions

View File

@@ -1,3 +1,4 @@
/* xeslint-disable */
import logger from "../utils/logit";
import store from "../store";
@@ -13,13 +14,35 @@ export default {
json(response) {
return response.json();
},
AuthorizedHeaders() {
PatchAuthorizedHeaders() {
return {
Accept: "application/json, text/plain, */*",
//Accept: "application/json, text/plain, */*",
Accept: "application/json",
"Content-Type": "application/json-patch+json",
Authorization: "Bearer " + store.state.apiToken
};
},
PostAuthorizedHeaders() {
return {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: "Bearer " + store.state.apiToken
};
},
PostUnAuthorizedHeaders() {
return {
Accept: "application/json",
"Content-Type": "application/json"
};
},
fetchPostNoAuth(data) {
return {
method: "post",
mode: "cors",
headers: this.PostUnAuthorizedHeaders(),
body: JSON.stringify(data)
};
},
APIUrl() {
return store.state.apiUrl;
}

View File

@@ -1,20 +1,16 @@
/* xeslint-disable */
import apiUtil from "./apiutil";
import { processLogin, processLogout } from "../utils/authutil";
export default {
async authenticate(login, password) {
return fetch(apiUtil.APIUrl + "auth", {
method: "post",
mode: "cors",
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json"
},
body: JSON.stringify({
return fetch(
apiUtil.APIUrl() + "auth",
apiUtil.fetchPostNoAuth({
login: login,
password: password
})
})
)
.then(apiUtil.status)
.then(apiUtil.json)
.then(processLogin)

View File

@@ -23,10 +23,11 @@ export default {
resolve();
return;
}
fetch(apiUtil.APIUrl + "locale/subset", {
//step 2: get it
fetch(apiUtil.APIUrl() + "locale/subset", {
method: "post",
mode: "cors",
headers: apiUtil.AuthorizedHeaders(),
headers: apiUtil.PostAuthorizedHeaders(),
body: JSON.stringify(NeedIt)
})
.then(apiUtil.status)

View File

@@ -1,3 +1,4 @@
/* xeslint-disable */
import decode from "jwt-decode";
import logger from "./logit";
import store from "../store";

View File

@@ -59,6 +59,8 @@ export default {
this.$router.replace({ name: "home" });
})
.catch(function(error) {
/* eslint-disable-next-line */
console.log(error);
alert("login failed: " + error);
});
}