Merge branch 'score-email' into 'develop'

Merge score-email into develop

See merge request sudoer777/cvcs-score-tracker!3
main
Ethan Reece 2021-10-04 17:22:59 +00:00
commit f2a8952eb2
10 changed files with 1802 additions and 161 deletions

8
.env.example 100644
View File

@ -0,0 +1,8 @@
NODE_ENV=development
MAIL_FROM=fromaddress@example.com
MAIL_HOST=smtp.smtphost.net
MAIL_PORT=465
MAIL_SECURE=true
MAIL_USER=username
MAIL_PASS=password

17
.vscode/launch.json vendored 100644
View File

@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/bin/www"
}
]
}

2
app.js
View File

@ -6,6 +6,7 @@ var logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var submitRouter = require('./routes/submit')
var app = express();
@ -21,6 +22,7 @@ app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/submit', submitRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {

33
mail/mail.js 100644
View File

@ -0,0 +1,33 @@
const app = require('../app');
const nodemailer = require('nodemailer');
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
module.exports = {
send: function (recipient, subject, message) {
send(recipient, subject, message);
}
};
var send = function (recipient, subject, message) {
transporter.sendMail({
to: recipient, // list of receivers
subject: subject, // Subject line
html: message, // html body
});
}
let transporter = nodemailer.createTransport({
host: process.env.MAIL_HOST,
port: process.env.MAIL_PORT,
secure: process.env.MAIL_SECURE,
auth: {
user: process.env.MAIL_USER,
pass: process.env.MAIL_PASS,
},
}, {
from: process.env.MAIL_FROM
});

1829
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -9,9 +9,11 @@
"dependencies": {
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"dotenv": "^10.0.0",
"express": "~4.16.0",
"http-errors": "~1.6.2",
"morgan": "~1.9.0",
"nodemailer": "^6.6.5",
"pug": "2.0.0-beta11"
},
"devDependencies": {

View File

@ -6,3 +6,8 @@ body {
a {
color: #00B7FF;
}
form {
display: flex;
flex-direction: column;
}

38
routes/submit.js 100644
View File

@ -0,0 +1,38 @@
var express = require('express');
var mail = require('../mail/mail');
var router = express.Router();
/* GET submit page. */
router.get('/', function(req, res, next) {
res.send('Nothing to send');
});
/* POST submit page. */
router.post('/', function(req, res, next) {
let sport = req.body.sport;
let gender = req.body.gender;
let division = req.body.division;
let home = req.body['home-team'];
let homeScore = req.body['home-team-score'];
let visiting = req.body['visiting-team'];
let visitingScore = req.body['visiting-team-score'];
let submitter = req.body['submitter'];
let recipient = req.body['email'];
let message = prepMailBody(sport, gender, division, home, homeScore, visiting, visitingScore, submitter);
mail.send(recipient, "Score Report", message);
res.send('Score sent');
});
var prepMailBody = function(sport, gender, division, home, homeScore, visiting, visitingScore, submitter) {
return(
"Score report from <b>" + submitter + "</b><br><br>" +
"<b>Sport:</b><br>" + sport + " - " + gender + " - " + division + "<br><br>" +
"<b>Home team:</b><br>" + home + " - " + homeScore + "<br><br>" +
"<b>Visiting team:</b><br>" + visiting + " - " + visitingScore + "<br><br>");
};
module.exports = router;

View File

@ -1,5 +1,30 @@
extends layout
block content
h1= title
p Welcome to #{title}
form(action='/submit', method='POST')
span
label Sport
select(name="sport")
option(value="Football" selected) Football
select(name="gender")
option(value="Male" selected) Male
option(value="Female") Female
select(name="division")
option(value="Varsity") Varsity
option(value="JV-A") JV-A
option(value="JV-B") JV-B
span
label Home Team
input(type="text", name="home-team")
input(type="number", name="home-team-score", value="0")
span
label Visiting Team
input(type="text", name="visiting-team")
input(type="number", name="visiting-team-score", value="0")
span
label Submitter
input(type="text", name="submitter")
span
label Send info to
input(type="email", name="email", placeholder="email@example.com")
button(type="submit") Submit

0
views/submit.pug 100644
View File