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 logger from "../utils/logit";
import store from "../store"; import store from "../store";
@@ -13,13 +14,35 @@ export default {
json(response) { json(response) {
return response.json(); return response.json();
}, },
AuthorizedHeaders() { PatchAuthorizedHeaders() {
return { 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", "Content-Type": "application/json",
Authorization: "Bearer " + store.state.apiToken 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() { APIUrl() {
return store.state.apiUrl; return store.state.apiUrl;
} }

View File

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

View File

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

View File

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

View File

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