Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"axios": "^1.7.2",
"core-js": "^3.33.2",
"file-saver": "^2.0.5",
"javascript-time-ago": "^2.5.11",
"jszip": "^3.10.1",
"mosha-vue-toastify": "^1.0.23",
"pinia": "^2.3.1",
Expand Down
17 changes: 3 additions & 14 deletions client/src/components/TopupPayment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>

<v-sheet class="d-flex flex-column pa-5 align-center" color="primary">
<p class="font-weight-bold">${{ balance }}</p>
<p class="font-weight-bold">${{ getTotalBalance }}</p>
<span class="text-disabled text-capitalize mt-1"
>current balance</span
>
Expand Down Expand Up @@ -111,7 +111,7 @@
</v-row>
</template>
<script setup>
import { ref, watch } from "vue";
import { ref } from "vue";
import BaseInput from "./Form/BaseInput.vue";
import BaseButton from "./Form/BaseButton.vue";
import userService from "@/services/userService";
Expand All @@ -130,8 +130,7 @@ const loading = ref(false);
const verifyVoucher = ref(false);
const toast = ref(null);
const store = useUserStore();
const { user } = storeToRefs(store);
const balance = ref(user.value.balance + user.value.voucher_balance);
const { user, getTotalBalance } = storeToRefs(store);
const defaultCard = ref(user.value.stripe_default_payment_id);
const voucher = ref();
const amount = ref(null);
Expand Down Expand Up @@ -187,14 +186,4 @@ async function chargeBalance() {
await store.getUserInfo();
});
}

watch(
user,
(newVal) => {
if (newVal) {
balance.value = newVal.balance;
}
},
{ immediate: true }
);
</script>
4 changes: 2 additions & 2 deletions client/src/layouts/default/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</v-btn>
</v-toolbar-items>
<v-btn class="text-capitalize" flat>
Balance: ${{ user?.balance }}
Balance: ${{ getTotalBalance }}
</v-btn>
<v-menu id="notifications" location="bottom">
<template v-slot:activator="{ props }">
Expand Down Expand Up @@ -133,7 +133,7 @@ const drawer = ref(false);
const isActive = ref(0);
const toast = ref(null);
const store = useUserStore();
const { user, isLoading, notifications } = storeToRefs(store);
const { user, isLoading, notifications, getTotalBalance } = storeToRefs(store);

const navItems = ref([
{ title: "Home", path: "/" },
Expand Down
36 changes: 28 additions & 8 deletions client/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import Account from "@/views/Account.vue";
import VM from "@/views/VM.vue";
import Admin from "@/views/Admin.vue";
import NewPassword from "@/views/Newpassword.vue";
import ProfileTab from "@/views/tabs/Profile.vue";
import PaymentsTab from "@/views/tabs/Payments.vue";
import Invoices from "@/views/tabs/Invoices.vue";
import ChangePassword from "@/views/tabs/ChangePassword.vue";
import AuditLogs from "@/views/tabs/AuditLogs.vue";
import DeleteAccount from "@/views/tabs/DeleteAccount.vue";
import ProfileTab from "@/views/accManagemenTabs/Profile.vue";
import PaymentsTab from "@/views/accManagemenTabs/Payments.vue";
import Invoices from "@/views/accManagemenTabs/Invoices.vue";
import ChangePassword from "@/views/accManagemenTabs/ChangePassword.vue";
import AuditLogs from "@/views/accManagemenTabs/AuditLogs.vue";
import DeleteAccount from "@/views/accManagemenTabs/DeleteAccount.vue";
import Deploy from "@/views/Deploy.vue";
import Home from "@/views/HomeWrapper.vue";
import Requests from "@/views/adminTabs/Requests.vue";
import History from "@/views/adminTabs/History.vue";

const routes = [
{
Expand Down Expand Up @@ -145,10 +147,28 @@ const routes = [
path: "/admin",
name: "Admin",
component: Admin,
beforeEnter(to, from, next) {
const store = useUserStore();

if (!store.isAdmin) {
next("/");
}
next();
},
meta: {
layout: "Default",
requiresAuth: true,
},
children: [
{
path: "",
component: Requests,
},
{
path: "history",
component: History,
},
],
},
{
path: "/logout",
Expand All @@ -171,13 +191,13 @@ const router = createRouter({
});

router.beforeEach(async (to, from, next) => {
const isAuthenticated = localStorage.getItem("token") !== null;
const store = useUserStore();
const { isAuthenticated, user } = store;

if (to.meta.requiresAuth && !isAuthenticated) {
next("/");
} else {
if (!store.user && isAuthenticated) await store.getUserInfo();
if (!user && isAuthenticated) await store.getUserInfo();
next();
}
});
Expand Down
10 changes: 4 additions & 6 deletions client/src/services/userService.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export default {

// Deployments
async getDeploymentsCount() {
return await authClient().get("/deployment/count");
return await authClient().get("/deployments/count");
},

// Vouchers
Expand All @@ -271,8 +271,8 @@ export default {
return await authClient().put("/voucher");
},

async generateVoucher(length, vms, public_ips) {
return await authClient().post("/voucher", { length, vms, public_ips });
async generateVoucher(balance, length) {
return await authClient().post("/voucher", { balance, length });
},

async getAuditEvents() {
Expand Down Expand Up @@ -323,8 +323,6 @@ export default {

// setting next launch value
async setNextLaunch(value) {
return await authClient().put("/nextlaunch", {
launched: value,
});
return await authClient().put("/nextlaunch", { launched: value });
},
};
18 changes: 14 additions & 4 deletions client/src/store/UserStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export const useUserStore = defineStore("userStore", {
isLoaded: false,
notifications: [],
maintenance: false,
next_launch: false,
next_launch_admin: false,
next_launch_admin: true,
isAuthenticated: localStorage.getItem("token"),
}),
actions: {
Expand All @@ -33,7 +32,7 @@ export const useUserStore = defineStore("userStore", {
} catch (error) {
if (error.response.status == 401) {
localStorage.removeItem("token");
router.push("/login");
router.push("/");
return error;
}
return error;
Expand All @@ -60,13 +59,21 @@ export const useUserStore = defineStore("userStore", {
try {
const response = await userService.nextLaunch();
const { launched } = response.data.data;
this.next_launch = launched;
this.next_launch_admin = launched;
} catch (error) {
return error;
}
},

async setNextLaunch(value) {
try {
const response = await userService.setNextLaunch(value);
return response;
} catch (error) {
return error;
}
},

async checkMaintenance() {
try {
const response = await userService.maintenance();
Expand All @@ -79,5 +86,8 @@ export const useUserStore = defineStore("userStore", {
},
getters: {
isUserLoaded: (state) => state.isLoaded,
isNextLaunchEnabled: (state) => state.next_launch_admin,
getTotalBalance: (state) => state.user? state.user.balance + state.user.voucher_balance : 0,
isAdmin: (state) => state.user.admin,
},
});
Loading