Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' of https://github.com/Thom2503/project-c
Browse files Browse the repository at this point in the history
  • Loading branch information
Thom2503 committed Jan 15, 2024
2 parents c5440a2 + 1a25727 commit 261283c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 23 deletions.
18 changes: 14 additions & 4 deletions Controller/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ public function index(): void {

public function update(): void {
$data = json_decode(file_get_contents("php://input"), true);
$this->eventsModel->updateEvent($data);
$success = $this->eventsModel->updateEvent($data);
header('Content-Type: application/json');
echo json_encode($this);
if ($success == true) {
echo json_encode(['success' => true]);
} else {
http_response_code(404);
echo json_encode(['success' => 'false']);
}
}

public function getConfirmedEvents(): void {
Expand All @@ -40,9 +45,14 @@ public function getConfirmedEvents(): void {

public function updateAccountEvents(): void {
$data = json_decode(file_get_contents("php://input"), true);
$this->eventsModel->updateAccountEvents($data);
$success = $this->eventsModel->updateAccountEvents($data);
header('Content-Type: application/json');
echo json_encode($this);
if ($success == true) {
echo json_encode(['success' => true]);
} else {
http_response_code(404);
echo json_encode(['success' => 'false']);
}
}

public function show(int $id): void {
Expand Down
8 changes: 4 additions & 4 deletions Model/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function unjoinEvent(int $accountid, int $eventid): int {
return $this->db->lastInsertId();
}

public function deleteEvent(int $id): void {
public function deleteEvent(int $id): bool {
// Delete from Events table
$queryEvents = "DELETE FROM `Events` WHERE `EventsID` = :id";
$stmtEvents = $this->db->prepare($queryEvents);
Expand All @@ -101,16 +101,16 @@ public function deleteEvent(int $id): void {
$queryAccountEvents = "DELETE FROM `AccountEvents` WHERE `event_id` = :id";
$stmtAccountEvents = $this->db->prepare($queryAccountEvents);
$stmtAccountEvents->bindParam(":id", $id, PDO::PARAM_INT);
$stmtAccountEvents->execute();
return $stmtAccountEvents->execute();
}

public function updateAccountEvents(array $data) {
public function updateAccountEvents(array $data): bool {
$query = "UPDATE `AccountEvents` SET `confirmed` = :confirmed WHERE `account_id` = :accountid AND `event_id` = :eventid";
$stmt = $this->db->prepare($query);
$stmt->bindParam(":confirmed", $data['confirmed']);
$stmt->bindParam(":accountid", $data['accountid']);
$stmt->bindParam(":eventid", $data['eventid']);
$stmt->execute();
return $stmt->execute();
}

public function updateEvent(array $data): bool {
Expand Down
12 changes: 6 additions & 6 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/src/components/2FA.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class TwoFactor extends Component {
}

setCookie("user", this.state.accountsid, 7);
setCookie("2FA", "true", 7);
setCookie("isadmin", Number.parseInt(this.state.accountdata.IsAdmin) === 1 ? "true" : "false", 7);
window.location.replace('agenda');
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Evenementen.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export class Evenementen extends Component {
const eventDateTime = dayjs(`${event.Date} ${event.startTime}`);
const currentDateTime = dayjs();
const totalRemainingHours = Math.floor(eventDateTime.diff(currentDateTime) / (60 * 60 * 1000));
if(totalRemainingHours <= parseInt(event.TentativeTime) && totalRemainingHours > 0) {
if(totalRemainingHours > parseInt(event.TentativeTime) && totalRemainingHours > 0) {
return true;
} else {
return false;
Expand Down
5 changes: 2 additions & 3 deletions client/src/components/EventModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,10 @@ export class EventModal extends Component {
}),
});
const data = await response.json();
window.location.replace("evenementen");
if (data.id > 0 || data.success === true) {

await sendMailNotification(1, `UPDATE: ${title}`, description);
await sendMailNotification(1, `UPDATE: ${title}`, description);
await addNotification(1, `UPDATE: ${title}`);
window.location.replace("evenementen");
} else {
// Handle form validation errors or other issues
console.log(data);
Expand Down
5 changes: 3 additions & 2 deletions client/src/components/FetchTentative.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import dayjs from 'dayjs';

import {faCheck} from "@fortawesome/free-solid-svg-icons";
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
import { toast } from 'react-toastify';

class FetchTentative extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -52,9 +53,9 @@ class FetchTentative extends React.Component {

if (!response.ok) {
throw new Error(`Failed to vote: ${response.status} ${response.statusText}`);
} else {
window.location.replace("evenementen");
}

const data = await response.json();
} catch (e) {
console.error('Error updating account events:', e);
}
Expand Down
10 changes: 7 additions & 3 deletions client/src/components/Login.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from 'react';
import { setCookie } from "../include/util_functions.js";
import { getCookie } from '../include/util_functions';
import {send2FAMail} from "../include/notification_functions";

export class Login extends Component {
Expand Down Expand Up @@ -35,12 +36,15 @@ export class Login extends Component {
});
if (response.ok) {
const data = await response.json();
if (data.verified === true)
if (data.verified === true && getCookie("2FA") !== "true")
{
await send2FAMail(data.AccountsID)
window.location.replace(`twofactor?id=${data.AccountsID}`);

} else {
} else if ((data.verified === true && getCookie("2FA") === "true")) {
setCookie("user", data.AccountsID, 7);
setCookie("isadmin", Number.parseInt(data.IsAdmin) === 1 ? "true" : "false", 7)
window.location.replace('agenda');
} else {
alert('Wachtwoord en email komen niet overeen.');
}
} else {
Expand Down

0 comments on commit 261283c

Please sign in to comment.