refactoring

main
jolatime 5 months ago
parent 8630b06376
commit afb1fb6c6f

@ -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 })

@ -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'

@ -50,8 +50,9 @@
<!-- image of the flag to create container -->
<label> Image: </label>
<select id="Images">
<select id="Images" [(ngModel)]="selectedImage">
<option> ubuntu </option>
<option *ngFor="let image of allImages" [value] ="image.Name">{{image.Name}}</option>
</select>
<br><br>

@ -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<void>{
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();
}
}

@ -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'

@ -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');
}

@ -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
});

@ -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'

@ -104,9 +104,13 @@ handlePopupMessage(event: MessageEvent): void {
if (this.selectedContestId !== null) {
try {
const email = this.getEmail();
await this.modifyContestService.setContestActive(this.selectedContestId, email);
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);
}

@ -9,7 +9,7 @@ export class ModifyContestService {
async getImages(email: string): Promise<any> {
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<any> {
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<any> {
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<any> {
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<any> {
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,8 +174,28 @@ export class ModifyContestService {
}
async setContestActive(contestId: number, email: string): Promise<any> {
const oldcontestID = await this.getActiveContest(email);
if(oldcontestID !== 0 && oldcontestID === contestId){
try{
const response = await fetch('api/setContestActive', {
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'
@ -186,16 +206,18 @@ export class ModifyContestService {
if (!response.ok) {
throw new Error('Failed to set contest active');
}
return await response.json();
await response.json();
return 1;
} catch (error) {
console.error('Error setting contest active:', error);
throw error;
}
}
}
async deleteImage(imageName: string): Promise<any> {
try {
const response = await fetch('api/DeleteImageReplaceFlags', {
const response = await fetch('api/images/DeleteImageReplaceFlags', {
method: 'POST',
headers: {
'Content-Type': 'application/json'

@ -1,3 +1 @@
<h1>Thought you could pull a fast one eh?</h1>
<p>I dont think so</p>
<h2>👎</h2>
<h1>You do not have permission to access this page.</h1>
Loading…
Cancel
Save