Improve exercise solution of 2.1, 2.2, 2.3 and 2.5
This commit is contained in:
@@ -137,7 +137,6 @@ band.get("/search", async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
// On stacked prompts, execute last prompt
|
// On stacked prompts, execute last prompt
|
||||||
if (prompts.length > 1) {
|
if (prompts.length > 1) {
|
||||||
console.log(prompts[prompts.length - 2])
|
|
||||||
const [results, metadata] =
|
const [results, metadata] =
|
||||||
await sequelize.query(prompts[prompts.length - 2])
|
await sequelize.query(prompts[prompts.length - 2])
|
||||||
|
|
||||||
@@ -154,6 +153,9 @@ band.get("/search", async (req: Request, res: Response) => {
|
|||||||
.then(bands => {
|
.then(bands => {
|
||||||
res.status(200).json(bands)
|
res.status(200).json(bands)
|
||||||
})
|
})
|
||||||
|
.catch(e => {
|
||||||
|
res.status(200).send()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ import { load } from "exifreader"
|
|||||||
export async function loadLicense(url: string){
|
export async function loadLicense(url: string){
|
||||||
let result = ""
|
let result = ""
|
||||||
|
|
||||||
|
try {
|
||||||
await load(url)
|
await load(url)
|
||||||
.then(tags => {
|
.then(tags => {
|
||||||
result = tags["Copyright"]["description"] + " by " + tags["Artist"]["description"]
|
result = tags["Copyright"]["description"] + " by " + tags["Artist"]["description"]
|
||||||
})
|
})
|
||||||
.catch(e => {})
|
} catch {}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@@ -100,6 +100,18 @@ export const useAccountStore = defineStore("accountStore", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async refreshAccount() {
|
||||||
|
getAccount(this.userAccountToken)
|
||||||
|
.then(response => {
|
||||||
|
this.userAccount = response.data
|
||||||
|
|
||||||
|
this.fetchInProgress = false
|
||||||
|
|
||||||
|
this.privilegeBuy = true
|
||||||
|
this.adminPanelVisible = response.data.accountRole.privilegeAdminPanel
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a new account to the database
|
* Register a new account to the database
|
||||||
* Log in on success
|
* Log in on success
|
||||||
|
|||||||
@@ -5,17 +5,22 @@ import { fetchLocationsBySearchTerm } from "../data/api/locationApi";
|
|||||||
import { fetchConcertsBySearchTerm } from "../data/api/concertApi";
|
import { fetchConcertsBySearchTerm } from "../data/api/concertApi";
|
||||||
import { ConcertApiModel } from "@/data/models/acts/concertApiModel";
|
import { ConcertApiModel } from "@/data/models/acts/concertApiModel";
|
||||||
import { useExerciseStore } from "./exercise.store";
|
import { useExerciseStore } from "./exercise.store";
|
||||||
|
import { AccountApiModel } from "@/data/models/user/accountApiModel";
|
||||||
|
import { LocationApiModel } from "@/data/models/locations/locationApiModel";
|
||||||
|
import { BandApiModel } from "@/data/models/acts/bandApiModel";
|
||||||
|
import { useBandStore } from "./band.store";
|
||||||
|
import { useAccountStore } from "./account.store";
|
||||||
|
|
||||||
export const useSearchStore = defineStore("searchStore", {
|
export const useSearchStore = defineStore("searchStore", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
/** Search term */
|
/** Search term */
|
||||||
searchTerm: ref(""),
|
searchTerm: ref<string>(""),
|
||||||
|
|
||||||
/** Band results */
|
/** Band results */
|
||||||
bands: ref(),
|
bands: ref<Array<BandApiModel>>([]),
|
||||||
|
|
||||||
/** Location results */
|
/** Location results */
|
||||||
locations: ref(),
|
locations: ref<Array<LocationApiModel>>([]),
|
||||||
|
|
||||||
/** Concert results */
|
/** Concert results */
|
||||||
concerts: ref<Array<ConcertApiModel>>([]),
|
concerts: ref<Array<ConcertApiModel>>([]),
|
||||||
@@ -37,28 +42,63 @@ export const useSearchStore = defineStore("searchStore", {
|
|||||||
this.alreadySearched = true
|
this.alreadySearched = true
|
||||||
this.fetchInProgress = true
|
this.fetchInProgress = true
|
||||||
|
|
||||||
// Exercise solutions
|
/**
|
||||||
// todo: Rewrite to avoid easy exercise solution
|
* Fetch all bands by this.searchTerm
|
||||||
if (this.searchTerm.endsWith("'); SELECT * FROM Accounts; --")) {
|
*/
|
||||||
|
await fetchBandsBySearchTerm(this.searchTerm)
|
||||||
|
.then(async result => {
|
||||||
|
this.bands = result.data
|
||||||
|
|
||||||
|
// Check for exercise solution
|
||||||
|
if (result.data.length != 0) {
|
||||||
|
// Exercise 2.1
|
||||||
|
if (this.bands[0].username != undefined) {
|
||||||
exerciseStore.solveExercise(2, 1)
|
exerciseStore.solveExercise(2, 1)
|
||||||
} else if (this.searchTerm.endsWith("'); SELECT * FROM AccountRoles; --")) {
|
console.log("Exercise 2.1 solved")
|
||||||
|
}
|
||||||
|
// Exercise 2.2
|
||||||
|
else if (this.bands[0].privilegeAdminPanel != undefined) {
|
||||||
exerciseStore.solveExercise(2, 2)
|
exerciseStore.solveExercise(2, 2)
|
||||||
} else if (this.searchTerm.includes("'); UPDATE Accounts SET accountRoleId = 2 WHERE username = ")) {
|
console.log("Exercise 2.2 solved")
|
||||||
exerciseStore.solveExercise(2, 3)
|
}
|
||||||
} else if (this.searchTerm.includes("'); DELETE FROM Ratings WHERE rating = 5; --")) {
|
|
||||||
exerciseStore.solveExercise(2, 5)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await fetchBandsBySearchTerm(this.searchTerm)
|
// Exercise 2.3
|
||||||
.then(result => {
|
else if (this.searchTerm.includes("UPDATE")) {
|
||||||
this.bands = result.data
|
const accountStore = useAccountStore()
|
||||||
|
await accountStore.refreshAccount()
|
||||||
|
|
||||||
|
if (accountStore.userAccount.accountRole.privilegeAdminPanel == true) {
|
||||||
|
exerciseStore.solveExercise(2, 3)
|
||||||
|
console.log("Exercise 2.3 solved")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exercise 2.5
|
||||||
|
else if (this.searchTerm.includes("DELETE")) {
|
||||||
|
const bandStore = useBandStore()
|
||||||
|
await bandStore.getBand("muse")
|
||||||
|
|
||||||
|
if (bandStore.band.ratingValues.find(rating => rating.value == 5).count == 0) {
|
||||||
|
exerciseStore.solveExercise(2, 5)
|
||||||
|
console.log("Exercise 2.5 solved")
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch all locations by this.searchTerm
|
||||||
|
*/
|
||||||
await fetchLocationsBySearchTerm(this.searchTerm)
|
await fetchLocationsBySearchTerm(this.searchTerm)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
this.locations = result.data
|
this.locations = result.data
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch all concerts by this.searchTerm
|
||||||
|
*/
|
||||||
await fetchConcertsBySearchTerm(this.searchTerm)
|
await fetchConcertsBySearchTerm(this.searchTerm)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
this.concerts = result.data
|
this.concerts = result.data
|
||||||
|
|||||||
Reference in New Issue
Block a user