From d51fa2f2d1e52db32b52e10a4e0e9cc11eda6310 Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Sun, 10 Nov 2024 00:09:31 -0500 Subject: [PATCH 01/63] https changes --- server.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index ebbede3..4b6f67a 100644 --- a/server.js +++ b/server.js @@ -4,10 +4,13 @@ const cors = require('cors'); const crypto = require('crypto'); // Import the crypto module const { client, connectDB } = require('./db/connection'); // Import the client and connectDB +const https = require('https'); // Import https module +const fs = require('fs'); // Import fs module for reading certificate files + const app = express(); // List of allowed origins -const allowedOrigins = ['http://localhost:3000', 'http://10.11.29.103:3000', 'http://facelect.capping.ecrl.marist.edu:3000']; +const allowedOrigins = ['http://localhost:3000', 'http://10.11.29.103:3000', 'http://facelect.capping.ecrl.marist.edu:3000','http://localhost:443', 'http://10.11.29.103:443', 'http://facelect.capping.ecrl.marist.edu:443']; // Configure CORS to allow requests from your React app app.use(cors({ @@ -83,7 +86,18 @@ app.get('/faculty', async (req, res) => { } }); -// Start server -app.listen(3001, () => { - console.log('Server is running on port 3001'); +// HTTPS configuration +const httpsOptions = { + key: fs.readFileSync('backend/sp-key.pem'), + cert: fs.readFileSync('backend/sp-cert.pem') +}; + +// Start HTTPS server on port 443 +https.createServer(httpsOptions, app).listen(443, () => { + console.log('HTTPS server is running on port 443'); }); + +// Start HTTP server on port 3001 +app.listen(3001, () => { + console.log('HTTP server is running on port 3001'); +}); \ No newline at end of file From b64d57984d912461c4859d098ac53d3075ba7d02 Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Mon, 11 Nov 2024 13:43:13 -0500 Subject: [PATCH 02/63] please work https --- server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.js b/server.js index 4b6f67a..ec0c45a 100644 --- a/server.js +++ b/server.js @@ -10,7 +10,7 @@ const fs = require('fs'); // Import fs module for reading certificate file const app = express(); // List of allowed origins -const allowedOrigins = ['http://localhost:3000', 'http://10.11.29.103:3000', 'http://facelect.capping.ecrl.marist.edu:3000','http://localhost:443', 'http://10.11.29.103:443', 'http://facelect.capping.ecrl.marist.edu:443']; +const allowedOrigins = ['http://localhost:3000', 'http://10.11.29.103:3000', 'http://facelect.capping.ecrl.marist.edu:3000','https://localhost:443','https://10.11.29.103:443', 'https://facelect.capping.ecrl.marist.edu:443']; // Configure CORS to allow requests from your React app app.use(cors({ From fb0b1d188243772ccbfade95c0ac4b8a4bd62017 Mon Sep 17 00:00:00 2001 From: Kai Date: Mon, 11 Nov 2024 13:59:37 -0500 Subject: [PATCH 03/63] ssl changes, secret, session and morgan --- server-ssl.js | 158 +++++++++++++++++++++++++++++++------------------- 1 file changed, 98 insertions(+), 60 deletions(-) diff --git a/server-ssl.js b/server-ssl.js index 68e42b3..998d4ab 100644 --- a/server-ssl.js +++ b/server-ssl.js @@ -7,108 +7,146 @@ const https = require('https'); const fs = require('fs'); const passport = require('passport'); const SamlStrategy = require('passport-saml').Strategy; +const session = require('express-session'); // Import express-session +const morgan = require('morgan'); // Import morgan for logging const app = express(); // List of allowed origins -const allowedOrigins = ['http://localhost:3000', 'http://10.11.29.103:3000', 'http://facelect.capping.ecrl.marist.edu:3000']; +const allowedOrigins = [ + 'http://localhost:3000', + 'http://10.11.29.103:3000', + 'http://facelect.capping.ecrl.marist.edu:3000', +]; // Configure CORS to allow requests from your React app -app.use(cors({ +app.use( + cors({ origin: function (origin, callback) { - // Allow requests with no origin (like mobile apps or curl requests) - if (!origin) return callback(null, true); - if (allowedOrigins.indexOf(origin) === -1) { - const msg = 'The CORS policy for this site does not allow access from the specified Origin.'; - return callback(new Error(msg), false); - } - return callback(null, true); - } -})); + // Allow requests with no origin (like mobile apps or curl requests) + if (!origin) return callback(null, true); + if (allowedOrigins.indexOf(origin) === -1) { + const msg = + 'The CORS policy for this site does not allow access from the specified Origin.'; + return callback(new Error(msg), false); + } + return callback(null, true); + }, + }) +); app.use(express.json()); // Parse incoming JSON data +app.use(morgan('dev')); // Log requests for debugging + +// Configure express-session middleware +app.use( + session({ + secret: 'c2d6e1f1b4a6e0f3c5d8e7f1a2b3c4d5e6f7081920a1b2c3d4e5f6a7b8c9d0e1', + resave: false, + saveUninitialized: true, + cookie: { secure: true }, // Set secure to true since we're using HTTPS + }) +); + +// Initialize Passport.js +app.use(passport.initialize()); +app.use(passport.session()); // Connect to the PostgreSQL database connectDB(); // Function to hash passwords using SHA-256 const hashPassword = (password) => { - return crypto.createHash('sha256').update(password).digest('hex'); + return crypto.createHash('sha256').update(password).digest('hex'); }; // Passport SAML strategy configuration -passport.use(new SamlStrategy({ - path: '/login/callback', - entryPoint: 'https://auth.it.marist.edu/idp/profile/SAML2/Redirect/SSO', - issuer: 'Marist-SSO', - cert: fs.readFileSync('/var/www/html/backend/sp-cert.pem', 'utf-8'), - privateCert: fs.readFileSync('/var/www/html/backend/sp-cert.pem', 'utf-8'), - identifierFormat: null, - decryptionPvk: fs.readFileSync('/var/www/html/backend/sp-cert.pem', 'utf-8'), - validateInResponseTo: false, - disableRequestedAuthnContext: true -}, (profile, done) => { - return done(null, profile); -})); +passport.use( + new SamlStrategy( + { + path: '/login/callback', + entryPoint: 'https://auth.it.marist.edu/idp/profile/SAML2/Redirect/SSO', + issuer: 'Marist-SSO', + cert: fs.readFileSync('/var/www/html/backend/sp-cert.pem', 'utf-8'), + privateCert: fs.readFileSync('/var/www/html/backend/sp-key.pem', 'utf-8'), // Use the private key for privateCert + identifierFormat: null, + decryptionPvk: fs.readFileSync('/var/www/html/backend/sp-key.pem', 'utf-8'), // Use the private key for decryptionPvk + validateInResponseTo: false, + disableRequestedAuthnContext: true, + }, + (profile, done) => { + return done(null, profile); + } + ) +); passport.serializeUser((user, done) => { - done(null, user); + done(null, user); }); passport.deserializeUser((user, done) => { - done(null, user); + done(null, user); }); -app.use(passport.initialize()); -app.use(passport.session()); - // Route to handle admin login app.post('/admin-login', async (req, res) => { - const { username, password } = req.body; // Capture username and password from request + const { username, password } = req.body; // Capture username and password from request - try { - // Query the Admins table to find the admin by username (Uname) - const adminResult = await client.query('SELECT * FROM Admins WHERE Uname = $1', [username]); + try { + // Query the Admins table to find the admin by username (Uname) + const adminResult = await client.query( + 'SELECT * FROM Admins WHERE Uname = $1', + [username] + ); - if (adminResult.rows.length === 0) { - return res.status(400).json({ message: 'Invalid username or password' }); - } - - const admin = adminResult.rows[0]; + if (adminResult.rows.length === 0) { + return res.status(400).json({ message: 'Invalid username or password' }); + } - // Hash the provided password and compare with the stored hash - const hashedInputPassword = hashPassword(password); // Hash the input password - if (hashedInputPassword !== admin.thepassword) { // Use correct case for ThePassword - return res.status(400).json({ message: 'Invalid username or password' }); - } + const admin = adminResult.rows[0]; - res.status(200).json({ message: 'Login successful' }); - } catch (error) { - res.status(500).json({ message: 'Internal server error' }); + // Hash the provided password and compare with the stored hash + const hashedInputPassword = hashPassword(password); // Hash the input password + if (hashedInputPassword !== admin.thepassword) { + // Use correct case for thepassword + return res.status(400).json({ message: 'Invalid username or password' }); } + + res.status(200).json({ message: 'Login successful' }); + } catch (error) { + console.error(error); // Log the error for debugging + res.status(500).json({ message: 'Internal server error' }); + } }); // SSO login route -app.get('/login', passport.authenticate('saml', { +app.get( + '/login', + passport.authenticate('saml', { successRedirect: '/', - failureRedirect: '/login' -})); + failureRedirect: '/login', + }) +); // SSO callback route -app.post('/login/callback', passport.authenticate('saml', { +app.post( + '/login/callback', + passport.authenticate('saml', { failureRedirect: '/login', - failureFlash: true -}), (req, res) => { + failureFlash: true, + }), + (req, res) => { res.redirect('/'); -}); + } +); // Read SSL certificate and key const options = { - key: fs.readFileSync('/var/www/html/backend/sp-key.pem'), - cert: fs.readFileSync('/var/www/html/backend/sp-cert.pem') + key: fs.readFileSync('/var/www/html/backend/sp-key.pem'), + cert: fs.readFileSync('/var/www/html/backend/sp-cert.pem'), }; -// Create HTTPS server -https.createServer(options, app).listen(443, () => { - console.log('HTTPS Server running on port 443'); -}); \ No newline at end of file +// Create HTTPS server on a non-privileged port (e.g., 8443) +https.createServer(options, app).listen(8443, () => { + console.log('HTTPS Server running on port 8443'); +}); From d48ba92de7b90edfd6d920ca74f2067e13575fe1 Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Mon, 11 Nov 2024 14:04:55 -0500 Subject: [PATCH 04/63] changed https port --- server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index ec0c45a..7d17b8c 100644 --- a/server.js +++ b/server.js @@ -92,8 +92,8 @@ const httpsOptions = { cert: fs.readFileSync('backend/sp-cert.pem') }; -// Start HTTPS server on port 443 -https.createServer(httpsOptions, app).listen(443, () => { +// Start HTTPS server on port 8443 +https.createServer(httpsOptions, app).listen(8443, () => { console.log('HTTPS server is running on port 443'); }); From ad668a945c0f61cadc3d3dbab19177544ebe66ee Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Mon, 11 Nov 2024 14:05:39 -0500 Subject: [PATCH 05/63] changed port again --- server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.js b/server.js index 7d17b8c..8b03928 100644 --- a/server.js +++ b/server.js @@ -10,7 +10,7 @@ const fs = require('fs'); // Import fs module for reading certificate file const app = express(); // List of allowed origins -const allowedOrigins = ['http://localhost:3000', 'http://10.11.29.103:3000', 'http://facelect.capping.ecrl.marist.edu:3000','https://localhost:443','https://10.11.29.103:443', 'https://facelect.capping.ecrl.marist.edu:443']; +const allowedOrigins = ['http://localhost:3000', 'http://10.11.29.103:3000', 'http://facelect.capping.ecrl.marist.edu:3000','https://localhost:8443','https://10.11.29.103:8443', 'https://facelect.capping.ecrl.marist.edu:8443']; // Configure CORS to allow requests from your React app app.use(cors({ From 30c1258910d72967e50ec0f250ee539720b1ce58 Mon Sep 17 00:00:00 2001 From: Kai Date: Mon, 11 Nov 2024 14:11:43 -0500 Subject: [PATCH 06/63] adding libraries --- package-lock.json | 427 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 4 + 2 files changed, 431 insertions(+) diff --git a/package-lock.json b/package-lock.json index f73facc..07a3acb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,10 @@ "cors": "^2.8.5", "crypto": "^1.0.1", "dotenv": "^16.4.5", + "express-session": "^1.18.1", + "morgan": "^1.10.0", + "passport": "^0.7.0", + "passport-saml": "^3.2.4", "pg": "^8.13.0", "react": "^18.3.1", "react-dom": "^18.3.1", @@ -4784,6 +4788,15 @@ "@xtuc/long": "4.2.2" } }, + "node_modules/@xmldom/xmldom": { + "version": "0.7.13", + "resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.7.13.tgz", + "integrity": "sha512-lm2GW5PkosIzccsaZIz7tp8cPADSIlIHWDFTR1N0SzfinhhYgeIQjFMz4rYzanCScr3DqQLeomUDArp6MWKm+g==", + "deprecated": "this version is no longer supported, please update to at least 0.8.*", + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/@xtuc/ieee754": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz", @@ -5640,6 +5653,22 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, + "node_modules/basic-auth": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", + "integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==", + "dependencies": { + "safe-buffer": "5.1.2" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/basic-auth/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, "node_modules/batch": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz", @@ -8377,6 +8406,50 @@ "node": ">= 0.10.0" } }, + "node_modules/express-session": { + "version": "1.18.1", + "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.18.1.tgz", + "integrity": "sha512-a5mtTqEaZvBCL9A9aqkrtfz+3SMDhOVUnjafjo+s7A9Txkq+SVX2DLvSp1Zrv4uCXa3lMSK3viWnh9Gg07PBUA==", + "dependencies": { + "cookie": "0.7.2", + "cookie-signature": "1.0.7", + "debug": "2.6.9", + "depd": "~2.0.0", + "on-headers": "~1.0.2", + "parseurl": "~1.3.3", + "safe-buffer": "5.2.1", + "uid-safe": "~2.1.5" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/express-session/node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express-session/node_modules/cookie-signature": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz", + "integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==" + }, + "node_modules/express-session/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/express-session/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, "node_modules/express/node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -12816,6 +12889,45 @@ "mkdirp": "bin/cmd.js" } }, + "node_modules/morgan": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz", + "integrity": "sha512-AbegBVI4sh6El+1gNwvD5YIck7nSA36weD7xvIxG4in80j/UoK8AEGaWnnz8v1GxonMCltmlNs5ZKbGvl9b1XQ==", + "dependencies": { + "basic-auth": "~2.0.1", + "debug": "2.6.9", + "depd": "~2.0.0", + "on-finished": "~2.3.0", + "on-headers": "~1.0.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/morgan/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/morgan/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, + "node_modules/morgan/node_modules/on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -13297,6 +13409,49 @@ "tslib": "^2.0.3" } }, + "node_modules/passport": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/passport/-/passport-0.7.0.tgz", + "integrity": "sha512-cPLl+qZpSc+ireUvt+IzqbED1cHHkDoVYMo30jbJIdOOjQ1MQYZBPiNvmi8UM6lJuOpTPXJGZQk0DtC4y61MYQ==", + "dependencies": { + "passport-strategy": "1.x.x", + "pause": "0.0.1", + "utils-merge": "^1.0.1" + }, + "engines": { + "node": ">= 0.4.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/jaredhanson" + } + }, + "node_modules/passport-saml": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/passport-saml/-/passport-saml-3.2.4.tgz", + "integrity": "sha512-JSgkFXeaexLNQh1RrOvJAgjLnZzH/S3HbX/mWAk+i7aulnjqUe7WKnPl1NPnJWqP7Dqsv0I2Xm6KIFHkftk0HA==", + "deprecated": "For versions >= 4, please use scopped package @node-saml/passport-saml", + "dependencies": { + "@xmldom/xmldom": "^0.7.6", + "debug": "^4.3.2", + "passport-strategy": "^1.0.0", + "xml-crypto": "^2.1.3", + "xml-encryption": "^2.0.0", + "xml2js": "^0.4.23", + "xmlbuilder": "^15.1.1" + }, + "engines": { + "node": ">= 12" + } + }, + "node_modules/passport-strategy": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz", + "integrity": "sha512-CB97UUvDKJde2V0KDWWB3lyf6PC3FaZP7YxZ2G8OAtn9p4HI9j9JLP9qjOGZFvyl8uwNT8qM+hGnz/n16NI7oA==", + "engines": { + "node": ">= 0.4.0" + } + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -13359,6 +13514,11 @@ "node": ">=8" } }, + "node_modules/pause": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz", + "integrity": "sha512-KG8UEiEVkR3wGEb4m5yZkVCzigAD+cVEJck2CzYZO37ZGJfctvVptVO192MwrtPhzONn6go8ylnOdMhKqi4nfg==" + }, "node_modules/performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", @@ -14982,6 +15142,14 @@ "performance-now": "^2.1.0" } }, + "node_modules/random-bytes": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz", + "integrity": "sha512-iv7LhNVO047HzYR3InF6pUcUsPQiHTM1Qal51DcGSuZFBil1aBBWG5eHPNek7bvILMaYJ/8RU1e8w1AMdHmLQQ==", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -17507,6 +17675,17 @@ "node": ">=4.2.0" } }, + "node_modules/uid-safe": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz", + "integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==", + "dependencies": { + "random-bytes": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -18599,16 +18778,77 @@ } } }, + "node_modules/xml-crypto": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/xml-crypto/-/xml-crypto-2.1.5.tgz", + "integrity": "sha512-xOSJmGFm+BTXmaPYk8pPV3duKo6hJuZ5niN4uMzoNcTlwYs0jAu/N3qY+ud9MhE4N7eMRuC1ayC7Yhmb7MmAWg==", + "dependencies": { + "@xmldom/xmldom": "^0.7.9", + "xpath": "0.0.32" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/xml-encryption": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/xml-encryption/-/xml-encryption-2.0.0.tgz", + "integrity": "sha512-4Av83DdvAgUQQMfi/w8G01aJshbEZP9ewjmZMpS9t3H+OCZBDvyK4GJPnHGfWiXlArnPbYvR58JB9qF2x9Ds+Q==", + "dependencies": { + "@xmldom/xmldom": "^0.7.0", + "escape-html": "^1.0.3", + "xpath": "0.0.32" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/xml-name-validator": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz", "integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==" }, + "node_modules/xml2js": { + "version": "0.4.23", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", + "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==", + "dependencies": { + "sax": ">=0.6.0", + "xmlbuilder": "~11.0.0" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/xml2js/node_modules/xmlbuilder": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", + "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==", + "engines": { + "node": ">=4.0" + } + }, + "node_modules/xmlbuilder": { + "version": "15.1.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-15.1.1.tgz", + "integrity": "sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg==", + "engines": { + "node": ">=8.0" + } + }, "node_modules/xmlchars": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==" }, + "node_modules/xpath": { + "version": "0.0.32", + "resolved": "https://registry.npmjs.org/xpath/-/xpath-0.0.32.tgz", + "integrity": "sha512-rxMJhSIoiO8vXcWvSifKqhvV96GjiD5wYb8/QHdoRyQvraTpp4IEv944nhGausZZ3u7dhQXteZuZbaqfpB7uYw==", + "engines": { + "node": ">=0.6.0" + } + }, "node_modules/xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", @@ -21984,6 +22224,11 @@ "@xtuc/long": "4.2.2" } }, + "@xmldom/xmldom": { + "version": "0.7.13", + "resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.7.13.tgz", + "integrity": "sha512-lm2GW5PkosIzccsaZIz7tp8cPADSIlIHWDFTR1N0SzfinhhYgeIQjFMz4rYzanCScr3DqQLeomUDArp6MWKm+g==" + }, "@xtuc/ieee754": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz", @@ -22601,6 +22846,21 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, + "basic-auth": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", + "integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==", + "requires": { + "safe-buffer": "5.1.2" + }, + "dependencies": { + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + } + } + }, "batch": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz", @@ -24569,6 +24829,46 @@ } } }, + "express-session": { + "version": "1.18.1", + "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.18.1.tgz", + "integrity": "sha512-a5mtTqEaZvBCL9A9aqkrtfz+3SMDhOVUnjafjo+s7A9Txkq+SVX2DLvSp1Zrv4uCXa3lMSK3viWnh9Gg07PBUA==", + "requires": { + "cookie": "0.7.2", + "cookie-signature": "1.0.7", + "debug": "2.6.9", + "depd": "~2.0.0", + "on-headers": "~1.0.2", + "parseurl": "~1.3.3", + "safe-buffer": "5.2.1", + "uid-safe": "~2.1.5" + }, + "dependencies": { + "cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==" + }, + "cookie-signature": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz", + "integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==" + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + } + } + }, "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -27728,6 +28028,41 @@ "minimist": "^1.2.6" } }, + "morgan": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz", + "integrity": "sha512-AbegBVI4sh6El+1gNwvD5YIck7nSA36weD7xvIxG4in80j/UoK8AEGaWnnz8v1GxonMCltmlNs5ZKbGvl9b1XQ==", + "requires": { + "basic-auth": "~2.0.1", + "debug": "2.6.9", + "depd": "~2.0.0", + "on-finished": "~2.3.0", + "on-headers": "~1.0.2" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, + "on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==", + "requires": { + "ee-first": "1.1.1" + } + } + } + }, "ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -28071,6 +28406,35 @@ "tslib": "^2.0.3" } }, + "passport": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/passport/-/passport-0.7.0.tgz", + "integrity": "sha512-cPLl+qZpSc+ireUvt+IzqbED1cHHkDoVYMo30jbJIdOOjQ1MQYZBPiNvmi8UM6lJuOpTPXJGZQk0DtC4y61MYQ==", + "requires": { + "passport-strategy": "1.x.x", + "pause": "0.0.1", + "utils-merge": "^1.0.1" + } + }, + "passport-saml": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/passport-saml/-/passport-saml-3.2.4.tgz", + "integrity": "sha512-JSgkFXeaexLNQh1RrOvJAgjLnZzH/S3HbX/mWAk+i7aulnjqUe7WKnPl1NPnJWqP7Dqsv0I2Xm6KIFHkftk0HA==", + "requires": { + "@xmldom/xmldom": "^0.7.6", + "debug": "^4.3.2", + "passport-strategy": "^1.0.0", + "xml-crypto": "^2.1.3", + "xml-encryption": "^2.0.0", + "xml2js": "^0.4.23", + "xmlbuilder": "^15.1.1" + } + }, + "passport-strategy": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz", + "integrity": "sha512-CB97UUvDKJde2V0KDWWB3lyf6PC3FaZP7YxZ2G8OAtn9p4HI9j9JLP9qjOGZFvyl8uwNT8qM+hGnz/n16NI7oA==" + }, "path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -28117,6 +28481,11 @@ "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==" }, + "pause": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz", + "integrity": "sha512-KG8UEiEVkR3wGEb4m5yZkVCzigAD+cVEJck2CzYZO37ZGJfctvVptVO192MwrtPhzONn6go8ylnOdMhKqi4nfg==" + }, "performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", @@ -29076,6 +29445,11 @@ "performance-now": "^2.1.0" } }, + "random-bytes": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz", + "integrity": "sha512-iv7LhNVO047HzYR3InF6pUcUsPQiHTM1Qal51DcGSuZFBil1aBBWG5eHPNek7bvILMaYJ/8RU1e8w1AMdHmLQQ==" + }, "randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -30929,6 +31303,14 @@ "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==" }, + "uid-safe": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz", + "integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==", + "requires": { + "random-bytes": "~1.0.0" + } + }, "unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -31754,16 +32136,61 @@ "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==", "requires": {} }, + "xml-crypto": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/xml-crypto/-/xml-crypto-2.1.5.tgz", + "integrity": "sha512-xOSJmGFm+BTXmaPYk8pPV3duKo6hJuZ5niN4uMzoNcTlwYs0jAu/N3qY+ud9MhE4N7eMRuC1ayC7Yhmb7MmAWg==", + "requires": { + "@xmldom/xmldom": "^0.7.9", + "xpath": "0.0.32" + } + }, + "xml-encryption": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/xml-encryption/-/xml-encryption-2.0.0.tgz", + "integrity": "sha512-4Av83DdvAgUQQMfi/w8G01aJshbEZP9ewjmZMpS9t3H+OCZBDvyK4GJPnHGfWiXlArnPbYvR58JB9qF2x9Ds+Q==", + "requires": { + "@xmldom/xmldom": "^0.7.0", + "escape-html": "^1.0.3", + "xpath": "0.0.32" + } + }, "xml-name-validator": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz", "integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==" }, + "xml2js": { + "version": "0.4.23", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", + "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==", + "requires": { + "sax": ">=0.6.0", + "xmlbuilder": "~11.0.0" + }, + "dependencies": { + "xmlbuilder": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", + "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==" + } + } + }, + "xmlbuilder": { + "version": "15.1.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-15.1.1.tgz", + "integrity": "sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg==" + }, "xmlchars": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==" }, + "xpath": { + "version": "0.0.32", + "resolved": "https://registry.npmjs.org/xpath/-/xpath-0.0.32.tgz", + "integrity": "sha512-rxMJhSIoiO8vXcWvSifKqhvV96GjiD5wYb8/QHdoRyQvraTpp4IEv944nhGausZZ3u7dhQXteZuZbaqfpB7uYw==" + }, "xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", diff --git a/package.json b/package.json index a23856b..e4627ca 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,10 @@ "cors": "^2.8.5", "crypto": "^1.0.1", "dotenv": "^16.4.5", + "express-session": "^1.18.1", + "morgan": "^1.10.0", + "passport": "^0.7.0", + "passport-saml": "^3.2.4", "pg": "^8.13.0", "react": "^18.3.1", "react-dom": "^18.3.1", From be39e5f221f699f3afaee35855089e55bda02480 Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Mon, 11 Nov 2024 14:24:56 -0500 Subject: [PATCH 07/63] formatting --- server.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 8b03928..4dfdd71 100644 --- a/server.js +++ b/server.js @@ -10,7 +10,12 @@ const fs = require('fs'); // Import fs module for reading certificate file const app = express(); // List of allowed origins -const allowedOrigins = ['http://localhost:3000', 'http://10.11.29.103:3000', 'http://facelect.capping.ecrl.marist.edu:3000','https://localhost:8443','https://10.11.29.103:8443', 'https://facelect.capping.ecrl.marist.edu:8443']; +const allowedOrigins = ['http://localhost:3000', + 'http://10.11.29.103:3000', + 'http://facelect.capping.ecrl.marist.edu:3000', + 'https://localhost:8443', + 'https://10.11.29.103:8443', + 'https://facelect.capping.ecrl.marist.edu:8443']; // Configure CORS to allow requests from your React app app.use(cors({ From 1d8bc73980f43b0e57339e35ea19af51a0e3edc2 Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Sun, 17 Nov 2024 17:33:30 -0500 Subject: [PATCH 08/63] merge from brendon-dev --- server.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/server.js b/server.js index 39e92c6..601af2b 100644 --- a/server.js +++ b/server.js @@ -15,15 +15,11 @@ const fs = require('fs'); // Import fs module for reading certificate file const app = express(); // List of allowed origins -<<<<<<< HEAD -const allowedOrigins = ['http://localhost:3000', 'http://10.11.29.103:3000', 'http://facelect.capping.ecrl.marist.edu:3000','http://localhost:443', 'http://10.11.29.103:443', 'http://facelect.capping.ecrl.marist.edu:443']; -======= const allowedOrigins = [ 'https://localhost', 'https://10.11.29.103', 'https://facelect.capping.ecrl.marist.edu' ]; ->>>>>>> 61494d1d9f02033965f7f18a6a59af0ace3cd238 // Configure CORS to allow requests from your React app app.use(cors({ @@ -137,17 +133,6 @@ app.get('/faculty', async (req, res) => { } }); -<<<<<<< HEAD -// HTTPS configuration -const httpsOptions = { - key: fs.readFileSync('backend/sp-key.pem'), - cert: fs.readFileSync('backend/sp-cert.pem') -}; - -// Start HTTPS server on port 443 -https.createServer(httpsOptions, app).listen(443, () => { - console.log('HTTPS server is running on port 443'); -======= // SSO login route app.get('/login', passport.authenticate('saml', { successRedirect: '/', @@ -174,7 +159,6 @@ const options = { // Create HTTPS server on port 3000 https.createServer(options, app).listen(3001, () => { console.log('HTTPS Server running on port 3001'); ->>>>>>> 61494d1d9f02033965f7f18a6a59af0ace3cd238 }); // Start HTTP server on port 3001 From 10e81fa04a723fe0e457b4ffca9812cb2d039ddb Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Sun, 17 Nov 2024 20:01:21 -0500 Subject: [PATCH 09/63] admin-login fix attempt --- src/AdminLogin.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdminLogin.tsx b/src/AdminLogin.tsx index 9b72a60..d8a1371 100644 --- a/src/AdminLogin.tsx +++ b/src/AdminLogin.tsx @@ -17,7 +17,7 @@ const AdminLogin: React.FC = () => { const handleSubmit = async (e: FormEvent) => { e.preventDefault(); try { - const response = await fetch('http://10.11.29.103:3001/admin-login', { + const response = await fetch('https://10.11.29.103:3001/admin-login', { method: 'POST', headers: { 'Content-Type': 'application/json', From dbedb071a99122e50051dfe234faf93c636acfa6 Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Sun, 17 Nov 2024 20:11:11 -0500 Subject: [PATCH 10/63] fix attempt 2 --- server.js | 5 ++++- src/AdminLogin.tsx | 2 +- src/AdminView.tsx | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index 601af2b..938bc49 100644 --- a/server.js +++ b/server.js @@ -18,7 +18,10 @@ const app = express(); const allowedOrigins = [ 'https://localhost', 'https://10.11.29.103', - 'https://facelect.capping.ecrl.marist.edu' + 'https://facelect.capping.ecrl.marist.edu', + 'http://localhost', + 'http://10.11.29.103', + 'http://facelect.capping.ecrl.marist.edu' ]; // Configure CORS to allow requests from your React app diff --git a/src/AdminLogin.tsx b/src/AdminLogin.tsx index d8a1371..93cb761 100644 --- a/src/AdminLogin.tsx +++ b/src/AdminLogin.tsx @@ -17,7 +17,7 @@ const AdminLogin: React.FC = () => { const handleSubmit = async (e: FormEvent) => { e.preventDefault(); try { - const response = await fetch('https://10.11.29.103:3001/admin-login', { + const response = await fetch('https://facelect.capping.ecrl.marist.edu/admin-login', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/src/AdminView.tsx b/src/AdminView.tsx index e1ad3b4..e6d6d95 100644 --- a/src/AdminView.tsx +++ b/src/AdminView.tsx @@ -87,7 +87,7 @@ const App: React.FC = () => { useEffect(() => { - fetch('http://10.11.29.103:3001/faculty') + fetch('https://facelect.capping.ecrl.marist.edu/faculty') .then(response => response.json()) .then(data => setRowData(data)) .catch(error => console.error('Error fetching data:', error)); From 05bf5e6bd276e5b72bad73666df52ca9bb2f370e Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Sun, 17 Nov 2024 20:12:17 -0500 Subject: [PATCH 11/63] 3 --- src/AdminLogin.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdminLogin.tsx b/src/AdminLogin.tsx index 93cb761..fb1666a 100644 --- a/src/AdminLogin.tsx +++ b/src/AdminLogin.tsx @@ -17,7 +17,7 @@ const AdminLogin: React.FC = () => { const handleSubmit = async (e: FormEvent) => { e.preventDefault(); try { - const response = await fetch('https://facelect.capping.ecrl.marist.edu/admin-login', { + const response = await fetch('https://10.11.29.103/admin-login', { method: 'POST', headers: { 'Content-Type': 'application/json', From 08d55527c4efca89b3784d926481d8a48e9181cd Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Sun, 17 Nov 2024 20:17:31 -0500 Subject: [PATCH 12/63] attempt 4 --- server.js | 3 ++- src/AdminLogin.tsx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 938bc49..f22bb5a 100644 --- a/server.js +++ b/server.js @@ -21,7 +21,8 @@ const allowedOrigins = [ 'https://facelect.capping.ecrl.marist.edu', 'http://localhost', 'http://10.11.29.103', - 'http://facelect.capping.ecrl.marist.edu' + 'http://facelect.capping.ecrl.marist.edu', + '0.0.0.0' ]; // Configure CORS to allow requests from your React app diff --git a/src/AdminLogin.tsx b/src/AdminLogin.tsx index fb1666a..93cb761 100644 --- a/src/AdminLogin.tsx +++ b/src/AdminLogin.tsx @@ -17,7 +17,7 @@ const AdminLogin: React.FC = () => { const handleSubmit = async (e: FormEvent) => { e.preventDefault(); try { - const response = await fetch('https://10.11.29.103/admin-login', { + const response = await fetch('https://facelect.capping.ecrl.marist.edu/admin-login', { method: 'POST', headers: { 'Content-Type': 'application/json', From 6c149b421bfbd6a1ee016b49c9ef9b646ced7b6f Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Sun, 17 Nov 2024 20:19:27 -0500 Subject: [PATCH 13/63] attempt 5 --- server.js | 6 +++--- src/AdminLogin.tsx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index f22bb5a..f696953 100644 --- a/server.js +++ b/server.js @@ -166,6 +166,6 @@ https.createServer(options, app).listen(3001, () => { }); // Start HTTP server on port 3001 -app.listen(3001, () => { - console.log('HTTP server is running on port 3001'); -}); \ No newline at end of file +//app.listen(3001, () => { + //console.log('HTTP server is running on port 3001'); +//}); \ No newline at end of file diff --git a/src/AdminLogin.tsx b/src/AdminLogin.tsx index 93cb761..a712c04 100644 --- a/src/AdminLogin.tsx +++ b/src/AdminLogin.tsx @@ -17,7 +17,7 @@ const AdminLogin: React.FC = () => { const handleSubmit = async (e: FormEvent) => { e.preventDefault(); try { - const response = await fetch('https://facelect.capping.ecrl.marist.edu/admin-login', { + const response = await fetch('https://facelect.capping.ecrl.marist.edu:3001/admin-login', { method: 'POST', headers: { 'Content-Type': 'application/json', From 206b64de97c940c8e1575f08ee0f561b2b045768 Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Sun, 17 Nov 2024 20:41:19 -0500 Subject: [PATCH 14/63] attempt 6 --- package-lock.json | 1 + server.js | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 07a3acb..2982c8c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13413,6 +13413,7 @@ "version": "0.7.0", "resolved": "https://registry.npmjs.org/passport/-/passport-0.7.0.tgz", "integrity": "sha512-cPLl+qZpSc+ireUvt+IzqbED1cHHkDoVYMo30jbJIdOOjQ1MQYZBPiNvmi8UM6lJuOpTPXJGZQk0DtC4y61MYQ==", + "license": "MIT", "dependencies": { "passport-strategy": "1.x.x", "pause": "0.0.1", diff --git a/server.js b/server.js index f696953..90a7d86 100644 --- a/server.js +++ b/server.js @@ -9,20 +9,17 @@ const passport = require('passport'); const SamlStrategy = require('passport-saml').Strategy; const session = require('express-session'); -const https = require('https'); // Import https module -const fs = require('fs'); // Import fs module for reading certificate files - const app = express(); // List of allowed origins const allowedOrigins = [ - 'https://localhost', + 'https://localhost:3001', 'https://10.11.29.103', - 'https://facelect.capping.ecrl.marist.edu', - 'http://localhost', + 'https://facelect.capping.ecrl.marist.edu:3001', + 'http://localhost:3000', + 'http://localhost:3001', 'http://10.11.29.103', - 'http://facelect.capping.ecrl.marist.edu', - '0.0.0.0' + 'https://facelect.capping.ecrl.marist.edu:3000', ]; // Configure CORS to allow requests from your React app @@ -161,11 +158,11 @@ const options = { }; // Create HTTPS server on port 3000 -https.createServer(options, app).listen(3001, () => { - console.log('HTTPS Server running on port 3001'); -}); +// https.createServer(options, app).listen(3001, () => { +// console.log('HTTPS Server running on port 3001'); +// }); // Start HTTP server on port 3001 -//app.listen(3001, () => { - //console.log('HTTP server is running on port 3001'); -//}); \ No newline at end of file +app.listen(3001, () => { + console.log('HTTP server is running on port 3002'); +}); \ No newline at end of file From 4ed0c3444b4a5611739e7670d4911ac882c889a7 Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Sun, 17 Nov 2024 20:50:59 -0500 Subject: [PATCH 15/63] attempt 7 --- server.js | 12 ++++++------ src/AdminView.tsx | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/server.js b/server.js index 90a7d86..6332207 100644 --- a/server.js +++ b/server.js @@ -157,12 +157,12 @@ const options = { ] }; -// Create HTTPS server on port 3000 -// https.createServer(options, app).listen(3001, () => { -// console.log('HTTPS Server running on port 3001'); -// }); +// Create HTTPS server on port 3001 +https.createServer(options, app).listen(3001, () => { + console.log('HTTPS Server running on port 3001'); +}); -// Start HTTP server on port 3001 -app.listen(3001, () => { +// Start HTTP server on port 3002 +app.listen(3002, () => { console.log('HTTP server is running on port 3002'); }); \ No newline at end of file diff --git a/src/AdminView.tsx b/src/AdminView.tsx index e6d6d95..cef7dce 100644 --- a/src/AdminView.tsx +++ b/src/AdminView.tsx @@ -87,7 +87,7 @@ const App: React.FC = () => { useEffect(() => { - fetch('https://facelect.capping.ecrl.marist.edu/faculty') + fetch('http://facelect.capping.ecrl.marist.edu/faculty') .then(response => response.json()) .then(data => setRowData(data)) .catch(error => console.error('Error fetching data:', error)); From f75eb09b2e0e5b66e8299abe9e90631737d4ae57 Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Sun, 17 Nov 2024 23:17:22 -0500 Subject: [PATCH 16/63] a --- server.js | 2 ++ src/AdminView.tsx | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 6332207..defa388 100644 --- a/server.js +++ b/server.js @@ -14,8 +14,10 @@ const app = express(); // List of allowed origins const allowedOrigins = [ 'https://localhost:3001', + 'https://localhost', 'https://10.11.29.103', 'https://facelect.capping.ecrl.marist.edu:3001', + 'https://facelect.capping.ecrl.marist.edu', 'http://localhost:3000', 'http://localhost:3001', 'http://10.11.29.103', diff --git a/src/AdminView.tsx b/src/AdminView.tsx index cef7dce..e6d6d95 100644 --- a/src/AdminView.tsx +++ b/src/AdminView.tsx @@ -87,7 +87,7 @@ const App: React.FC = () => { useEffect(() => { - fetch('http://facelect.capping.ecrl.marist.edu/faculty') + fetch('https://facelect.capping.ecrl.marist.edu/faculty') .then(response => response.json()) .then(data => setRowData(data)) .catch(error => console.error('Error fetching data:', error)); From 15c2a14db9e4b9aa9e7ea585f8f53276ff2e83b7 Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Sun, 17 Nov 2024 23:21:32 -0500 Subject: [PATCH 17/63] logging messages for debugging --- server.js | 1 + src/AdminLogin.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/server.js b/server.js index defa388..2d266d5 100644 --- a/server.js +++ b/server.js @@ -87,6 +87,7 @@ passport.deserializeUser((user, done) => { // Route to handle admin login app.post('/admin-login', async (req, res) => { + console.log('Received admin login request'); // Log request received const { username, password } = req.body; // Capture username and password from request try { diff --git a/src/AdminLogin.tsx b/src/AdminLogin.tsx index a712c04..edca632 100644 --- a/src/AdminLogin.tsx +++ b/src/AdminLogin.tsx @@ -16,6 +16,7 @@ const AdminLogin: React.FC = () => { const handleSubmit = async (e: FormEvent) => { e.preventDefault(); + console.log('Submitting login form'); // Log form submission try { const response = await fetch('https://facelect.capping.ecrl.marist.edu:3001/admin-login', { method: 'POST', From 0458b9931965cdde29d8d23983653d2ea168f95b Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Sun, 17 Nov 2024 23:33:26 -0500 Subject: [PATCH 18/63] cors test --- server.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/server.js b/server.js index 2d266d5..1e0e1a4 100644 --- a/server.js +++ b/server.js @@ -26,15 +26,17 @@ const allowedOrigins = [ // Configure CORS to allow requests from your React app app.use(cors({ - origin: function (origin, callback) { - // Allow requests with no origin (like mobile apps or curl requests) - if (!origin) return callback(null, true); - if (allowedOrigins.indexOf(origin) === -1) { - const msg = 'The CORS policy for this site does not allow access from the specified Origin.'; - return callback(new Error(msg), false); - } - return callback(null, true); - } + origin: '*' + + // function (origin, callback) { + // // Allow requests with no origin (like mobile apps or curl requests) + // if (!origin) return callback(null, true); + // if (allowedOrigins.indexOf(origin) === -1) { + // const msg = 'The CORS policy for this site does not allow access from the specified Origin.'; + // return callback(new Error(msg), false); + // } + // return callback(null, true); + // } })); app.use(express.json()); // Parse incoming JSON data From 72fd9296a63de7f01f14a921571f3f1cf09371e7 Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Sun, 17 Nov 2024 23:34:31 -0500 Subject: [PATCH 19/63] reverted cors change --- server.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/server.js b/server.js index 1e0e1a4..2d266d5 100644 --- a/server.js +++ b/server.js @@ -26,17 +26,15 @@ const allowedOrigins = [ // Configure CORS to allow requests from your React app app.use(cors({ - origin: '*' - - // function (origin, callback) { - // // Allow requests with no origin (like mobile apps or curl requests) - // if (!origin) return callback(null, true); - // if (allowedOrigins.indexOf(origin) === -1) { - // const msg = 'The CORS policy for this site does not allow access from the specified Origin.'; - // return callback(new Error(msg), false); - // } - // return callback(null, true); - // } + origin: function (origin, callback) { + // Allow requests with no origin (like mobile apps or curl requests) + if (!origin) return callback(null, true); + if (allowedOrigins.indexOf(origin) === -1) { + const msg = 'The CORS policy for this site does not allow access from the specified Origin.'; + return callback(new Error(msg), false); + } + return callback(null, true); + } })); app.use(express.json()); // Parse incoming JSON data From ee9c499c2c083b193389792aaba2b55c997deda1 Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Sun, 17 Nov 2024 23:49:35 -0500 Subject: [PATCH 20/63] cors test 2 --- server.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index 2d266d5..3f8d537 100644 --- a/server.js +++ b/server.js @@ -29,12 +29,17 @@ app.use(cors({ origin: function (origin, callback) { // Allow requests with no origin (like mobile apps or curl requests) if (!origin) return callback(null, true); - if (allowedOrigins.indexOf(origin) === -1) { + + if (allowedOrigins.includes(origin)) { + return callback(null, true); + } else { const msg = 'The CORS policy for this site does not allow access from the specified Origin.'; return callback(new Error(msg), false); } - return callback(null, true); - } + }, + methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], // Allow common methods + allowedHeaders: ['Content-Type', 'Authorization'], // Specify headers your API expects + credentials: true, // Allow cookies and credentials })); app.use(express.json()); // Parse incoming JSON data From 5cc5c9aecdace303945601f67d22be94a423da93 Mon Sep 17 00:00:00 2001 From: AaronBonilla Date: Sun, 17 Nov 2024 23:50:53 -0500 Subject: [PATCH 21/63] revert cors tests 2 --- server.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/server.js b/server.js index 3f8d537..2d266d5 100644 --- a/server.js +++ b/server.js @@ -29,17 +29,12 @@ app.use(cors({ origin: function (origin, callback) { // Allow requests with no origin (like mobile apps or curl requests) if (!origin) return callback(null, true); - - if (allowedOrigins.includes(origin)) { - return callback(null, true); - } else { + if (allowedOrigins.indexOf(origin) === -1) { const msg = 'The CORS policy for this site does not allow access from the specified Origin.'; return callback(new Error(msg), false); } - }, - methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], // Allow common methods - allowedHeaders: ['Content-Type', 'Authorization'], // Specify headers your API expects - credentials: true, // Allow cookies and credentials + return callback(null, true); + } })); app.use(express.json()); // Parse incoming JSON data From 7f25016d81ceb603728f8ad184a628c1d97f2786 Mon Sep 17 00:00:00 2001 From: Brendon Kupsch Date: Mon, 18 Nov 2024 11:23:22 -0500 Subject: [PATCH 22/63] Https site all errors fixed --- package-lock.json | 77 ++++++++++++++++--------------- package.json | 3 +- server.js | 31 +++++++++++-- src/AdminView.tsx | 2 +- src/App.tsx | 40 ++++++++-------- src/components/WebSocketClient.js | 36 +++++++++++++++ src/useWebSocket.js | 45 ++++++++++++++++++ 7 files changed, 171 insertions(+), 63 deletions(-) create mode 100644 src/components/WebSocketClient.js create mode 100644 src/useWebSocket.js diff --git a/package-lock.json b/package-lock.json index 2982c8c..44ec2c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,8 @@ "react-scripts": "5.0.1", "react-select": "^5.8.2", "typescript": "^4.9.5", - "web-vitals": "^2.1.4" + "web-vitals": "^2.1.4", + "ws": "^8.18.0" } }, "node_modules/@adobe/css-tools": { @@ -12384,6 +12385,27 @@ } } }, + "node_modules/jsdom/node_modules/ws": { + "version": "7.5.10", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz", + "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==", + "license": "MIT", + "engines": { + "node": ">=8.3.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, "node_modules/jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -18094,26 +18116,6 @@ } } }, - "node_modules/webpack-dev-server/node_modules/ws": { - "version": "8.18.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", - "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", - "engines": { - "node": ">=10.0.0" - }, - "peerDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": ">=5.0.2" - }, - "peerDependenciesMeta": { - "bufferutil": { - "optional": true - }, - "utf-8-validate": { - "optional": true - } - } - }, "node_modules/webpack-manifest-plugin": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/webpack-manifest-plugin/-/webpack-manifest-plugin-4.1.1.tgz", @@ -18760,15 +18762,16 @@ } }, "node_modules/ws": { - "version": "7.5.10", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz", - "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==", + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", + "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", + "license": "MIT", "engines": { - "node": ">=8.3.0" + "node": ">=10.0.0" }, "peerDependencies": { "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" + "utf-8-validate": ">=5.0.2" }, "peerDependenciesMeta": { "bufferutil": { @@ -27648,6 +27651,14 @@ "whatwg-url": "^8.5.0", "ws": "^7.4.6", "xml-name-validator": "^3.0.0" + }, + "dependencies": { + "ws": { + "version": "7.5.10", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz", + "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==", + "requires": {} + } } }, "jsesc": { @@ -31619,14 +31630,6 @@ "spdy": "^4.0.2", "webpack-dev-middleware": "^5.3.4", "ws": "^8.13.0" - }, - "dependencies": { - "ws": { - "version": "8.18.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", - "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", - "requires": {} - } } }, "webpack-manifest-plugin": { @@ -32132,9 +32135,9 @@ } }, "ws": { - "version": "7.5.10", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz", - "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==", + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", + "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", "requires": {} }, "xml-crypto": { diff --git a/package.json b/package.json index e4627ca..708333b 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "react-scripts": "5.0.1", "react-select": "^5.8.2", "typescript": "^4.9.5", - "web-vitals": "^2.1.4" + "web-vitals": "^2.1.4", + "ws": "^8.18.0" }, "scripts": { "start": "concurrently \"react-scripts start\" \"node server.js\"", diff --git a/server.js b/server.js index 2d266d5..cb0ae2b 100644 --- a/server.js +++ b/server.js @@ -8,6 +8,7 @@ const fs = require('fs'); const passport = require('passport'); const SamlStrategy = require('passport-saml').Strategy; const session = require('express-session'); +const WebSocket = require('ws'); const app = express(); @@ -22,6 +23,7 @@ const allowedOrigins = [ 'http://localhost:3001', 'http://10.11.29.103', 'https://facelect.capping.ecrl.marist.edu:3000', + 'https://facelect.capping.ecrl.marist.edu/', ]; // Configure CORS to allow requests from your React app @@ -160,12 +162,35 @@ const options = { ] }; -// Create HTTPS server on port 3001 -https.createServer(options, app).listen(3001, () => { +const httpsServer = https.createServer(options, app); +httpsServer.listen(3001, () => { console.log('HTTPS Server running on port 3001'); }); +// Initialize WebSocket server on the HTTPS server +const wss = new WebSocket.Server({ server: httpsServer, path: '/ws' }); + +// Handle WebSocket connections +wss.on('connection', (ws) => { + console.log('New WebSocket connection established'); + + ws.on('message', (message) => { + console.log(`Received message: ${message}`); + ws.send(`Server received: ${message}`); + }); + + ws.on('close', () => { + console.log('WebSocket connection closed'); + }); + + ws.on('error', (error) => { + console.error('WebSocket error:', error); + }); +}); + // Start HTTP server on port 3002 app.listen(3002, () => { console.log('HTTP server is running on port 3002'); -}); \ No newline at end of file +}); + + diff --git a/src/AdminView.tsx b/src/AdminView.tsx index e6d6d95..898c9e4 100644 --- a/src/AdminView.tsx +++ b/src/AdminView.tsx @@ -87,7 +87,7 @@ const App: React.FC = () => { useEffect(() => { - fetch('https://facelect.capping.ecrl.marist.edu/faculty') + fetch('https://facelect.capping.ecrl.marist.edu:3001/faculty') .then(response => response.json()) .then(data => setRowData(data)) .catch(error => console.error('Error fetching data:', error)); diff --git a/src/App.tsx b/src/App.tsx index 17119a0..cdaa01f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,29 +1,30 @@ -import React from 'react'; +import React, { createContext, useContext, useEffect, useState } from 'react'; import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom'; -import Login from './Login'; // Login component +import Login from './Login'; // Login component import AdminLogin from './AdminLogin'; // Admin login component import AdminView from './AdminView'; // Admin view component import UserProfile from './UserProfile'; // User profile component import { AuthProvider, useAuth } from './AuthContext'; // Adjust the path as necessary +import WebSocketComponent from './components/WebSocketClient'; function App() { return ( - - - {/* Default route for the login page */} - } /> + + + {/* Default route for the login page */} + } /> - {/* Route for the admin login page */} - } /> + {/* Route for the admin login page */} + } /> - {/* Protected route for the admin view page */} - } /> + {/* Protected route for the admin view page */} + } /> - {/* Route for the user profile page */} - } /> - - + {/* Route for the user profile page */} + } /> + + ); } @@ -32,13 +33,10 @@ function App() { const ProtectedAdminRoute = () => { const { isAuthenticated, isAdmin } = useAuth(); - return ( - isAuthenticated && isAdmin ? ( - - ) : ( - - ) + return isAuthenticated && isAdmin ? ( + + ) : ( + ); }; - export default App; diff --git a/src/components/WebSocketClient.js b/src/components/WebSocketClient.js new file mode 100644 index 0000000..2662b8a --- /dev/null +++ b/src/components/WebSocketClient.js @@ -0,0 +1,36 @@ +import React, { useEffect, useState } from 'react'; +import useWebSocket from '../src/useWebSocket.js'; + +const WebSocketComponent = () => { + const { messages, sendMessage } = useWebSocket('wss://facelect.capping.ecrl.marist.edu:3001/ws'); // Use the hook + const [inputMessage, setInputMessage] = useState(''); + + const handleSendMessage = () => { + sendMessage(inputMessage); // Send the message using the hook + setInputMessage(''); // Clear the input field + }; + + return ( +
+

WebSocket Example

+ setInputMessage(e.target.value)} + placeholder="Type a message" + /> + +
+

Messages from Server:

+
    + {messages.map((msg, index) => ( +
  • {msg}
  • + ))} +
+
+
+ ); +}; + +export default WebSocketComponent; + diff --git a/src/useWebSocket.js b/src/useWebSocket.js new file mode 100644 index 0000000..e07aaca --- /dev/null +++ b/src/useWebSocket.js @@ -0,0 +1,45 @@ +import { useEffect, useRef, useState } from 'react'; + +const useWebSocket = (url) => { + const [messages, setMessages] = useState([]); + const socketRef = useRef(null); + + useEffect(() => { + const ws = new WebSocket(url); + + ws.onopen = () => { + console.log('WebSocket connection established'); + }; + + ws.onmessage = (event) => { + console.log('Message from server:', event.data); + setMessages((prev) => [...prev, event.data]); + }; + + ws.onerror = (error) => { + console.error('WebSocket error:', error); + }; + + ws.onclose = () => { + console.log('WebSocket connection closed'); + }; + + socketRef.current = ws; + + return () => { + ws.close(); + }; + }, [url]); + + const sendMessage = (message) => { + if (socketRef.current && socketRef.current.readyState === WebSocket.OPEN) { + socketRef.current.send(message); + } else { + console.error('WebSocket is not open'); + } + }; + + return { messages, sendMessage }; +}; + +export default useWebSocket; From 7d3204e106d9bed44870db1be5df34a4b24c7be5 Mon Sep 17 00:00:00 2001 From: Ethan Date: Mon, 18 Nov 2024 12:43:48 -0500 Subject: [PATCH 23/63] changes to user profile --- src/UserProfile.css | 32 +++++++- src/UserProfile.tsx | 121 +++++++++++++++++-------------- src/components/navbar/Navbar.css | 11 +++ src/components/navbar/Navbar.tsx | 5 +- 4 files changed, 111 insertions(+), 58 deletions(-) diff --git a/src/UserProfile.css b/src/UserProfile.css index a68645d..c4cd668 100644 --- a/src/UserProfile.css +++ b/src/UserProfile.css @@ -3,9 +3,13 @@ * { font-family: "Inter", serif; } +.container{ + background-color: white; +} + .profile-form-container { - background-color: #f8f8f8; + background-color: white; border-radius: 20px; padding: 50px; max-width: 500px; @@ -14,7 +18,7 @@ } h1 { - font-size: 24px; + font-size: 30px; color: #b21e2d; text-align: center; } @@ -109,5 +113,29 @@ select, width: 30px; } +.profile-view{ + font-size: larger; +} + +.edit-button{ + background-color: #b21e2d; + border: 2px solid #fe6978; + cursor: pointer; + display: flex; + justify-content: flex-end; + margin: auto; + transition-duration: 0.4s; + color: white; + padding: 10px; + font-size: large; + border-radius: 15px; + margin-top: 30px; + margin-bottom: -10px; +} + +.edit-button:hover { + background-color: #831b25; +} + diff --git a/src/UserProfile.tsx b/src/UserProfile.tsx index 18ad6ec..a35b24d 100644 --- a/src/UserProfile.tsx +++ b/src/UserProfile.tsx @@ -6,6 +6,7 @@ import CreatableSelect from 'react-select/creatable'; import Select from 'react-select'; const UserProfile: React.FC = () => { + const [isEditing, setIsEditing] = useState(false); // State to track if in edit mode const [preferredName, setPreferredName] = useState(''); const [school, setSchool] = useState(''); const [committees, setCommittees] = useState([]); @@ -27,66 +28,76 @@ const UserProfile: React.FC = () => { setCommittees(selectedOptions ? selectedOptions.map((option: any) => option.value) : []); }; + const handleSave = () => { + setIsEditing(false); + // You can also trigger a save to the database here + }; + return ( -
+
-

Your Election Profile

+

Your Election Profile

-
- {/* Preferred Name Input */} -
- - setPreferredName(e.target.value)} - placeholder="Your Preferred Name Here" - /> -
- - {/* Dropdown for School */} -
- -