mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-04-21 16:37:23 -05:00
added contact page with functionality
This commit is contained in:
parent
e649a165b2
commit
affb7fc36a
|
|
@ -5,6 +5,11 @@
|
|||
"database": {
|
||||
"url": "mongodb://localhost:27017/pretendo_website"
|
||||
},
|
||||
"contactWebhook": {
|
||||
"port": 443,
|
||||
"host": "host.com",
|
||||
"path": "/webhookurl"
|
||||
},
|
||||
"secrets": {
|
||||
"session": "session secret here"
|
||||
}
|
||||
|
|
|
|||
74
routes/contact.js
Normal file
74
routes/contact.js
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
|
||||
contact.js -
|
||||
file for handling routes regarding contact
|
||||
|
||||
*/
|
||||
|
||||
// imports
|
||||
const router = require('express').Router();
|
||||
const common = require('../helpers/common');
|
||||
const config = require('../config.json');
|
||||
const https = require('https');
|
||||
|
||||
// display contact page
|
||||
router.get('/contact', (req, res) => {
|
||||
res.render('contact');
|
||||
});
|
||||
|
||||
/*
|
||||
* /api/v1/sendmessage
|
||||
*
|
||||
* registers a new admin user
|
||||
*
|
||||
* post {
|
||||
* email - email of sender
|
||||
* subject - subject of message
|
||||
* message - actual message
|
||||
* }
|
||||
* return {
|
||||
* code: httpcode
|
||||
* success: boolean - true if sending was successull
|
||||
* errors: Strings[messages]
|
||||
* }
|
||||
*/
|
||||
router.post('/api/v1/sendmessage', function (req, res) {
|
||||
if (!req.body) return common.sendApiGenericError(res);
|
||||
|
||||
const { email, subject, message } = req.body;
|
||||
if (email && subject && message && message.length < 2000) {
|
||||
console.log('checks passed');
|
||||
const postData = JSON.stringify({
|
||||
content: 'email: ' + email + ' \n subject: ' + subject + ' \n\n' + message
|
||||
});
|
||||
|
||||
const request = https.request({
|
||||
hostname: config.contactWebhook.host,
|
||||
port: config.contactWebhook.port,
|
||||
path: config.contactWebhook.path,
|
||||
method : 'POST',
|
||||
headers : {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Content-Length': postData.length
|
||||
}
|
||||
}, () => {
|
||||
common.sendApiReturn(res, {});
|
||||
});
|
||||
|
||||
request.on('error', (e) => {
|
||||
common.sendApiGenericError(res);
|
||||
console.log('request errored' + e);
|
||||
});
|
||||
|
||||
request.write(postData);
|
||||
request.end();
|
||||
} else {
|
||||
// TODO give more detailed response
|
||||
return common.sendApiGenericError(res);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// export router
|
||||
module.exports = router;
|
||||
|
|
@ -14,10 +14,5 @@ router.get('/', (req, res) => {
|
|||
res.render('home');
|
||||
});
|
||||
|
||||
// display contact page
|
||||
router.get('/contact', (req, res) => {
|
||||
res.render('contact');
|
||||
});
|
||||
|
||||
// export the router
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ const locations = {
|
|||
home: require('./routes/home'),
|
||||
posts: require('./routes/blog'),
|
||||
admin: require('./routes/admin'),
|
||||
contact: require('./routes/contact'),
|
||||
progress: require('./routes/progress')
|
||||
};
|
||||
|
||||
|
|
@ -67,6 +68,7 @@ const locations = {
|
|||
app.use('/assets', express.static('assets'));
|
||||
// page map
|
||||
app.use('/', locations.home);
|
||||
app.use('/', locations.contact);
|
||||
app.use('/', locations.posts);
|
||||
app.use('/', locations.admin);
|
||||
app.use('/', locations.progress);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,16 @@
|
|||
<body>
|
||||
{{> navbar }}
|
||||
|
||||
<h1>contact form here</h1>
|
||||
<h1>contact form</h1>
|
||||
<form action="/api/v1/sendmessage" method="POST">
|
||||
<p>content</p>
|
||||
<textarea name="message" cols="30" rows="10"></textarea>
|
||||
<p>subject</p>
|
||||
<input type="text" name="subject">
|
||||
<p>email</p>
|
||||
<input type="text" name="email">
|
||||
<button>send message</button>
|
||||
</form>
|
||||
|
||||
{{> footer }}
|
||||
</body>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user