diff --git a/CTF/CTF-Frontend/src/app/Helper/ContestSetup.ts b/CTF/CTF-Frontend/src/app/Helper/ContestSetup.ts index f446337..64d0d16 100644 --- a/CTF/CTF-Frontend/src/app/Helper/ContestSetup.ts +++ b/CTF/CTF-Frontend/src/app/Helper/ContestSetup.ts @@ -183,7 +183,7 @@ export async function setNewFlag(flag: Flag, el: ElementRef, elements: any, ts: const email = getEmail(); const data = { FlagImage: flag.Image, email: email }; - const res = await fetch('api/setNewActiveFlag', { + const res = await fetch('api/flags/setNewActiveFlag', { method: 'POST', headers: { 'Content-Type' : 'application/json' @@ -279,14 +279,14 @@ async function checkSubmission(isPractice: boolean, el: ElementRef, socket: Sock } let res, result; if(!isPractice){ - res = await fetch('api/checkFlagSubmission', { + res = await fetch('api/submissions/checkFlagSubmission', { method: 'POST', headers: { 'Content-Type': 'application/json'}, body: JSON.stringify({ email, flagID, submittedFlag }) }); } else{ - res = await fetch('api/checkPracSubmission', { + res = await fetch('api/submissions/checkPracSubmission', { method: 'POST', headers: { 'Content-Type': 'application/json'}, body: JSON.stringify({ email, flagID, submittedFlag }) diff --git a/CTF/CTF-Frontend/src/app/add-contest/add-contest.component.ts b/CTF/CTF-Frontend/src/app/add-contest/add-contest.component.ts index cb1abeb..8e2359e 100644 --- a/CTF/CTF-Frontend/src/app/add-contest/add-contest.component.ts +++ b/CTF/CTF-Frontend/src/app/add-contest/add-contest.component.ts @@ -20,7 +20,7 @@ export class AddContestComponent { const isActive = 0; console.log("EMAIL IS:", this.getEmail()) const data = {Name: name, IsActive: isActive, email: this.getEmail(), Desc: desc}; - const res = await fetch('api/AddContest', { + const res = await fetch('api/contests/AddContest', { method: 'POST', headers: { 'Content-Type' : 'application/json' diff --git a/CTF/CTF-Frontend/src/app/add-flag/add-flag.component.html b/CTF/CTF-Frontend/src/app/add-flag/add-flag.component.html index 3663166..d0c49ad 100644 --- a/CTF/CTF-Frontend/src/app/add-flag/add-flag.component.html +++ b/CTF/CTF-Frontend/src/app/add-flag/add-flag.component.html @@ -50,8 +50,9 @@ - +

diff --git a/CTF/CTF-Frontend/src/app/add-flag/add-flag.component.ts b/CTF/CTF-Frontend/src/app/add-flag/add-flag.component.ts index 2a5f694..ae8497a 100644 --- a/CTF/CTF-Frontend/src/app/add-flag/add-flag.component.ts +++ b/CTF/CTF-Frontend/src/app/add-flag/add-flag.component.ts @@ -1,16 +1,26 @@ import { Component } from '@angular/core'; -import { gotoPage } from '../Helper/Helpers'; +import { gotoPage, getEmail } from '../Helper/Helpers'; import { Router } from '@angular/router'; +import { ModifyContestService } from '../modify-contest/modify-contest.service'; +import { Image } from '../models/image.model'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; + @Component({ selector: 'app-add-flag', - imports: [], + imports: [CommonModule, FormsModule], templateUrl: './add-flag.component.html', styleUrl: './add-flag.component.css' }) export class AddFlagComponent { - constructor(private router: Router){} + allImages: Image[] = []; + selectedImage: string = "Select an Image"; + constructor(private router: Router, private modifyContestService: ModifyContestService){} + ngOnInit(): void { + this.getImages(); + } // add a flag to a contest async AddFlag(){ // get contestId from URL @@ -38,7 +48,7 @@ export class AddFlagComponent { // add the flag const data = {name: flagName.value, desc: description.value, contest: contestId, image: image.value, path: path.value, hint1: Hint1.value || '', hint2: Hint2.value || '', hint3: Hint3.value || ''}; try{ - const response = await fetch('api/AddFlag', { + const response = await fetch('api/flags/AddFlag', { method: 'POST', headers: {'Content-Type': 'application/json',}, body: JSON.stringify(data) @@ -58,7 +68,21 @@ export class AddFlagComponent { } } + async getImages(): Promise{ + const email = this.getEmail(); + try{ + const imageData = await this.modifyContestService.getImages(email); + this.allImages = imageData || []; + }catch(error){ + console.error('Error loading images'); + } + } + navtoPageCI(){ gotoPage(this.router, '/create-image'); } + + getEmail(): string{ + return getEmail(); + } } diff --git a/CTF/CTF-Frontend/src/app/add-student/add-student.component.ts b/CTF/CTF-Frontend/src/app/add-student/add-student.component.ts index f91f3a2..9d7fd3c 100644 --- a/CTF/CTF-Frontend/src/app/add-student/add-student.component.ts +++ b/CTF/CTF-Frontend/src/app/add-student/add-student.component.ts @@ -36,7 +36,7 @@ export class AddStudentComponent { if (this.password == this.confirmPassword) { // passwords match const data = {name: this.Uname, email: this.email, Aemail: Aemail, password: this.password}; - const res = await fetch('api/AddStudent', { + const res = await fetch('api/users/AddStudent', { method: 'POST', headers: { 'Content-Type' : 'application/json' diff --git a/CTF/CTF-Frontend/src/app/admin-profile/admin-profile.component.ts b/CTF/CTF-Frontend/src/app/admin-profile/admin-profile.component.ts index 40be52c..9414d61 100644 --- a/CTF/CTF-Frontend/src/app/admin-profile/admin-profile.component.ts +++ b/CTF/CTF-Frontend/src/app/admin-profile/admin-profile.component.ts @@ -33,7 +33,6 @@ export class AdminProfileComponent implements OnInit{ this.populateTable(); } - async populateTable(){ try{ const email = this.getEmail(); @@ -54,6 +53,8 @@ export class AdminProfileComponent implements OnInit{ const result = await this.adminProfileService.getContestFlagsSubs(email, this.selectedContest); this.flags = result.flags; this.subs = result.subs; + console.log("flags", this.flags); + console.log("Subs", this.subs); }catch(error){ console.error('Failed to populate flag table'); } diff --git a/CTF/CTF-Frontend/src/app/create-image/create-image.component.ts b/CTF/CTF-Frontend/src/app/create-image/create-image.component.ts index 647ec58..09b0094 100644 --- a/CTF/CTF-Frontend/src/app/create-image/create-image.component.ts +++ b/CTF/CTF-Frontend/src/app/create-image/create-image.component.ts @@ -281,7 +281,7 @@ export class CreateImageComponent { formdata.append('data', JSON.stringify(data)); // send the post request - const res = await fetch('api/AddImage', { + const res = await fetch('api/images/AddImage', { method: 'POST', body: formdata }); diff --git a/CTF/CTF-Frontend/src/app/edit-student/edit-student.component.ts b/CTF/CTF-Frontend/src/app/edit-student/edit-student.component.ts index 58de85d..ea9ef41 100644 --- a/CTF/CTF-Frontend/src/app/edit-student/edit-student.component.ts +++ b/CTF/CTF-Frontend/src/app/edit-student/edit-student.component.ts @@ -25,7 +25,7 @@ export class EditStudentComponent { if (ps1 == ps2) { // if both passwords are equal, continue const data = { email: this.emailinput, password: ps1}; - const res = await fetch('api/UpdateStudent', { + const res = await fetch('api/users/UpdateStudent', { method: "POST", headers: { 'Content-Type' : 'application/json' diff --git a/CTF/CTF-Frontend/src/app/modify-contest/modify-contest.component.ts b/CTF/CTF-Frontend/src/app/modify-contest/modify-contest.component.ts index b5755cb..006dba1 100644 --- a/CTF/CTF-Frontend/src/app/modify-contest/modify-contest.component.ts +++ b/CTF/CTF-Frontend/src/app/modify-contest/modify-contest.component.ts @@ -104,9 +104,13 @@ handlePopupMessage(event: MessageEvent): void { if (this.selectedContestId !== null) { try { const email = this.getEmail(); - await this.modifyContestService.setContestActive(this.selectedContestId, email); - this.loadContests(); - console.log('Contest set as active'); + const actOrDeact = await this.modifyContestService.setContestActive(this.selectedContestId, email); + if(actOrDeact === 1){ + this.loadContests(); + console.log('Contest set as active'); + } + else if(actOrDeact === 0) + this.activeContest = null; } catch (error) { console.error('Error activating contest:', error); } diff --git a/CTF/CTF-Frontend/src/app/modify-contest/modify-contest.service.ts b/CTF/CTF-Frontend/src/app/modify-contest/modify-contest.service.ts index f8c955b..8682a9b 100644 --- a/CTF/CTF-Frontend/src/app/modify-contest/modify-contest.service.ts +++ b/CTF/CTF-Frontend/src/app/modify-contest/modify-contest.service.ts @@ -9,7 +9,7 @@ export class ModifyContestService { async getImages(email: string): Promise { try { - const response = await fetch('api/getImages', { + const response = await fetch('api/images/getImages', { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -71,7 +71,7 @@ export class ModifyContestService { async addContest(data: any): Promise { try { - const response = await fetch('api/AddContest', { + const response = await fetch('api/constests/AddContest', { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -93,7 +93,7 @@ export class ModifyContestService { // Send a POST request to delete the contest by its name let data = {contest: contestId}; await this.deleteFlagsFromContest(contestId); - let res = await fetch('api/DeleteContest', { + let res = await fetch('api/contests/DeleteContest', { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -111,7 +111,7 @@ export class ModifyContestService { async deleteFlagsFromContest(contestId: number): Promise { try { - const response = await fetch('api/DeleteFlagsFromContest', { + const response = await fetch('api/flags/DeleteFlagsFromContest', { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -131,7 +131,7 @@ export class ModifyContestService { async AddFlag(data: any): Promise { try { - const response = await fetch('api/AddFlag', { + const response = await fetch('api/flags/AddFlag', { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -151,7 +151,7 @@ export class ModifyContestService { async DeleteFlag(flagId: number): Promise { let data = { flag: flagId }; - let res = await fetch('api/DeleteFlag', { + let res = await fetch('api/flags/DeleteFlag', { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -164,7 +164,7 @@ export class ModifyContestService { const image = flagImage; // set up the container for the image const data = { FlagImage: image, email: Email }; - const res = await fetch('/api/setNewActiveFlag', { + const res = await fetch('/api/flags/setNewActiveFlag', { method: 'POST', headers: { 'Content-Type' : 'application/json' @@ -174,28 +174,50 @@ export class ModifyContestService { } async setContestActive(contestId: number, email: string): Promise { - try { - const response = await fetch('api/setContestActive', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ contest: contestId, email }) - }); - - if (!response.ok) { - throw new Error('Failed to set contest active'); - } - return await response.json(); - } catch (error) { - console.error('Error setting contest active:', error); + const oldcontestID = await this.getActiveContest(email); + if(oldcontestID !== 0 && oldcontestID === contestId){ + try{ + const response = await fetch('api/contests/EndContest', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({contest: oldcontestID, email}) + }); + if(!response.ok) + throw new Error('Failed to end contest'); + await response.json(); + return 0; + }catch(error){ + console.error('Error ending contest'); throw error; } + } + else{ + try { + const response = await fetch('api/contests/setContestActive', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ contest: contestId, email }) + }); + + if (!response.ok) { + throw new Error('Failed to set contest active'); + } + await response.json(); + return 1; + } catch (error) { + console.error('Error setting contest active:', error); + throw error; + } + } } async deleteImage(imageName: string): Promise { try { - const response = await fetch('api/DeleteImageReplaceFlags', { + const response = await fetch('api/images/DeleteImageReplaceFlags', { method: 'POST', headers: { 'Content-Type': 'application/json' diff --git a/CTF/CTF-Frontend/src/app/unauthorized/unauthorized.component.html b/CTF/CTF-Frontend/src/app/unauthorized/unauthorized.component.html index 81bbd6e..74dd97f 100644 --- a/CTF/CTF-Frontend/src/app/unauthorized/unauthorized.component.html +++ b/CTF/CTF-Frontend/src/app/unauthorized/unauthorized.component.html @@ -1,3 +1 @@ -

Thought you could pull a fast one eh?

-

I dont think so

-

👎

\ No newline at end of file +

You do not have permission to access this page.

\ No newline at end of file