diff --git a/src/components/LoginForm.vue b/src/components/LoginForm.vue index c4753dc4fdbfe53d016bf2cebf62cffbad4bfda4..9d8afb4563c0f7c182fad24eda2b40016abbd784 100644 --- a/src/components/LoginForm.vue +++ b/src/components/LoginForm.vue @@ -102,7 +102,7 @@ import useVuelidate from "@vuelidate/core"; import { required, email, helpers } from "@vuelidate/validators"; import { doLogin } from "@/utils/apiutil"; -//import { parseUserFromToken } from "@/utils/token-utils"; +import { parseUserFromToken } from "@/utils/token-utils"; export default { name: "LoginForm.vue", @@ -158,12 +158,15 @@ export default { if (loginResponse.isLoggedIn === false) { this.message = "Feil e-post/passord"; this.$store.commit("logout"); - } - else if (loginResponse.isLoggedIn === true) { + } else if (loginResponse.isLoggedIn === true) { this.$store.commit("saveToken", loginResponse.token); - await this.$router.push("/"); - } - else { + + let user = parseUserFromToken(loginResponse.token); + console.log(user); + let id = user.accountId; + console.log(id); + this.$router.push("/profile/" + id); + } else { console.log("Something went wrong"); } }, diff --git a/src/components/UserProfileComponents/LargeProfileCard.vue b/src/components/UserProfileComponents/LargeProfileCard.vue index b27bd17390af37ac6aca878e982ee7b1e46e2c83..7c5c036f8103be9c42b62d0c818dfa229af2f8cd 100644 --- a/src/components/UserProfileComponents/LargeProfileCard.vue +++ b/src/components/UserProfileComponents/LargeProfileCard.vue @@ -74,7 +74,7 @@ alt="Profile picture" /> <h5 class="mb-1 text-xl font-medium text-gray-900 dark:text-white"> - {{ user.first_name }} {{ user.last_name }} + {{ user.firstName }} {{ user.lastName }} </h5> <div> <rating-component :rating="renterRating" :ratingType="'Leietaker'" /> @@ -94,8 +94,8 @@ <script> import RatingComponent from "@/components/UserProfileComponents/RatingComponent.vue"; -import { parseUserFromToken } from "@/utils/token-utils"; -import { getUser /* getRenterRating, getOwnerRating */ } from "@/utils/apiutil"; +import { parseCurrentUser } from "@/utils/token-utils"; +import { getUser, getRenterRating, getOwnerRating } from "@/utils/apiutil"; import router from "@/router"; export default { @@ -106,8 +106,8 @@ export default { currentUser: {}, id: -1, isCurrentUser: false, - renterRating: 0, //getRenterRating(this.userID), - ownerRating: 0, //getOwnerRating(this.userID), + renterRating: -1, //getRenterRating(this.userID), + ownerRating: -1, //getOwnerRating(this.userID), dropdown: false, }; }, @@ -116,19 +116,16 @@ export default { }, methods: { async getUser() { - this.currentUser = parseUserFromToken(); + this.currentUser = parseCurrentUser(); this.id = router.currentRoute.value.params.id; if (this.id == this.currentUser.account_id) { this.isCurrentUser = true; this.user = this.currentUser; return; } - let getuser = await getUser(this.id); - this.user = { - account_id: getuser.userID, - first_name: getuser.firstName, - last_name: getuser.lastName, - }; + this.user = await getUser(this.id); + this.renterRating = getRenterRating(this.id); + this.ownerRating = getOwnerRating(this.id); }, getProfilePicture() { /* if (this.user.picture != "") { diff --git a/src/components/UserProfileComponents/RatingComponent.vue b/src/components/UserProfileComponents/RatingComponent.vue index f79ff22085c106a75f32e0b8294c7ef3c02e9801..662b9607911697c89421e7c4727b44caa93dfe4c 100644 --- a/src/components/UserProfileComponents/RatingComponent.vue +++ b/src/components/UserProfileComponents/RatingComponent.vue @@ -1,5 +1,5 @@ <template> - <ul class="flex justify-center"> + <ul v-if="compRating != -1" class="flex justify-center"> <li> <p class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400"> {{ ratingType }}: @@ -23,6 +23,18 @@ </p> </li> </ul> + <ul v-else class="flex justify-center"> + <li> + <p class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400"> + {{ ratingType }}: + </p> + </li> + <li> + <p class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400"> + Rating ikke tilgjengelig + </p> + </li> + </ul> </template> <script> diff --git a/src/utils/apiutil.js b/src/utils/apiutil.js index 887d222831d94469e22f88bdef28c13672fb02db..94dee186948baab225e5824ec5ec4b1fce8f59ba 100644 --- a/src/utils/apiutil.js +++ b/src/utils/apiutil.js @@ -4,7 +4,7 @@ import { tokenHeader } from "./token-utils"; const API_URL = process.env.VUE_APP_BASEURL; export function doLogin(loginRequest) { - const auth = {isLoggedIn: false, token: ""}; + const auth = { isLoggedIn: false, token: "" }; return axios .post(API_URL + "login/authentication", loginRequest) .then((response) => { @@ -48,7 +48,7 @@ export async function getUser(userid) { export function getRenterRating(userid) { return axios - .get(API_URL + "users/" + userid + "", { + .get(API_URL + "rating/" + userid + "/as_owner", { headers: tokenHeader(), }) .then((response) => { @@ -61,7 +61,7 @@ export function getRenterRating(userid) { export function getOwnerRating(userid) { return axios - .get(API_URL + "users/" + userid + "", { + .get(API_URL + "rating/" + userid + "/as_renter", { headers: tokenHeader(), }) .then((response) => { diff --git a/src/utils/token-utils.js b/src/utils/token-utils.js index baf77654f57a548de5a335038ed9fed4628d80e2..ba37787fbb3f43cfdce7ba11aba70d2d3c8b5bff 100644 --- a/src/utils/token-utils.js +++ b/src/utils/token-utils.js @@ -6,7 +6,11 @@ export function tokenHeader() { return { Authorization: token }; } -export function parseUserFromToken() { +export function parseCurrentUser() { let token = store.state.user.token; return jwt_decode(token); } + +export function parseUserFromToken(token) { + return jwt_decode(token); +}