Merge branch '61-login-communication' into 'master'

Resolve "Login Communication"

Closes #61

See merge request marcel.schwarz/2020ss-qbc-geofence-timetracking!50
This commit is contained in:
Tim Zieger 2020-05-17 19:05:55 +00:00
commit fc813f14db
3 changed files with 49 additions and 6 deletions

View File

@ -53,6 +53,7 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte
HttpServletResponse res, HttpServletResponse res,
FilterChain chain, FilterChain chain,
Authentication auth) { Authentication auth) {
res.setHeader("Access-Control-Expose-Headers", "Authorization");
String token = JWT.create() String token = JWT.create()
.withSubject(((User) auth.getPrincipal()).getUsername()) .withSubject(((User) auth.getPrincipal()).getUsername())
.withExpiresAt(new Date(System.currentTimeMillis() + EXPIRATION_TIME)) .withExpiresAt(new Date(System.currentTimeMillis() + EXPIRATION_TIME))

View File

@ -51,12 +51,13 @@
<template v-slot:activator="{ on }"> <template v-slot:activator="{ on }">
<v-btn color="primary" dark v-on="on">Login</v-btn> <v-btn color="primary" dark v-on="on">Login</v-btn>
</template> </template>
<v-card class="main"> <v-card class="main">
<v-card-actions> <v-card-actions>
<v-spacer></v-spacer> <v-spacer></v-spacer>
<v-btn icon @click="dialog = false"><v-icon>mdi-window-close</v-icon></v-btn> <v-btn icon @click="dialog = false"><v-icon>mdi-window-close</v-icon></v-btn>
</v-card-actions> </v-card-actions>
<SignIn /> <SignIn v-on:signIn="signIn"/>
<p id="loginError" ></p>
</v-card> </v-card>
</v-dialog> </v-dialog>
</v-row> </v-row>
@ -81,7 +82,7 @@
</v-list-item-content> </v-list-item-content>
<v-list-item-action> <v-list-item-action>
</v-list-item-action> </v-list-item-action>
</v-list-item> </v-list-item>
</v-list> </v-list>
@ -92,7 +93,7 @@
<v-list-item> <v-list-item>
<v-list-item-action> <v-list-item-action>
<v-switch <v-switch
color="primary" color="primary"
:input-value="login" :input-value="login"
@change="login= !login" @change="login= !login"
@ -126,7 +127,9 @@
</template> </template>
<script> <script>
import SignIn from "./views/SignIn.vue"; import SignIn from "./views/SignIn.vue";
var baseUri = "http://backend:5000";
export default { export default {
components: { components: {
SignIn SignIn
@ -139,7 +142,31 @@ export default {
login: true, login: true,
dialog: false, dialog: false,
menu: false menu: false
}), }),
methods: {
signIn (loginData) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.status == 200 & this.readyState ==4) {
sessionStorage.setItem("jwt", this.getResponseHeader("Authorization"));
location.reload();
}else if(this.status != 200 && this.status !=0) {
document.getElementById("loginError").innerHTML="Login not successfull";
}
};
xhttp.open("POST", baseUri + "/login", true);
xhttp.send('{"username": "' + loginData.username +'", "password": "'+ loginData.password +'"}');
}
},
created() { created() {
this.$vuetify.theme.dark = true; this.$vuetify.theme.dark = true;
} }

View File

@ -22,12 +22,14 @@
<v-text-field <v-text-field
id="password" id="password"
label="Password" label="Password"
v-model="password"
name="Password" name="Password"
prepend-icon="mdi-key" prepend-icon="mdi-key"
type="password" type="password"
color="primary" color="primary"
/> />
</v-form> </v-form>
<p id="missing"></p>
</v-card-text> </v-card-text>
<div class="text-center mt-3"> <div class="text-center mt-3">
<v-btn rounded color="logowhite" outlined dark v-on:click="signin()">Sign In</v-btn> <v-btn rounded color="logowhite" outlined dark v-on:click="signin()">Sign In</v-btn>
@ -121,14 +123,27 @@
export default { export default {
data: () => ({ data: () => ({
step: 1, step: 1,
username: "" username: "",
password: "",
}), }),
props: { props: {
source: String source: String
}, },
methods: { methods: {
signin() { signin() {
console.log(this.username); if (this.username != "" && this.password != "") {
document.getElementById("missing").innerHTML= "";
const loginData = {
username: this.username,
password: this. password
}
this.$emit('signIn', loginData);
}else {
document.getElementById("missing").innerHTML= "Please fill out all fields";
}
} }
} }
}; };