Merge branch '97-account-link-and-admin' into 'master'

Resolve "Account link and admin"

Closes #97

See merge request marcel.schwarz/2020ss-qbc-geofence-timetracking!77
This commit is contained in:
Tim Zieger 2020-05-28 15:41:34 +00:00
commit 19d01b1502

View File

@ -28,6 +28,14 @@
<v-list-item-title>Statistics</v-list-item-title> <v-list-item-title>Statistics</v-list-item-title>
</v-list-item-content> </v-list-item-content>
</v-list-item> </v-list-item>
<v-list-item @click="toAccounts" v-bind:class="{'d-none':loggedIn=='false'}">
<v-list-item-action>
<v-icon>mdi-account-details</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>Accounts</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item link to="/about"> <v-list-item link to="/about">
<v-list-item-action> <v-list-item-action>
<v-icon>mdi-information-outline</v-icon> <v-icon>mdi-information-outline</v-icon>
@ -41,7 +49,7 @@
<v-icon>mdi-account-group</v-icon> <v-icon>mdi-account-group</v-icon>
</v-list-item-action> </v-list-item-action>
<v-list-item-content> <v-list-item-content>
<v-list-item-title>Users</v-list-item-title> <v-list-item-title>Admin</v-list-item-title>
</v-list-item-content> </v-list-item-content>
</v-list-item> </v-list-item>
</v-list> </v-list>
@ -55,9 +63,15 @@
<v-spacer></v-spacer> <v-spacer></v-spacer>
<!-- Menu with account icon --> <!-- Menu with account icon -->
<v-menu v-model="menu" :close-on-content-click="false" :nudge-width="200" offset-y v-if="loggedIn == 'true'"> <v-menu
v-model="menu"
:close-on-content-click="false"
:nudge-width="200"
offset-y
v-if="loggedIn == 'true'"
>
<template v-slot:activator="{ on }"> <template v-slot:activator="{ on }">
<v-btn icon v-on="on" > <v-btn icon v-on="on">
<v-icon>mdi-account</v-icon> <v-icon>mdi-account</v-icon>
</v-btn> </v-btn>
</template> </template>
@ -70,10 +84,9 @@
</v-list-item-avatar> </v-list-item-avatar>
<v-list-item-content> <v-list-item-content>
<v-list-item-title >{{fullname}}</v-list-item-title> <v-list-item-title>{{fullname}}</v-list-item-title>
<v-list-item-subtitle >{{role}}</v-list-item-subtitle>
</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>
@ -96,30 +109,28 @@
<v-btn color="primary" text @click="logout">Logout</v-btn> <v-btn color="primary" text @click="logout">Logout</v-btn>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</v-menu> </v-menu>
<v-card v-if="loggedIn == 'false'"> <v-card v-if="loggedIn == 'false'">
<!-- Modal --> <!-- Modal -->
<v-row justify="center">
<v-row justify="center"> <v-dialog v-model="dialog" width="70%" persistent>
<v-dialog v-model="dialog" width="70%" persistent> <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-btn icon @click="dialog = false"> <v-icon>mdi-window-close</v-icon>
<v-icon>mdi-window-close</v-icon> </v-btn>
</v-btn> </v-card-actions>
</v-card-actions> <SignIn v-on:signIn="signIn" v-on:signUp="signUp" />
<SignIn v-on:signIn="signIn" v-on:signUp="signUp" /> <p id="loginError"></p>
<p id="loginError"></p> </v-card>
</v-card> </v-dialog>
</v-dialog> </v-row>
</v-row> </v-card>
</v-card>
</v-app-bar> </v-app-bar>
<!-- Routed pages are inserted here --> <!-- Routed pages are inserted here -->
@ -156,15 +167,16 @@ export default {
dialog: false, dialog: false,
menu: false, menu: false,
loggedIn: sessionStorage.getItem("loggedin"), loggedIn: sessionStorage.getItem("loggedin"),
fullname: sessionStorage.getItem("firstname") + " " + sessionStorage.getItem("lastname"), fullname:
role: sessionStorage.getItem("role") sessionStorage.getItem("firstname") +
" " +
sessionStorage.getItem("lastname")
}), }),
methods: { methods: {
forward() { forward() {
this.$router.push("/") this.$router.push("/");
}, },
signIn(loginData) { signIn(loginData) {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() { xhttp.onreadystatechange = function() {
@ -174,14 +186,12 @@ export default {
this.getResponseHeader("Authorization") this.getResponseHeader("Authorization")
); );
sessionStorage.setItem("loggedin", true); sessionStorage.setItem("loggedin", true);
} else if (this.status != 200 && this.status != 0) { } else if (this.status != 200 && this.status != 0) {
document.getElementById("loginError").innerHTML = document.getElementById("loginError").innerHTML =
"Login not successfull"; "Login not successfull";
} }
}; };
xhttp.open("POST", baseUri + "/login", false); xhttp.open("POST", baseUri + "/login", false);
xhttp.send( xhttp.send(
'{"username": "' + '{"username": "' +
@ -190,29 +200,32 @@ export default {
loginData.password + loginData.password +
'"}' '"}'
); );
if(sessionStorage.getItem("loggedin")== "true"){ if (sessionStorage.getItem("loggedin") == "true") {
sessionStorage.setItem("haveData", true); sessionStorage.setItem("haveData", true);
var whoxhttp = new XMLHttpRequest(); var whoxhttp = new XMLHttpRequest();
whoxhttp.onreadystatechange = function() { whoxhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) { if (this.readyState == 4 && this.status == 200) {
var userInformation = JSON.parse(whoxhttp.responseText); var userInformation = JSON.parse(whoxhttp.responseText);
sessionStorage.setItem("firstname", userInformation.firstname); sessionStorage.setItem("firstname", userInformation.firstname);
sessionStorage.setItem("lastname", userInformation.lastname); sessionStorage.setItem("lastname", userInformation.lastname);
sessionStorage.setItem("username", userInformation.username); sessionStorage.setItem("username", userInformation.username);
sessionStorage.setItem("role", userInformation.role.name);
this.fullname= sessionStorage.getItem("firstname") + " " + sessionStorage.getItem("lastname");
location.reload();
}
};
whoxhttp.open("GET", baseUri + "/whoami", false);
whoxhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt")); this.fullname =
sessionStorage.getItem("firstname") +
" " +
sessionStorage.getItem("lastname");
location.reload();
}
};
whoxhttp.open("GET", baseUri + "/whoami", false);
whoxhttp.send(null); whoxhttp.setRequestHeader(
location.reload(); "Authorization",
sessionStorage.getItem("jwt")
);
whoxhttp.send(null);
location.reload();
} }
}, },
signUp(signupData) { signUp(signupData) {
@ -241,12 +254,48 @@ export default {
'"}' '"}'
); );
}, },
logout(){ logout() {
sessionStorage.clear(); sessionStorage.clear();
sessionStorage.setItem("loggedin", false); sessionStorage.setItem("loggedin", false);
location.reload(); location.reload();
},
toAccounts() {
sessionStorage.setItem(
"timeTrackAccountListUser",
sessionStorage.getItem("username")
);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var usersInformation = JSON.parse(xhttp.responseText);
sessionStorage.setItem(
"timeTrackAccountListUserId",
usersInformation._links.self.href
);
}
};
xhttp.open(
"GET",
baseUri +
"/users/search/byUsername?username=" +
sessionStorage.getItem("username"),
false
);
xhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt"));
xhttp.send(null);
this.users = JSON.parse(sessionStorage.getItem("users"));
if (this.$route.path == "/timetrackaccounts" ) {
location.reload();
}else{
this.$router.push("/timetrackaccounts");
}
} }
}, },
created() { created() {