Skip to content

Commit

Permalink
Fixing issues with certs and https
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexGottschalkSE committed Oct 7, 2024
1 parent b2b27b1 commit b6f8a69
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
File renamed without changes.
29 changes: 13 additions & 16 deletions API/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ const express = require("express");
const bcrypt = require("bcrypt");
const helmet = require("helmet");
const cors = require("cors");
const payments = require("./routes/payments");
const payments = require("./routes/payments");
const app = express();

app.use(helmet());
app.use(cors());
app.use(helmet());
app.use(cors());
app.use(express.json());


let users = [];


app.post("/api/auth/register", async (req, res) => {
const { username, password } = req.body;


if (!username || !password) {
return res.status(400).json({ message: "Username and password are required" });
return res
.status(400)
.json({ message: "Username and password are required" });
}

const userExists = users.find((user) => user.username === username);
Expand All @@ -45,7 +44,9 @@ app.post("/api/auth/login", async (req, res) => {
const { username, password } = req.body;

if (!username || !password) {
return res.status(400).json({ message: "Username and password are required" });
return res
.status(400)
.json({ message: "Username and password are required" });
}

const user = users.find((user) => user.username === username);
Expand All @@ -66,7 +67,6 @@ app.post("/api/auth/login", async (req, res) => {
}
});


app.post("/api/payment", async (req, res) => {
const { amount, currency, provider, accountNumber, swiftCode } = req.body;

Expand All @@ -90,8 +90,7 @@ app.post("/api/payment", async (req, res) => {
.json({ message: "SWIFT code must be between 8 and 11 characters." });
}


const transactionId = `TXN${Date.now()}`;
const transactionId = `TXN${Date.now()}`;
const paymentData = {
amount,
currency,
Expand All @@ -101,7 +100,6 @@ app.post("/api/payment", async (req, res) => {
transactionId,
};


console.log("Payment processed:", paymentData);

res.status(201).json({
Expand All @@ -110,8 +108,8 @@ app.post("/api/payment", async (req, res) => {
});
});

const privateKey = fs.readFileSync("C:/Users/andre/source/repos/APDS7311POE/API/server.key", "utf8");
const certificate = fs.readFileSync("C:/Users/andre/source/repos/APDS7311POE/API/server.cert", "utf8");
const privateKey = fs.readFileSync("./server.key", "utf8");
const certificate = fs.readFileSync("./server.crt", "utf8");

const credentials = { key: privateKey, cert: certificate };

Expand All @@ -126,7 +124,6 @@ app.use((req, res, next) => {
res.redirect(`https://${req.headers.host}${req.url}`);
});

http.createServer(app).listen(80, () => {
http.createServer(app).listen(180, () => {
console.log("HTTP Server running on port 80, redirecting to HTTPS");

});
8 changes: 4 additions & 4 deletions Frontend/src/Login.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
import "./Login.css";
import { useNavigate } from "react-router-dom";
import "./Login.css";

function Login() {
const [message, setMessage] = useState("");
const navigate = useNavigate();
const navigate = useNavigate();

const handleLogin = async (e) => {
e.preventDefault();
Expand All @@ -29,7 +29,7 @@ function Login() {
const data = await response.json();
if (response.ok) {
setMessage("Login successful!");
navigate("/dashboard");
navigate("/dashboard");
} else {
setMessage(`Login failed: ${data.message}`);
}
Expand Down
6 changes: 3 additions & 3 deletions Frontend/src/Register.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from "react";
import ReCAPTCHA from "react-google-recaptcha";
import "./Register.css";
import "./Register.css";

function Register() {
const [captchaVerified, setCaptchaVerified] = useState(false);
Expand All @@ -25,7 +25,7 @@ function Register() {
};

try {
const response = await fetch("https://localhost:443/api/auth/register",{
const response = await fetch("https://localhost:443/api/auth/register", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -51,7 +51,7 @@ function Register() {
<input type="text" placeholder="Username" required />
<input type="password" placeholder="Password" required />
<ReCAPTCHA
sitekey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"
sitekey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"
onChange={handleCaptchaChange}
/>
<button type="submit">Register</button>
Expand Down

0 comments on commit b6f8a69

Please sign in to comment.