This commit is contained in:
2018-11-08 01:08:09 +00:00
parent 063b68c9b9
commit 8c7a001bca
4 changed files with 60 additions and 40 deletions

View File

@@ -1,8 +1,11 @@
import logger from "../utils/logit";
export default {
status(response) {
if (response.status >= 200 && response.status < 300) {
return Promise.resolve(response);
} else {
logger.log("API error", response.statusText);
return Promise.reject(new Error(response.statusText));
}
},

View File

@@ -1,11 +1,10 @@
import config from "../utils/config";
import api from "./apiutil";
import { processLogin, processLogout } from "../utils/auth";
import { processLogin, processLogout } from "../utils/authUtil";
export default {
async authenticate(login, password) {
return (
fetch(config.apiUrl + "auth", {
return fetch(config.apiUrl + "auth", {
method: "post",
mode: "cors",
headers: {
@@ -23,15 +22,9 @@ export default {
.then(() => {
return Promise.resolve(true);
}) //succeeded, nothing to return
// .then(function(data) {
// //todo: this should just return a bool on successful login and let the util\auth handle storing token etc
// //router will handle views available based on roles etc so login only really needs to know if it succeeded or not.
// return data;
// })
.catch(function(error) {
processLogout();
return Promise.reject(error);
})
);
});
}
};

View File

@@ -1,5 +1,3 @@
/* eslint-disable */
import decode from "jwt-decode";
import config from "./config";
import logger from "./logit";
@@ -131,8 +129,8 @@ export function setToken(token) {
}
export function isLoggedIn() {
const token = getToken();
return !!token && !isTokenExpired(token);
//const token = getToken();
return !!config.apiToken && !isTokenExpired(config.apiToken);
}
function getTokenExpirationDate(encodedToken) {

View File

@@ -1,11 +1,37 @@
<template>
<div id="login">
<v-container fluid>
<v-layout row wrap>
<v-flex xs12 class="text-xs-center" mt-5>
<h1>Login</h1>
<input type="text" name="username" v-model="input.username" placeholder="Username">
<input type="password" name="password" v-model="input.password" placeholder="Password">
<button type="button" v-on:click="login()">Login</button>
<button type="button" v-on:click="showlog()">ShowLog</button>
</div>
</v-flex>
<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>
<script>