Merge branch 'develop' into 'testing'

Add basic prototype to testing

See merge request sudoer777/cvcs-score-tracker!4
main
Ethan Reece 2021-10-04 20:07:17 +00:00
commit 250bc3eb59
13 changed files with 1853 additions and 163 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' || process.env.NODE_ENV !== 'testing') {
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

@ -1,8 +1,9 @@
body {
padding: 50px;
padding: 1em;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}
a {
color: #00B7FF;
}

View File

@ -0,0 +1,41 @@
h1 {
text-align: center;
}
form {
display: flex;
flex-direction: column;
max-width: 20em;
margin-left: auto;
margin-right: auto;
}
span {
display: flex;
flex-direction: column;
}
#sport-dropdown {
width: 100%;
}
.form-section {
margin-bottom: 0.75em;
}
.form-section-input {
flex-direction: row;
}
input {
width: 100%;
}
.score-input{
width: 35%;
}
button {
margin-top: 1.5em;
}

View File

@ -3,7 +3,7 @@ var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
res.render('index', { title: 'Submit Score' });
});
module.exports = router;

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,40 @@
extends layout
block stylesheets
link(rel='stylesheet', href='/stylesheets/submit.css')
block content
h1= title
p Welcome to #{title}
h1 Submit Score
form(action='/submit', method='POST')
span(class='form-section')
label Sport
span(class='form-section-input')
select#sport-dropdown(name="sport")
option(value="Football" selected) Football
select#gender-dropdown(name="gender")
option(value="Male" selected) Male
option(value="Female") Female
select#division-dropdown(name="division")
option(value="Varsity") Varsity
option(value="JV-A") JV-A
option(value="JV-B") JV-B
span(class='form-section')
label Home Team
span(class='form-section-input')
input(type="text", name="home-team")
input(class="score-input", type="number", name="home-team-score", value="0")
span(class='form-section')
label Visiting Team
span(class='form-section-input')
input(type="text", name="visiting-team")
input(class="score-input", type="number", name="visiting-team-score", value="0")
span(class='form-section')
label Submitter
span(class='form-section-input')
input(type="text", name="submitter")
span(class='form-section')
label Send info to
span(class='form-section-input')
input(type="email", name="email", placeholder="email@example.com")
span(class='form-section')
button(type="submit") Submit

View File

@ -2,6 +2,8 @@ doctype html
html
head
title= title
meta(name='viewport', content='width=device-width, initial-scale=1')
link(rel='stylesheet', href='/stylesheets/style.css')
block stylesheets
body
block content

0
views/submit.pug 100644
View File