From 908a8bd351843284ed1ad5a60d2d015b8380f04f Mon Sep 17 00:00:00 2001 From: newtbot Date: Fri, 19 Jan 2024 03:21:15 +0800 Subject: [PATCH] ejs templating --- consumerWebsite/database/model/apiKeyModel.js | 45 ++- consumerWebsite/middleware/authChecker.js | 0 consumerWebsite/modules/app.js | 20 +- consumerWebsite/public/404.html | 213 --------------- consumerWebsite/public/index.html | 256 ------------------ .../public/js/{jquery.js => app.js} | 3 +- consumerWebsite/public/js/contact.js | 44 +++ consumerWebsite/public/news.html | 233 ---------------- consumerWebsite/routes/render.js | 60 ++++ consumerWebsite/views/404.ejs | 37 +++ consumerWebsite/views/bot.ejs | 88 ++++++ consumerWebsite/views/index.ejs | 124 +++++++++ consumerWebsite/views/news.ejs | 112 ++++++++ consumerWebsite/views/top.ejs | 124 +++++++++ webserver/database/model/apiKeyModel.js | 2 +- 15 files changed, 648 insertions(+), 713 deletions(-) create mode 100644 consumerWebsite/middleware/authChecker.js delete mode 100644 consumerWebsite/public/404.html delete mode 100644 consumerWebsite/public/index.html rename consumerWebsite/public/js/{jquery.js => app.js} (99%) create mode 100644 consumerWebsite/public/js/contact.js delete mode 100644 consumerWebsite/public/news.html create mode 100644 consumerWebsite/routes/render.js create mode 100644 consumerWebsite/views/404.ejs create mode 100644 consumerWebsite/views/bot.ejs create mode 100644 consumerWebsite/views/index.ejs create mode 100644 consumerWebsite/views/news.ejs create mode 100644 consumerWebsite/views/top.ejs diff --git a/consumerWebsite/database/model/apiKeyModel.js b/consumerWebsite/database/model/apiKeyModel.js index 03bcb95..55e096b 100644 --- a/consumerWebsite/database/model/apiKeyModel.js +++ b/consumerWebsite/database/model/apiKeyModel.js @@ -45,7 +45,7 @@ const apikeyModel = sequelize.define( validate: { notEmpty: true, len: [1, 255], - isIn: [["canRead", "canWrite"]], + isIn: [["canRead", "canWrite" , "auto-generated"]], }, }, createdAt: { @@ -63,3 +63,46 @@ const apikeyModel = sequelize.define( ); module.exports = { apikeyModel }; + + +/* + class AuthToken extends Model { + check(){ + // check expires_on date + return this.is_valid; + } + } + AuthToken.init({ + token:{ + type: DataTypes.UUID, + defaultValue: DataTypes.UUIDV4, + allowNull: false, + primaryKey: true + }, + expires_on: { + type: DataTypes.DATE, + allowNull: true, + validate:{ + isDate:true + } + }, + username: { + type: DataTypes.STRING, + ldapModel: 'User', + allowNull: false, + validate:{ + notNull: true, + }, + }, + is_valid: { + type: DataTypes.BOOLEAN, + defaultValue: true + } + }, { + sequelize, + modelName: 'AuthToken', + }); + + + +*/ \ No newline at end of file diff --git a/consumerWebsite/middleware/authChecker.js b/consumerWebsite/middleware/authChecker.js new file mode 100644 index 0000000..e69de29 diff --git a/consumerWebsite/modules/app.js b/consumerWebsite/modules/app.js index 680beba..069240b 100644 --- a/consumerWebsite/modules/app.js +++ b/consumerWebsite/modules/app.js @@ -1,20 +1,23 @@ const express = require("express"); -const helmet = require("helmet"); const path = require("path"); const app = express(); -const port = 80; +const port = 3000; +const ejs = require("ejs"); -const bodyParser = require('body-parser'); // Middleware +const bodyParser = require("body-parser"); // Middleware app.use(bodyParser.urlencoded({ extended: false })); -app.use(helmet()); -//disable x-powered-by header for security reasons -app.disable("x-powered-by"); + app.use(express.json()); app.set("json spaces", 2); -//public folder with path to static files +// Set up the templating engine to build HTML for the front end. +app.set("views", path.join(__dirname, "../views")); +app.set("view engine", "ejs"); + +// Have express server static content( images, CSS, browser JS) from the public +// local folder. app.use(express.static(path.join(__dirname, "../public"))); //middleware logic ( called by next() ) @@ -23,6 +26,9 @@ app.use(express.static(path.join(__dirname, "../public"))); //route logic app.use("/api/v0", require("../routes/api_routes")); //consumerWebsite\routes\api_routes.js +//render logic +app.use("/", require("../routes/render")); //consumerWebsite\routes\render.js + // Catch 404 and forward to error handler. If none of the above routes are // used, this is what will be called. app.use(function (req, res, next) { diff --git a/consumerWebsite/public/404.html b/consumerWebsite/public/404.html deleted file mode 100644 index c78fd96..0000000 --- a/consumerWebsite/public/404.html +++ /dev/null @@ -1,213 +0,0 @@ - - - - - - - - N & LW Lawn Care - Landscaping Bootstrap4 HTML5 Responsive Template - - - - - - - - - - - - -
-
- -

404 - Page Not Found -

-
-
- - -
- - -
-

Oops! That page can’t be found.

-
- -
-

We can’t find the page your are looking for. You can check out our Homepage.

- Back To Homepage -
- - -
- - - - - - - - - - diff --git a/consumerWebsite/public/index.html b/consumerWebsite/public/index.html deleted file mode 100644 index 38274fa..0000000 --- a/consumerWebsite/public/index.html +++ /dev/null @@ -1,256 +0,0 @@ - - - - - - - - - EcoSaver - - - - - - - - - - - -
- -
- -
-
-

Services

- -
-
-
-

Humidity

-
-

75%

-
- -
-
-
-
-

Air Quality Index

-
-

18 PSI

-
- -
-
-
-
-

Temperature

-
-

30°

-
- -
-
-
- -
- -
-
-
- EcoSaver - Your Air Quality Index Source - - - - -
-

Welcome to EcoSaver - Your Air Quality Index Source

-

We prioritize your well-being by providing up-to-date information on air quality indexes.

-
- -
-

Our Approach: Smart and Informative

-

We believe in offering precise and comprehensive data to empower your decisions for a better - quality of life.

-
    -
  • Presenting real-time air quality data in a user-friendly format.
  • -
  • Equipping you with insights into the impact of air quality on health and the environment. -
  • -
  • Empowering communities with knowledge to make informed choices for a sustainable future. -
  • -
-
-
-
- -
-
-
-
-
- - - - - - - - - - \ No newline at end of file diff --git a/consumerWebsite/public/js/jquery.js b/consumerWebsite/public/js/app.js similarity index 99% rename from consumerWebsite/public/js/jquery.js rename to consumerWebsite/public/js/app.js index 78db376..3fb3560 100644 --- a/consumerWebsite/public/js/jquery.js +++ b/consumerWebsite/public/js/app.js @@ -1,6 +1,6 @@ var app = {}; -/* + app.api = (function(app){ var baseURL = '/api/v0/' @@ -85,7 +85,6 @@ app.api = (function(app){ return {post: post, get: get, put: put, delete: remove} })(app) -*/ app.auth = (function(app) { var user = {} diff --git a/consumerWebsite/public/js/contact.js b/consumerWebsite/public/js/contact.js new file mode 100644 index 0000000..98a07a6 --- /dev/null +++ b/consumerWebsite/public/js/contact.js @@ -0,0 +1,44 @@ +require('dotenv').config({ path: path.resolve(__dirname, '../../../.env') }) + + +document.addEventListener('DOMContentLoaded', () => { + const form = document.getElementById('form'); + + // Set the new value for the access_key input field + form.querySelector('input[name="access_key"]').value = process.env.emailKey; + + form.addEventListener('submit', async (event) => { + event.preventDefault(); // Prevent default form submission + + // Create a FormData object to include the key + const formData = new FormData(form); + + // Submit the form using fetch API + try { + const response = await fetch('https://api.web3forms.com/submit', { + method: 'POST', + body: formData + }); + + const result = await response.json(); + + // Handle the API response + //console.log(result); + + if (result.success) { + // Form submitted successfully, display notification + alert('Form submitted successfully!'); + location.reload() + // You can replace the alert with your custom notification logic + } else { + // Form submission failed, display error notification + alert('Form submission failed. Please try again.'); + // You can replace the alert with your custom error notification logic + } + + } catch (error) { + //console.error('Error:', error); + } + }); +}); + diff --git a/consumerWebsite/public/news.html b/consumerWebsite/public/news.html deleted file mode 100644 index 7d72ac8..0000000 --- a/consumerWebsite/public/news.html +++ /dev/null @@ -1,233 +0,0 @@ - - - - - - - - - N & LW Lawn Care - Landscaping Bootstrap4 HTML5 Responsive Template - - - - - - - - - - - - - -
-
- -

News - -

-
-
- - -
- -
- -
-
-
-
- Card image Blog -
-

Singapore's air quality hits unhealthy range, 'slightly hazy' conditions forecast for Saturday

-

he National Environment Agency said there has been a "significant increase" in the number of hotspots in Sumatra.

- Read More → -
- -
- -
- Card image Blog -
-

Singapore Government Agencies Stand Ready To Mitigate Impact Of Haze

-

As of 29 September 2023, 3pm, the 24-hr Pollutant Standards Index (PSI) is 81 (Moderate range) in the East region of Singapore. Accordingly, the 28 public agencies that make up the Government’s Haze Task Force (HTF), are ready to roll out their respective haze action plans should the air quality deteriorate into the Unhealthy range (24-hour PSI above 100).

- Read More → -
- -
- -
- Card image Blog -
-

High risk of severe transboundary haze in 2023, public advised to be prepared: Singapore institute

-

A latest report predicts a high risk of severe haze occurring in Southeast Asia, though not as severe as in 2015

- Read More → -
- -
- -
- - -
- -
- - - -
-
-
Search
-
-
- - - - -
-
-
-
-
-
- - - - - - - - - - - \ No newline at end of file diff --git a/consumerWebsite/routes/render.js b/consumerWebsite/routes/render.js new file mode 100644 index 0000000..356c63b --- /dev/null +++ b/consumerWebsite/routes/render.js @@ -0,0 +1,60 @@ +/* +'use strict'; + +var router = require('express').Router(); +const conf = require('../conf') + +const values ={ + title: conf.environment !== 'production' ? `` : '' +} + +router.get('/', async function(req, res, next) { + res.render('runner', {...values}); +}); + + +router.get('/topics', function(req, res, next) { + res.render('topics', {...values}); +}); + +router.get('/chat', function(req, res, next) { + res.render('chat', {...values}); +}); + +router.get('/login*', function(req, res, next) { + res.render('login', {redirect: req.query.redirect, ...values}); +}); + +router.get('/runner', function(req, res, next) { + res.render('runner', {...values}); +}); + +router.get('/worker', function(req, res, next) { + res.render('worker', {...values}); +}); + +module.exports = router; + +*/ + +'use strict'; + +var router = require('express').Router(); + +//landing page of index +router.get('/', function(req, res, next) { + res.render('index'); +}); + +//news page +router.get('/news', function(req, res, next) { + res.render('news'); +}); + +//404 page +router.get('*', function(req, res, next) { + res.render('404'); +}); + + +module.exports = router; diff --git a/consumerWebsite/views/404.ejs b/consumerWebsite/views/404.ejs new file mode 100644 index 0000000..ccb157b --- /dev/null +++ b/consumerWebsite/views/404.ejs @@ -0,0 +1,37 @@ +<%- include('top') %> + + +
+
+ +

404 + Page Not Found +

+
+
+ + +
+ + +
+

Oops! That page can’t be found.

+
+ +
+

We can’t find the page your are looking for. You can check out our Homepage.

+ Back To Homepage +
+ + +
+ + +<%- include('bot') %> \ No newline at end of file diff --git a/consumerWebsite/views/bot.ejs b/consumerWebsite/views/bot.ejs new file mode 100644 index 0000000..898fd63 --- /dev/null +++ b/consumerWebsite/views/bot.ejs @@ -0,0 +1,88 @@ + + + + + + + + diff --git a/consumerWebsite/views/index.ejs b/consumerWebsite/views/index.ejs new file mode 100644 index 0000000..f1a31a7 --- /dev/null +++ b/consumerWebsite/views/index.ejs @@ -0,0 +1,124 @@ +<%- include('top') %> + + +
+ +
+ +
+
+

Services

+ +
+
+
+

Humidity

+
+

70% - 75%

+
+ +
+
+
+
+

Air Quality Index

+
+

15 - 18 PSI

+
+ +
+
+
+
+

Temperature

+
+

30° - 37°

+
+ +
+
+
+ +
+ +
+
+
+ EcoSaver - Your Air Quality Index Source + + + + + +
+

Welcome to EcoSaver - Your Air Quality Index Source

+

We prioritize your well-being by providing up-to-date information on air quality indexes.

+
+ +
+

Our Approach: Smart and Informative

+

We believe in offering precise and comprehensive data to empower your decisions for a better + quality of life.

+
    +
  • Presenting real-time air quality data in a user-friendly format.
  • +
  • Equipping you with insights into the impact of air quality on health and the environment. +
  • +
  • Empowering communities with knowledge to make informed choices for a sustainable future. +
  • +
+
+
+
+ +
+
+
+
+
+ +<%- include('bot') %> diff --git a/consumerWebsite/views/news.ejs b/consumerWebsite/views/news.ejs new file mode 100644 index 0000000..97f27b9 --- /dev/null +++ b/consumerWebsite/views/news.ejs @@ -0,0 +1,112 @@ +<%- include('top') %> + + + +
+
+ +

News + +

+
+
+ + +
+ +
+ +
+
+
+
+ Card image Blog +
+

Singapore's air quality hits unhealthy range, 'slightly hazy' conditions + forecast for Saturday

+

he National Environment Agency said there has been a "significant increase" + in the number of hotspots in Sumatra.

+ Read More → +
+ +
+ +
+ Card image Blog +
+

Singapore Government Agencies Stand Ready To Mitigate Impact Of Haze

+

As of 29 September 2023, 3pm, the 24-hr Pollutant Standards Index (PSI) is + 81 (Moderate range) in the East region of Singapore. Accordingly, the 28 public agencies + that make up the Government’s Haze Task Force (HTF), are ready to roll out their respective + haze action plans should the air quality deteriorate into the Unhealthy range (24-hour PSI + above 100).

+ Read More → +
+ +
+ +
+ Card image Blog +
+

High risk of severe transboundary haze in 2023, public advised to be + prepared: Singapore institute

+

A latest report predicts a high risk of severe haze occurring in Southeast + Asia, though not as severe as in 2015

+ Read More → +
+ +
+ +
+ + +
+ +
+ + + +
+
+
Search
+
+
+ + + + +
+
+
+
+
+
+ + +<%- include('bot') %> diff --git a/consumerWebsite/views/top.ejs b/consumerWebsite/views/top.ejs new file mode 100644 index 0000000..30f2ebf --- /dev/null +++ b/consumerWebsite/views/top.ejs @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/webserver/database/model/apiKeyModel.js b/webserver/database/model/apiKeyModel.js index 03bcb95..69e45d9 100644 --- a/webserver/database/model/apiKeyModel.js +++ b/webserver/database/model/apiKeyModel.js @@ -45,7 +45,7 @@ const apikeyModel = sequelize.define( validate: { notEmpty: true, len: [1, 255], - isIn: [["canRead", "canWrite"]], + isIn: [["canRead", "canWrite" , "auto-generated"]], }, }, createdAt: {