Skip to content
Snippets Groups Projects
Commit ddf35b37 authored by Gilgard's avatar Gilgard
Browse files

Merge branch 'main' into edit-listing

parents bb57e150 89521694
No related branches found
No related tags found
1 merge request!133Edit listing
Pipeline #181754 passed
......@@ -39,7 +39,6 @@
<script>
import { LeaveCommunity } from "@/utils/apiutil";
import CommunityAdminService from "@/services/community-admin.service";
export default {
name: "CommunityHamburger",
......@@ -57,13 +56,12 @@ export default {
this.$router.push("/");
},
},
async mounted() {
this.admin = await CommunityAdminService.isUserAdmin(
this.$route.params.communityID
);
},
created() {
this.communityID = this.$route.params.communityID;
if (!Array.isArray(this.$store.state.user.adminList)) return;
this.admin = this.$store.state.user.adminList.includes(
parseInt(this.communityID)
);
},
};
</script>
......@@ -94,6 +94,7 @@ import useVuelidate from "@vuelidate/core";
import { required, email, helpers } from "@vuelidate/validators";
import { doLogin } from "@/utils/apiutil";
import Button from "@/components/BaseComponents/ColoredButton";
import UserService from "@/services/user.service";
export default {
name: "LoginForm.vue",
......@@ -151,6 +152,8 @@ export default {
this.message = "Feil e-post/passord";
} else if (loginResponse.isLoggedIn === true) {
this.$store.commit("saveToken", loginResponse.token);
const adminList = await UserService.getAdminList();
this.$store.commit("addAdminList", adminList);
await this.$router.push("/");
}
},
......
......@@ -175,6 +175,7 @@ import {
helpers,
} from "@vuelidate/validators";
import Button from "@/components/BaseComponents/ColoredButton";
import UserService from "@/services/user.service";
// const isEmailTaken = (value) =>
// fetch(`/api/unique/${value}`).then((r) => r.json()); // check the email in the server
......@@ -263,8 +264,9 @@ export default {
await this.$router.push("/login");
return;
}
this.$store.commit("saveToken", loginResponse.token);
const adminList = await UserService.getAdminList();
this.$store.commit("addAdminList", adminList);
await this.$router.push("/");
},
async sendRegisterRequest() {
......
......@@ -140,6 +140,9 @@ export default {
}
return this.profileImage.src;
},
adminList() {
return this.$store.state.user.adminList;
},
},
methods: {
async getUser() {
......@@ -172,7 +175,7 @@ export default {
},
async deleteUser(){
await UserService.deleteUser();
this.$store.commit("logout");
this.logout()
},
},
beforeMount() {
......
......@@ -15,6 +15,12 @@ function guardRoute(to, from, next) {
}
}
function isAdmin(to, from, next) {
if (store.state.user.adminList.includes(parseInt(from.params.communityID)))
next();
else next("/");
}
const routes = [
{
path: "/",
......@@ -114,7 +120,7 @@ const routes = [
path: "/community/:communityID/admin",
name: "CommunityAdminView",
component: () => import("@/views/CommunityViews/AdminView.vue"),
beforeEnter: guardRoute,
beforeEnter: isAdmin,
},
{
path: "/itempage/:id",
......
......@@ -15,6 +15,19 @@ class UserService {
.catch((err) => console.error(err));
}
async getAdminList() {
return await axios
.get(API_URL + "communities/admin", {
headers: tokenHeader(),
})
.then((res) => {
return res.data;
})
.catch((err) => {
console.error(err);
});
}
async getUserRatingAverage(userId) {
return await axios
.get(API_URL + "rating/" + userId + "/average", {
......
const state = {
token: null,
adminList: [],
};
const mutations = {
......@@ -9,6 +10,14 @@ const mutations = {
saveToken(state, token) {
state.token = token;
},
addAdminList(state, communityIDArray) {
if (!Array.isArray(communityIDArray)) return;
if (communityIDArray.length === 0) return;
for (let i = 0; i < communityIDArray.length; i++) {
if (isNaN(communityIDArray[i])) continue;
state.adminList.push(communityIDArray[i]);
}
},
};
export default {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment