Implement exercise 1.1 (open help page)

This commit is contained in:
2024-11-14 08:09:06 +01:00
parent 20b9a59257
commit c2fe6ee3d2
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
Exercise.findOne({
where: {
[Op.and] : [
{
exerciseNr: req.params.exerciseNr
},
{
"$exerciseGroup.groupNr$": req.params.groupNr
}
})
.then(exercise => {
exercise.update({ solved: req.params.state == "1"})
res.status(200).send()
]
},
include: [ ExerciseGroup ]
})
.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)
}