Authentification Token

This commit is contained in:
2024-11-14 15:32:28 +01:00
parent ae577dc023
commit 86acedc8aa
10 changed files with 283 additions and 58 deletions

View File

@@ -13,7 +13,13 @@ exerciseStore.getAllExercises()
<template>
<v-btn variant="plain" icon="mdi-magnify" to="/search" />
<v-btn v-if="accountStore.userAccount.id == undefined" variant="plain" icon="mdi-account" to="/account/login" />
<v-btn
v-if="accountStore.userAccountToken == ''"
variant="plain"
icon="mdi-account"
to="/account/login"
/>
<v-btn v-else variant="plain" icon="mdi-account-check" to="/account/home" />
<div>
@@ -27,7 +33,7 @@ exerciseStore.getAllExercises()
</div>
<v-btn
v-if="accountStore.userAccount.accountRole != null &&
v-if="accountStore.userAccountToken != '' &&
accountStore.userAccount.accountRole.privilegeAdminPanel"
variant="plain"
icon="mdi-table-cog"

View File

@@ -7,10 +7,15 @@ export async function fetchAllAccounts() {
return await axios.get(BASE_URL)
}
export async function loginAccount(username: string, password: string) {
return await axios.post(BASE_URL + "/login", {
username: username,
password: password
export async function login(username: string, password: string) {
return await axios.get(BASE_URL + "/login?username=" + username + "&password=" + password)
}
export async function getAccount(token: string) {
return await axios.get(BASE_URL + "/account", {
headers: {
"Authorization": token
}
})
}
@@ -18,8 +23,12 @@ export async function registerAccount(account: AccountModel) {
return await axios.post(BASE_URL, account)
}
export async function updateAccount(account: AccountModel) {
return await axios.patch(BASE_URL, account)
export async function updateAccount(account: AccountModel, token: string) {
return await axios.patch(BASE_URL, account, {
headers: {
"Authorization": token
}
})
}
export async function deleteAccount(account: AccountModel) {

View File

@@ -11,7 +11,7 @@ const router = useRouter()
async function startLogin() {
accountStore.login()
.then(result => {
if (accountStore.userAccount.id != undefined) {
if (accountStore.userAccountToken != "") {
router.push("/account/home")
}
})
@@ -30,6 +30,7 @@ async function startLogin() {
:label="$t('account.userData.username')"
prepend-icon="mdi-account"
v-model="accountStore.loginData.username"
variant="outlined"
clearable
/>
</v-col>
@@ -41,6 +42,7 @@ async function startLogin() {
:label="$t('account.userData.password')"
prepend-icon="mdi-key"
type="password"
variant="outlined"
v-model="accountStore.loginData.password"
clearable
/>

View File

@@ -31,6 +31,8 @@ async function registerAccount() {
prepend-icon="mdi-account"
v-model="accountStore.registerData.username"
clearable
hide-details
variant="outlined"
:rules="getStringRules()"
/>
</v-col>
@@ -44,6 +46,8 @@ async function registerAccount() {
type="password"
v-model="accountStore.registerData.password"
clearable
hide-details
variant="outlined"
:rules="getPasswordRules()"
/>
</v-col>
@@ -56,6 +60,8 @@ async function registerAccount() {
prepend-icon="mdi-mail"
v-model="accountStore.registerData.email"
:rules="getEmailRules()"
variant="outlined"
hide-details
clearable
/>
</v-col>

View File

@@ -15,15 +15,13 @@ export function generateResultsPdf() {
const exerciseData = []
exerciseStore.exerciseGroups.forEach(group => {
group.exercises.forEach(exercise => {
exerciseData.push([
group.groupNr + "." + exercise.exerciseNr,
group.nameDe,
exercise.nameDe,
exercise.solved ? 'Ja' : 'Nein'
])
})
exerciseStore.exercises.forEach(exercise => {
exerciseData.push([
exercise.exerciseGroup.groupNr + "." + exercise.exerciseNr,
exercise.exerciseGroup.nameDe,
exercise.nameDe,
exercise.solved ? 'Ja' : 'Nein'
])
})
// Title and image
@@ -37,11 +35,9 @@ export function generateResultsPdf() {
// Progress total
doc.setFontSize(28)
doc.text("Hat " + exerciseStore.exerciseGroups.reduce((counter, group) => {
for (let exercise of group.exercises) {
if (exercise.solved) {
counter++
}
doc.text("Hat " + exerciseStore.exercises.reduce((counter, exercise) => {
if (exercise.solved) {
counter++
}
return counter
@@ -57,10 +53,19 @@ export function generateResultsPdf() {
})
// Footer
doc.setFontSize(12)
doc.text(["Grundlagen der IT-Sicherheit", "Fachgebiet Usable Security and Privacy", "Institut für IT-Sicherheit", "Leibniz Universität Hannover"], midPage, pageHeight - 30, { align: "center" })
doc.text(
[
"Grundlagen der IT-Sicherheit",
"Fachgebiet Usable Security and Privacy",
"Institut für IT-Sicherheit", "Leibniz Universität Hannover"
],
midPage, pageHeight - 30, { align: "center" }
)
doc.text(moment().format("DD.MM.YYYY, HH:mm:ss"), midPage, pageHeight - 8, { align: "center" })
// Save
doc.save("eventmaster-exercise-result.pdf")
}

View File

@@ -1,7 +1,7 @@
import { useLocalStorage } from "@vueuse/core";
import { AccountModel } from "../data/models/user/accountModel";
import { useFeedbackStore } from "./feedback.store";
import { deleteAccount, fetchAllAccounts, loginAccount, registerAccount, updateAccount } from "../data/api/accountApi";
import { deleteAccount, fetchAllAccounts, getAccount, login, registerAccount, updateAccount } from "../data/api/accountApi";
import { fetchUserOrders } from "../data/api/orderApi";
import { BannerStateEnum } from "../data/enums/bannerStateEnum";
import { AddressModel } from "../data/models/user/addressModel";
@@ -17,10 +17,11 @@ export const useAccountStore = defineStore("accountStore", {
accounts: ref<Array<AccountApiModel>>([]),
/** Useraccount which is currently logged in */
userAccountToken: useLocalStorage("hackmycart/accountStore/userAccountToken", ""),
userAccount: useLocalStorage("hackmycart/accountStore/userAccount", new AccountApiModel()),
/** User input on login screen */
// todo: Remove JSON!
loginData: ref<{ username: String, password: String}>(
{ username: "", password: "" }
),
@@ -62,15 +63,36 @@ export const useAccountStore = defineStore("accountStore", {
}
else
{
await loginAccount(this.loginData.username, this.loginData.password)
await login(this.loginData.username, this.loginData.password)
.then(async result => {
this.userAccount = result.data
this.userAccountToken = result.data.token
feedbackStore.addSnackbar(BannerStateEnum.ACCOUNTLOGINSUCCESSFUL)
getAccount(this.userAccountToken)
.then(account => {
this.userAccount = account.data
this.fetchInProgress = false
return true
feedbackStore.addSnackbar(BannerStateEnum.ACCOUNTLOGINSUCCESSFUL)
this.fetchInProgress = false
})
})
// await loginAccount(this.loginData.username, this.loginData.password)
// .then(async result => {
// this.userAccountId = result.data.id
// this.userLoggedIn = true
// fetchAddresses(result.data.id)
// .then(addresses => {
// })
// feedbackStore.addSnackbar(BannerStateEnum.ACCOUNTLOGINSUCCESSFUL)
// this.fetchInProgress = false
// return true
// })
.catch(error => {
if (error.status == 400) {
feedbackStore.addSnackbar(BannerStateEnum.ACCOUNTLOGINERROR)
@@ -129,10 +151,12 @@ export const useAccountStore = defineStore("accountStore", {
async updateAccount() {
const feedbackStore = useFeedbackStore()
await updateAccount(this.userAccount)
await updateAccount(this.userAccount, this.userAccountToken)
.then(res => {
if (res.status == 200) {
feedbackStore.addSnackbar(BannerStateEnum.ACCOUNTUPDATESUCCESSFUL)
this.userAccount = res.data
}
})
},
@@ -144,6 +168,7 @@ export const useAccountStore = defineStore("accountStore", {
const feedbackStore = useFeedbackStore()
this.userAccount = new AccountModel()
this.userAccountId = -1
this.loggedIn = false
feedbackStore.addSnackbar(BannerStateEnum.ACCOUNTLOGOUTSUCCESSFUL)
@@ -162,6 +187,10 @@ export const useAccountStore = defineStore("accountStore", {
})
},
async getAdresses() {
},
/**
* Remove an address from the user model
*