diff --git a/consumerWebsite/app.js b/consumerWebsite/app.js index e6ce391..9d61535 100644 --- a/consumerWebsite/app.js +++ b/consumerWebsite/app.js @@ -2,7 +2,6 @@ const express = require("express"); const { rateLimit } = require("express-rate-limit"); const path = require("path"); const app = express(); -const port = 3000; const ejs = require("ejs"); module.exports = app; diff --git a/consumerWebsite/database/model/sensorModel.js b/consumerWebsite/database/model/sensorModel.js index d1eb2c3..0c83ac1 100644 --- a/consumerWebsite/database/model/sensorModel.js +++ b/consumerWebsite/database/model/sensorModel.js @@ -107,6 +107,6 @@ const sensorModel = sequelize.define( } ); -sensorModel.belongsTo(locationModel); +//sensorModel.belongsTo(locationModel); module.exports = { sensorModel }; diff --git a/consumerWebsite/database/model/tokenModel.js b/consumerWebsite/database/model/tokenModel.js index 17e6e4e..0b0fe49 100644 --- a/consumerWebsite/database/model/tokenModel.js +++ b/consumerWebsite/database/model/tokenModel.js @@ -3,7 +3,7 @@ const { Sequelize, DataTypes } = require("sequelize"); const { sequelize } = require("../mySQL"); const { userModel } = require("./userModel"); -sequelize.sync(); +//sequelize.sync(); const tokenModel = sequelize.define( "token", { @@ -48,6 +48,14 @@ const tokenModel = sequelize.define( isIn: [["canRead", "canWrite",]], }, }, + isKey: { + type: DataTypes.STRING, + allowNull: true, + length: 45, + validate:{ + isIn: [["isKey" , "isNotKey"]], + } + }, expiration: { type: DataTypes.DATE, allowNull: false, diff --git a/consumerWebsite/database/mySQL.js b/consumerWebsite/database/mySQL.js index 275674f..6bba43b 100644 --- a/consumerWebsite/database/mySQL.js +++ b/consumerWebsite/database/mySQL.js @@ -15,7 +15,7 @@ const sequelize = new Sequelize( attributeBehavior: 'escape', dialectOptions: { ssl: { - ca: fs.readFileSync(path.resolve(__dirname, '../cert/DigiCertGlobalRootCA.crt.pem')), + ca: fs.readFileSync(path.resolve(__dirname, '../cert/DigiCertGlobalRootCA.crt_3.pem')), }, }, diff --git a/consumerWebsite/functions/api.js b/consumerWebsite/functions/api.js index 5422d8b..4f456d1 100644 --- a/consumerWebsite/functions/api.js +++ b/consumerWebsite/functions/api.js @@ -30,7 +30,7 @@ async function getTokenByToken(token) { return token; } -async function addToken(userId, permission, expiry) { +async function addToken(userId, permission, isKey ,expiry) { let uuid = await generateUUID(); let hashtoken = await hash(uuid); //console.log("user id", userId); @@ -41,6 +41,7 @@ async function addToken(userId, permission, expiry) { userid: userId, token: hashtoken, permission: permission, + isKey: isKey, expiration: expiry, }); @@ -48,4 +49,16 @@ async function addToken(userId, permission, expiry) { return token.id + "-" + uuid; } -module.exports = { addToken, getTokenByToken }; +async function checkToken(id) { + let tokenRes = await tokenModel.findOne( + { + where: { + userid: id, + } + } + + ); + return tokenRes; +} + +module.exports = { addToken, getTokenByToken , checkToken}; diff --git a/consumerWebsite/functions/user.js b/consumerWebsite/functions/user.js index d79d86d..987968e 100644 --- a/consumerWebsite/functions/user.js +++ b/consumerWebsite/functions/user.js @@ -84,7 +84,7 @@ async function loginUser(user) { //let tokenToLive = moment().add(30, 'minutes').format(); let currentDate = new Date(); let tokenToLive = new Date(currentDate.getTime() + 30 * 60000); - let token = await addToken(userRes.id , "canRead" , tokenToLive); + let token = await addToken(userRes.id , "canRead" , "isNotKey" , tokenToLive); return { token: token, userid: userRes.id, username: userRes.username }; } diff --git a/consumerWebsite/functions/validateData.js b/consumerWebsite/functions/validateData.js index d3f255f..dcf05e0 100644 --- a/consumerWebsite/functions/validateData.js +++ b/consumerWebsite/functions/validateData.js @@ -1,5 +1,9 @@ var validator = require("validator"); +/* +All the validation functions are used by database model. +*/ + const dateRegex = /^[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT$/; function isValidDateString(value) { diff --git a/consumerWebsite/public/css/api.css b/consumerWebsite/public/css/api.css index e1d3812..d462c29 100644 --- a/consumerWebsite/public/css/api.css +++ b/consumerWebsite/public/css/api.css @@ -547,106 +547,3 @@ body.one-content-column-version .content thead { background-color: #45a049; /* Darker green on hover */ } -.delete-key-button { - float: right; /* Align the button to the right */ - margin-right: 78%; - margin-top: -40px; /* Adjust the margin-top value based on your layout */ - /* Add any additional styling you want for the button */ -} - -#content-get-api .delete-key-button { - background-color: #af4c4c; /* Green background color */ - color: white; /* White text color */ - padding: 5px 11px; /* Padding for the button */ - border: none; /* Remove button border */ - border-radius: 5px; /* Add border-radius for rounded corners */ - cursor: pointer; /* Add pointer cursor on hover */ - font-size: 14px; /* Font size */ -} - -#content-get-api .delete-key-button:hover { - background-color: #a04545; /* Darker green on hover */ -} - - -.generate-key-screen { - position: fixed; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); - padding: 30px; - width: 400px; /* Adjust the width as needed */ - background-color: #ffffff; - border: 1px solid #eaeaea; - box-shadow: 0 0 20px rgba(0, 0, 0, 0.1); /* Adjust the shadow as needed */ - z-index: 1000; - border-radius: 12px; /* Slightly increased border-radius for a softer look */ - overflow: hidden; /* Hide overflow content */ -} - -.generate-key-screen label { - display: block; - margin-bottom: 8px; - color: #333; -} - -.generate-key-screen input { - width: 100%; - padding: 8px; - margin-bottom: 16px; - box-sizing: border-box; - border: 1px solid #ccc; - border-radius: 4px; -} - -.generate-key-screen button { - background-color: #4caf50; - color: #fff; - padding: 10px 15px; - border: none; - border-radius: 4px; - cursor: pointer; - transition: background-color 0.3s ease; -} - -.generate-key-screen button:hover { - background-color: #45a049; -} - -.generate-key-screen button + button { - margin-left: 8px; - background-color: #f44336; -} - -.generate-key-screen button + button:hover { - background-color: #d32f2f; -} - -.key-input { - display: flex; - align-items: center; -} - -.key-input input { - flex: 1; - padding: 8px; - margin-right: 8px; - box-sizing: border-box; - border: 1px solid #ccc; - border-radius: 4px; -} - -.key-input button { - background-color: #4caf50; - color: #fff; - padding: 8px 12px; - border: none; - border-radius: 4px; - cursor: pointer; - transition: background-color 0.3s ease; -} - -.key-input button:hover { - background-color: #45a049; -} - diff --git a/consumerWebsite/public/css/style.css b/consumerWebsite/public/css/style.css index 3958ad7..5a15ebc 100644 --- a/consumerWebsite/public/css/style.css +++ b/consumerWebsite/public/css/style.css @@ -147,13 +147,13 @@ button.btn-secondary:hover{ border: none; } .services-bar .card h4.card-header{ - background-color: #4e3914; + background-color: #ffffff; color: #4eae3a; font-size: 18px; font-weight: 400; } .services-bar .card .card-footer{ - background-color: #4e3914; + background-color: #ffffff; } .about-main{ padding: 30px 0px; diff --git a/consumerWebsite/public/js/learnmore.js b/consumerWebsite/public/js/learnmore.js index a8948ee..67e27c7 100644 --- a/consumerWebsite/public/js/learnmore.js +++ b/consumerWebsite/public/js/learnmore.js @@ -5,8 +5,6 @@ document.addEventListener("DOMContentLoaded", function () { const aqi = "15"; const temperature = "25°C"; const humidity = "60%"; - const pm25 = "10"; - const pm10 = "20"; const so2 = "5"; const o3 = "35"; const co = "0.5"; @@ -15,7 +13,6 @@ document.addEventListener("DOMContentLoaded", function () { infoContainer.innerHTML = `