From 1ddce4b74320f6bbb9d0c1e1f24cd3906ef879c9 Mon Sep 17 00:00:00 2001 From: newtbot Date: Tue, 16 Jan 2024 21:06:37 +0800 Subject: [PATCH] blah --- consumerWebsite/Vivian/eco saver.mwb | Bin 0 -> 5287 bytes consumerWebsite/Vivian/index.php | 22 ++++++++ consumerWebsite/Vivian/login.html | 21 ++++++++ consumerWebsite/Vivian/login.js | 37 +++++++++++++ consumerWebsite/Vivian/server.js | 44 +++++++++++++++ consumerWebsite/Vivian/signup.html | 24 +++++++++ consumerWebsite/Vivian/signup.js | 35 ++++++++++++ webserver/functions/Database.js | 2 +- webserver/routes/apiLog.js | 77 +++++++++++++++++++++++++++ webserver/routes/api_route.js | 3 ++ 10 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 consumerWebsite/Vivian/eco saver.mwb create mode 100644 consumerWebsite/Vivian/index.php create mode 100644 consumerWebsite/Vivian/login.html create mode 100644 consumerWebsite/Vivian/login.js create mode 100644 consumerWebsite/Vivian/server.js create mode 100644 consumerWebsite/Vivian/signup.html create mode 100644 consumerWebsite/Vivian/signup.js create mode 100644 webserver/routes/apiLog.js diff --git a/consumerWebsite/Vivian/eco saver.mwb b/consumerWebsite/Vivian/eco saver.mwb new file mode 100644 index 0000000000000000000000000000000000000000..563e07f805759ba0cb8891ac9c4da3cb76867ea5 GIT binary patch literal 5287 zcmZ{oWmFXIw#EmBE(giKFmyA-5P~>#cS|=z&M*Q4f(l3uBB3-$H;8nDbayBz-5?+! zB7O0kb=JD;u6y>o-nIAI&wjo=pME;(KpaW{Hh=(tk6|@_XWE6tA_o8#Qvm=F006K@ z*?A%1ZfJhw3tN64B;vrr%yXe3)<4r~^<>>ZmYLu^Q~kqC7A%ixue5I0r=H%KdX%_B zk-if@ZTlQu@2;@(*oLaOj)VT``)8Y(U9PuK3Akt_=Jxt7=1BE5y6==_aPmRl^BnNq z`bN@ubrwnVmhZ)x#86z;_4Cqq0?`g8#_TY@w!{a-x2u2FyEX&T!8g1^s6rS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>R`Oe^%4`el(LrjrA&5m5EAe`i}XL}81orfv?{%Ni$&pxQ!Dxz5mMNF6W zCLU{2ydF9+H2h>V!sS<5d{&&|X+wi+^-Zxs8}6%WZHT_?0qd&`EzMiJ*vVUOf0Adp zeeipP80_-vM8Tpw^~xa*kC*5Xf6ZH2thx%)3W0+V6aI0;*mL@@h?nlF~p*#-9{#sQF;nJNL}Zdi{(rvACWQ zdGb(Mn2oOBSg?I9{RHeF7Cy5do8y~ss$5&Px?CGoCb{RO`~ymEr`{?MITixpbxetf z(O#I?95k6zrHN%Uax1=V`3TD-9sJ!p;f?|{lAJmn|HzU}kO)uH8NJ zK1$HK?x^3;58s#}qoZD2t zbo3PD;;S)(m!-#hzTx_b`! zf+pGiu#Q)l#p+bYYtvs}p2#YdyUpLwi@$~DHJDq>w zl6x`&U=3n5E*B$o!M&gVew_P{K-swp35h_3{(bhBsz`*g8jI@dn+agw>-R{7_`b>5 z+X~p*pl$f=Z4VO1Q1gP6ec(3~VgWP(dw!5R&)R?u+alIG zy}+{MU~IwbZouv7uxi)*56tv>%@!-?=;^Cvntg78fj>?aYU1W@xq>QLcqKBi?Vbc! z08w{?4!&Z(Dv z3;kvgakNGCv|uz4jdwvDD)t<|S8p9%adBHlox#_vRlO-rLb-9A@n(LdgvJA23H* z%8*;rjk`I|CsL2v!MI~V0yi4x?;KwxUUvvDhcPd+wGBL`|Kg*lr2i*YYc+;+dG5rm zcnX2m$)9GqdT5NKz83Otrp7%EKDGZi=WnUOxJ~0MVD!ZoI3 zO9THque%S|zp5_qZ~MRW?mzCo+W!~dzx%&c7btMg0RM*hKaT&F@O6@mA!_`a7>000sIO<#Ro4JIR$hpR2z&CZEQ6J-xaFxhz6IXQd7nV|fFM99Az XK2JL*IMT*bf=SU1rElX6_aOQoo&WGx literal 0 HcmV?d00001 diff --git a/consumerWebsite/Vivian/index.php b/consumerWebsite/Vivian/index.php new file mode 100644 index 0000000..ba3725b --- /dev/null +++ b/consumerWebsite/Vivian/index.php @@ -0,0 +1,22 @@ + + + + + + + + + + + Hello, world! + + +

Hello, world!

+ + + + + + + + \ No newline at end of file diff --git a/consumerWebsite/Vivian/login.html b/consumerWebsite/Vivian/login.html new file mode 100644 index 0000000..25f261c --- /dev/null +++ b/consumerWebsite/Vivian/login.html @@ -0,0 +1,21 @@ + + + + + + Login Page + + + +

Login

+
+ + + + + + + +
+ + diff --git a/consumerWebsite/Vivian/login.js b/consumerWebsite/Vivian/login.js new file mode 100644 index 0000000..a88887f --- /dev/null +++ b/consumerWebsite/Vivian/login.js @@ -0,0 +1,37 @@ +function validateForm() { + var username = document.getElementById('email').value; + var password = document.getElementById('password').value; + + // Perform basic validation + if (!email || !password) { + alert('Please enter both email and password'); + return; + } + + // If validation passes, send data to the server + sendDataToServer(email, password); +} + +function sendDataToServer(email, password) { + // Use AJAX or fetch to send data to the server + // Example using fetch: + fetch('/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ email, password }), + }) + .then(response => response.json()) + .then(data => { + // Handle the response from the server + console.log(data); + if (data.success) { + // Redirect or perform other actions for successful login + alert('Login successful'); + } else { + alert('Login failed. Please check your credentials.'); + } + }) + .catch(error => console.error('Error:', error)); +} diff --git a/consumerWebsite/Vivian/server.js b/consumerWebsite/Vivian/server.js new file mode 100644 index 0000000..6d8edc6 --- /dev/null +++ b/consumerWebsite/Vivian/server.js @@ -0,0 +1,44 @@ +const express = require('express'); +const bodyParser = require('body-parser'); +const mysql = require('mysql'); + +const app = express(); +const port = 3000; + +app.use(bodyParser.json()); + +const db = mysql.createConnection({ + host: 'localhost', + user: 'root', + password: 'your_mysql_password', + database: 'your_database_name', +}); + +db.connect(err => { + if (err) { + console.error('Error connecting to MySQL:', err); + } else { + console.log('Connected to MySQL'); + } +}); + +app.post('/signup', (req, res) => { + const { username, password } = req.body; + + // Perform server-side validation if needed + + const sql = 'INSERT INTO users (username, password) VALUES (?, ?)'; + db.query(sql, [username, password], (err, result) => { + if (err) { + console.error('Error executing SQL query:', err); + res.status(500).json({ success: false, message: 'Internal Server Error' }); + } else { + console.log('User signed up successfully'); + res.json({ success: true, message: 'User signed up successfully' }); + } + }); +}); + +app.listen(port, () => { + console.log(`Server is running on http://localhost:${port}`); +}); diff --git a/consumerWebsite/Vivian/signup.html b/consumerWebsite/Vivian/signup.html new file mode 100644 index 0000000..28a7d84 --- /dev/null +++ b/consumerWebsite/Vivian/signup.html @@ -0,0 +1,24 @@ + + + + + + Signup Page + + + +

Signup

+
+ + + + + + + + + + +
+ + diff --git a/consumerWebsite/Vivian/signup.js b/consumerWebsite/Vivian/signup.js new file mode 100644 index 0000000..2f036a4 --- /dev/null +++ b/consumerWebsite/Vivian/signup.js @@ -0,0 +1,35 @@ +function validateForm() { + var userid = document.getElementById('user_id').value; + var username = document.getElementById('user_name').value; + var email = document.getElementById('email').value; + var password = document.getElementById('password').value; + var confirmPassword = document.getElementById('confirmPassword').value; + var email = document.getElementById('email').value; + + // Perform basic validation + if (password !== confirmPassword) { + alert('Passwords do not match'); + return; + } + + // If validation passes, send data to the server + sendDataToServer(username, email, password); +} + +function sendDataToServer(username, password) { + // Use AJAX or fetch to send data to the server + // Example using fetch: + fetch('/signup', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ username, email, password }), + }) + .then(response => response.json()) + .then(data => { + // Handle the response from the server + console.log(data); + }) + .catch(error => console.error('Error:', error)); +} diff --git a/webserver/functions/Database.js b/webserver/functions/Database.js index 2c73813..d18f7dd 100644 --- a/webserver/functions/Database.js +++ b/webserver/functions/Database.js @@ -2,7 +2,7 @@ const { sequelize } = require("../Database/mySql.js"); const { api_log_Model } = require("../Database/model/apiLogModel.js"); const { sensorDataModel } = require("../Database/model/sensorDataModel.js"); const { apikeyModel } = require("../Database/model/apiKeyModel.js"); -const { compareAPIKey } = require("../functions/bcrypt.js"); +const { compareAPIKey } = require("./bcrypt.js"); async function insertLogData(log) { try { diff --git a/webserver/routes/apiLog.js b/webserver/routes/apiLog.js new file mode 100644 index 0000000..80ed39a --- /dev/null +++ b/webserver/routes/apiLog.js @@ -0,0 +1,77 @@ +const { + +} = require("../functions/apiDatabase.js"); + +const express = require("express"); +const router = express.Router(); + + + +module.exports = router; + +/* + +//get location +router.get("/", async (req, res, next) => { + try { + const location = await getLocation(); + //res send json and status code + res.status(200).json(location); + } catch (error) { + console.error(error); + next(error); + } +}); + + +//add location +router.post("/new", async (req, res, next) => { + try { + const { name, added_by, description } = req.body; + await addLocation(name, added_by, description); + res.sendStatus(200) + } catch (error) { + console.error(error); + next(error); + } +}); + +//update location +router.put("/update", async (req, res, next) => { + try { + const { id, name, added_by, description } = req.body; + await updateLocation(id, name, added_by, description); + res.status(200).json({ message: "Location " + id + " updated" }); + } catch (error) { + console.error(error); + next(error); + } +}); + +//delete location +router.delete("/delete", async (req, res, next) => { + try { + const { id } = req.body; + await deleteLocation(id); + res.status(200).json({ message: "Location " + id + " deleted" }); + } catch (error) { + console.error(error); + next(error); + } +}); + + + +//get location by id +router.get("/:id", async (req, res, next) => { + try { + //get params + const { id } = req.params; + const location = await getLocationById(id); + res.status(200).json(location); + } catch (error) { + console.error(error); + next(error); + } +}); +*/ \ No newline at end of file diff --git a/webserver/routes/api_route.js b/webserver/routes/api_route.js index a90c0df..1144957 100644 --- a/webserver/routes/api_route.js +++ b/webserver/routes/api_route.js @@ -26,6 +26,9 @@ router.use('/sensor', require('./sensor')) //sensor data route router.use('/sensor-data', require('./sensorData')); +//log route +//router.use('/log', require('./logLog')); +