This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
|
import logger from "../utils/logit";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
status(response) {
|
status(response) {
|
||||||
if (response.status >= 200 && response.status < 300) {
|
if (response.status >= 200 && response.status < 300) {
|
||||||
return Promise.resolve(response);
|
return Promise.resolve(response);
|
||||||
} else {
|
} else {
|
||||||
|
logger.log("API error", response.statusText);
|
||||||
return Promise.reject(new Error(response.statusText));
|
return Promise.reject(new Error(response.statusText));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,37 +1,30 @@
|
|||||||
import config from "../utils/config";
|
import config from "../utils/config";
|
||||||
import api from "./apiutil";
|
import api from "./apiutil";
|
||||||
import { processLogin, processLogout } from "../utils/auth";
|
import { processLogin, processLogout } from "../utils/authUtil";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async authenticate(login, password) {
|
async authenticate(login, password) {
|
||||||
return (
|
return fetch(config.apiUrl + "auth", {
|
||||||
fetch(config.apiUrl + "auth", {
|
method: "post",
|
||||||
method: "post",
|
mode: "cors",
|
||||||
mode: "cors",
|
headers: {
|
||||||
headers: {
|
Accept: "application/json, text/plain, */*",
|
||||||
Accept: "application/json, text/plain, */*",
|
"Content-Type": "application/json"
|
||||||
"Content-Type": "application/json"
|
},
|
||||||
},
|
body: JSON.stringify({
|
||||||
body: JSON.stringify({
|
login: login,
|
||||||
login: login,
|
password: password
|
||||||
password: password
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.then(api.status)
|
})
|
||||||
.then(api.json)
|
.then(api.status)
|
||||||
.then(processLogin)
|
.then(api.json)
|
||||||
.then(() => {
|
.then(processLogin)
|
||||||
return Promise.resolve(true);
|
.then(() => {
|
||||||
}) //succeeded, nothing to return
|
return Promise.resolve(true);
|
||||||
// .then(function(data) {
|
}) //succeeded, nothing to return
|
||||||
// //todo: this should just return a bool on successful login and let the util\auth handle storing token etc
|
.catch(function(error) {
|
||||||
// //router will handle views available based on roles etc so login only really needs to know if it succeeded or not.
|
processLogout();
|
||||||
// return data;
|
return Promise.reject(error);
|
||||||
// })
|
});
|
||||||
.catch(function(error) {
|
|
||||||
processLogout();
|
|
||||||
return Promise.reject(error);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/* eslint-disable */
|
|
||||||
|
|
||||||
import decode from "jwt-decode";
|
import decode from "jwt-decode";
|
||||||
import config from "./config";
|
import config from "./config";
|
||||||
import logger from "./logit";
|
import logger from "./logit";
|
||||||
@@ -131,8 +129,8 @@ export function setToken(token) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function isLoggedIn() {
|
export function isLoggedIn() {
|
||||||
const token = getToken();
|
//const token = getToken();
|
||||||
return !!token && !isTokenExpired(token);
|
return !!config.apiToken && !isTokenExpired(config.apiToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTokenExpirationDate(encodedToken) {
|
function getTokenExpirationDate(encodedToken) {
|
||||||
@@ -1,11 +1,37 @@
|
|||||||
<template>
|
<template>
|
||||||
<div id="login">
|
|
||||||
<h1>Login</h1>
|
<v-container fluid>
|
||||||
<input type="text" name="username" v-model="input.username" placeholder="Username">
|
<v-layout row wrap>
|
||||||
<input type="password" name="password" v-model="input.password" placeholder="Password">
|
<v-flex xs12 class="text-xs-center" mt-5>
|
||||||
<button type="button" v-on:click="login()">Login</button>
|
<h1>Login</h1>
|
||||||
<button type="button" v-on:click="showlog()">ShowLog</button>
|
</v-flex>
|
||||||
</div>
|
<v-flex xs12 sm6 offset-sm3 mt-3>
|
||||||
|
<form>
|
||||||
|
<v-layout column>
|
||||||
|
<v-flex>
|
||||||
|
<v-text-field
|
||||||
|
name="username"
|
||||||
|
v-model="input.username"
|
||||||
|
label="Username"
|
||||||
|
required></v-text-field>
|
||||||
|
</v-flex>
|
||||||
|
<v-flex>
|
||||||
|
<v-text-field
|
||||||
|
name="password"
|
||||||
|
v-model="input.password"
|
||||||
|
label="Password"
|
||||||
|
type="password"
|
||||||
|
required></v-text-field>
|
||||||
|
</v-flex>
|
||||||
|
<v-flex class="text-xs-center" mt-5>
|
||||||
|
<v-btn color="primary" v-on:click="login()">Login</v-btn>
|
||||||
|
<v-btn color="primary" v-on:click="showlog()">Log</v-btn>
|
||||||
|
</v-flex>
|
||||||
|
</v-layout>
|
||||||
|
</form>
|
||||||
|
</v-flex>
|
||||||
|
</v-layout>
|
||||||
|
</v-container>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
Reference in New Issue
Block a user