Implement exercise 1.1 (open help page)

This commit is contained in:
2024-11-14 08:09:06 +01:00
parent 2b14f76d4b
commit c0d110f386
8 changed files with 126 additions and 79 deletions

View File

@@ -10,16 +10,14 @@
"nameEn": "Register",
"exerciseNr": 1,
"descriptionDe": "Erstelle einen neuen Account im Online Shop",
"descriptionEn": "Create a new account in the online shop",
"solved": false
"descriptionEn": "Create a new account in the online shop"
},
{
"nameDe": "Ein Ticket kaufen",
"nameEn": "Buy a ticket",
"exerciseNr": 2,
"descriptionDe": "Suche dir ein Event deiner Wahl und kaufe dafür ein Ticket",
"descriptionEn": "Search for an event of choice and buy a ticket for",
"solved": false
"descriptionEn": "Search for an event of choice and buy a ticket for"
}
]
},
@@ -33,16 +31,14 @@
"nameEn": "Access Help Page",
"exerciseNr": 1,
"descriptionDe": "Manipuliere die URL so, dass du die Hilfe-Seite erreichen kannst",
"descriptionEn": "Manipulate the URL and access the help page",
"solved": false
"descriptionEn": "Manipulate the URL and access the help page"
},
{
"nameDe": "Das ausgebuchte Konzert buchen",
"nameEn": "Book the unavailable concert",
"exerciseNr": 2,
"descriptionDe": "Manipuliere die URL so, dass du das ausgebuchte Konzert aufrufen kannst und buche ein Ticket dafür",
"descriptionEn": "Manipulate the URL and access the sold out concert and buy a ticket",
"solved": false
"descriptionEn": "Manipulate the URL and access the sold out concert and buy a ticket"
}
]
},
@@ -56,24 +52,21 @@
"nameEn": "Readout account names",
"exerciseNr": 1,
"descriptionDe": "Lasse dir alle Accountnamen über das Suchfeld ausgeben",
"descriptionEn": "Readout all account names via the search field",
"solved": false
"descriptionEn": "Readout all account names via the search field"
},
{
"nameDe": "Passwort auslesen",
"nameEn": "Readout password",
"exerciseNr": 2,
"descriptionDe": "Versuche ein Passwort aus der Datenbank eines Accounts auszulesen",
"descriptionEn": "Get the password of an account from the database",
"solved": false
"descriptionEn": "Get the password of an account from the database"
},
{
"nameDe": "Verändere deine Account Berechtigungen",
"nameEn": "Change your account role",
"exerciseNr": 3,
"descriptionDe": "Ändere die Berechtigungen deines Accounts",
"descriptionEn": "Change the privileges of your account",
"solved": false
"descriptionEn": "Change the privileges of your account"
}
]
},
@@ -87,24 +80,21 @@
"nameEn": "Hello World!",
"exerciseNr": 1,
"descriptionDe": "Nimm dir eine URL des Shops und erweitere sie mit JavaScript Code so, dass beim Öffnen des Links eine 'Hallo Welt' Nachricht erscheint",
"descriptionEn": "Take an URL of the shop and extend it with JavaScript code so that a 'Hello World' message appears whent the link is opened",
"solved": false
"descriptionEn": "Take an URL of the shop and extend it with JavaScript code so that a 'Hello World' message appears whent the link is opened"
},
{
"nameDe": "Ein externes Script aufrufen",
"nameEn": "Run an external script",
"exerciseNr": 2,
"descriptionDe": "Bearbeite die URL des Shops so, dass du das Script ausführen kannst",
"descriptionEn": "Create an URL of the shop, which calls the script",
"solved": false
"descriptionEn": "Create an URL of the shop, which calls the script"
},
{
"nameDe": "Hacken mit eigenem Script",
"nameEn": "Hack with your script",
"exerciseNr": 3,
"descriptionDe": "Schreibe eine JavaScript Datei, lade sie über das Admin Panel hoch und kreiere eine URL, welche es ausführt",
"descriptionEn": "Write our own JavaScript file, upload it via Admin Panel and create an URL to execute it",
"solved": false
"descriptionEn": "Write our own JavaScript file, upload it via Admin Panel and create an URL to execute it"
}
]
}

View File

@@ -21,11 +21,9 @@ account.get("/", (req: Request, res: Response) => {
// Login user
account.post("/login", async (req: Request, res: Response) => {
// Using raw SQL code for SQL injections!
// todo: Inner join
const [results, metadata] =
await sequelize.query(
"SELECT * FROM Accounts " +
"INNER JOIN Addresses ON Accounts.id=Addresses.accountId " +
"WHERE (username='" + req.body.username +
"' AND password='" + req.body.password + "')")
@@ -42,6 +40,7 @@ account.post("/login", async (req: Request, res: Response) => {
}
if (results.length != 0) {
// Status: 200 OK
res.status(200).json(results[0])
} else {

View File

@@ -1,3 +1,4 @@
import { Op } from "sequelize";
import { Exercise } from "../models/exercises/exercise.model";
import { ExerciseGroup } from "../models/exercises/exerciseGroup.model";
import { Request, Response, Router } from "express";
@@ -27,19 +28,47 @@ exercises.get("/", (req: Request, res: Response) => {
* @param state New state boolean
*/
exercises.post("/:groupNr/:exerciseNr/:state", (req: Request, res: Response) => {
ExerciseGroup.findOne({
where: { groupNr: req.params.groupNr }
})
.then(group => {
Exercise.findOne({
where: {
exerciseNr: req.params.exerciseNr,
exerciseGroupId: group.id
[Op.and] : [
{
exerciseNr: req.params.exerciseNr
},
{
"$exerciseGroup.groupNr$": req.params.groupNr
}
]
},
include: [ ExerciseGroup ]
})
.then(exercise => {
exercise.update({ solved: req.params.state == "1"})
res.status(200).send()
.then(async exercise => {
let changed = false
if (exercise.dataValues.solved != (req.params.state == "1")) {
await exercise.update({ solved: req.params.state == "1" })
changed = true
}
res.status(200).json({
exercise: exercise,
changed: changed
})
})
// ExerciseGroup.findOne({
// where: { groupNr: req.params.groupNr }
// })
// .then(group => {
// Exercise.findOne({
// where: {
// exerciseNr: req.params.exerciseNr,
// exerciseGroupId: group.id
// }
// })
// .then(exercise => {
// exercise.update({ solved: req.params.state == "1"})
// res.status(200).send()
// })
// })
})

View File

@@ -131,7 +131,6 @@ location.get("/search", (req: Request, res: Response) => {
include: [ City, Concert ]
})
.then(locations => {
console.log(locations)
res.status(200).json(locations)
})
})

View File

@@ -64,6 +64,7 @@ export async function prepopulateExerciseDatabase() {
.then(async dataset => {
for (let exercise of exerciseGroup.exercises) {
exercise["exerciseGroupId"] = dataset.id
exercise["solved"] = false
await Exercise.create(exercise)
}

View File

@@ -1,9 +1,13 @@
<script setup lang="ts">
import { useAccountStore } from '@/stores/account.store';
import { useBasketStore } from '@/stores/basket.store';
import { useExerciseStore } from '@/stores/exercise.store';
const accountStore = useAccountStore()
const basketStore = useBasketStore()
const exerciseStore = useExerciseStore()
exerciseStore.getAllExercises()
</script>
<template>
@@ -30,6 +34,12 @@ const basketStore = useBasketStore()
to="/admin"
/>
<v-btn variant="plain" icon="mdi-help" to="/help" />
<v-btn
v-if="exerciseStore.helpPageVisible"
variant="plain"
icon="mdi-help"
to="/help"
/>
<v-btn variant="plain" icon="mdi-cog" to="/preferences"/>
</template>

View File

@@ -9,7 +9,7 @@ import { LanguageEnum } from '@/data/enums/languageEnum';
const exerciseStore = useExerciseStore()
const preferencesStore = usePreferencesStore()
exerciseStore.getAllExercises()
exerciseStore.solveExercise(1, 1)
function getDotColor(exerciseGroupNr: number) {
switch(exerciseGroupNr) {

View File

@@ -11,7 +11,9 @@ export const useExerciseStore = defineStore("exerciseStore", {
exercises: ref<Array<ExerciseModel>>([]),
/** Request to server sent, waiting for data response */
fetchInProgress: ref(false)
fetchInProgress: ref(false),
helpPageVisible: ref(false)
}),
actions: {
@@ -24,10 +26,26 @@ export const useExerciseStore = defineStore("exerciseStore", {
await fetchAllExerciseGroups()
.then(result => {
this.exercises = result.data
this.helpPageVisible = this.getExercise(1, 1).solved
this.fetchInProgress = false
})
},
/**
* Get a exercise by group and exercise number
*
* @param exerciseGroupNr Number of group of exercise
* @param exerciseNr Number of exercise in group
*
* @returns ExerciseModel
*/
getExercise(exerciseGroupNr: number, exerciseNr: number): ExerciseModel {
return this.exercises.find((exercise: ExerciseModel) => {
return exercise.exerciseNr == exerciseNr && exercise.exerciseGroup.groupNr == exerciseGroupNr
})
},
/**
* Mark an exercise as solved
*
@@ -42,9 +60,10 @@ export const useExerciseStore = defineStore("exerciseStore", {
this.fetchInProgress = true
// Change only if the exercise is not solved
if(!this.exerciseGroups[exerciseGroupNr].exercises[exerciseNr - 1].solved) {
updateExercise(exerciseGroupNr, exerciseNr, true)
.then(result => {
if (result.data.changed) {
let bannerState = BannerStateEnum.ERROR
switch(exerciseGroupNr) {
@@ -90,8 +109,8 @@ export const useExerciseStore = defineStore("exerciseStore", {
feedbackStore.changeBanner(bannerState)
this.getAllExercises()
})
}
})
}
}
})