Merged feature contact into develop
commit
0c5cf8976f
|
@ -31,4 +31,8 @@ module.exports = {
|
|||
// Google maps API key
|
||||
googleMapsAPI: 'XXXXXXXXXXXXXXX_XXXXXXXXXXXXXXXXXXXXXXX'
|
||||
|
||||
// reCaptcha API key
|
||||
recaptchaSitekey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
|
||||
recaptchaSecret: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
|
||||
|
||||
};
|
||||
|
|
|
@ -34,7 +34,7 @@ module.exports = {
|
|||
return `<h1><a href="/" style="text-decoration:none;"><span style="color:#000;font-family:sans-serif;font-size:36px;font-weight:bold"><img src="${env.url}/static/img/icon/by/32.png" alt="+" style="margin-right:10px">Tracman</span></a></h1>${text}<p style="font-size:8px;">Do not reply to this email. For information about why you recieved this email, see our <a href="${env.url}/privacy#email">privacy policy</a>. </p>`;
|
||||
},
|
||||
|
||||
from: `"Tracman" <NoReply@tracman.org>`,
|
||||
noReply: `"Tracman" <NoReply@tracman.org>`,
|
||||
|
||||
to: (user)=>{
|
||||
return `"${user.name}" <${user.email}>`;
|
||||
|
|
|
@ -80,7 +80,7 @@ module.exports = (app, passport) => {
|
|||
|
||||
// Email the instructions to continue
|
||||
mail.send({
|
||||
from: mail.from,
|
||||
from: mail.noReply,
|
||||
to: `<${user.email}>`,
|
||||
subject: 'Complete your Tracman registration',
|
||||
text: mail.text(`Welcome to Tracman! \n\nTo complete your registration, follow this link and set your password:\n${env.url}/settings/password/${token}\n\nThis link will expire at ${expirationTimeString}. `),
|
||||
|
@ -238,7 +238,7 @@ module.exports = (app, passport) => {
|
|||
|
||||
// Email reset link
|
||||
mail.send({
|
||||
from: mail.from,
|
||||
from: mail.noReply,
|
||||
to: mail.to(user),
|
||||
subject: 'Reset your Tracman password',
|
||||
text: mail.text(`Hi, \n\nDid you request to reset your Tracman password? If so, follow this link to do so:\n${env.url}/settings/password/${token}\n\nIf you didn't initiate this request, just ignore this email. `),
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
const mw = require('../middleware.js'),
|
||||
env = require('../env/env.js'),
|
||||
mail = require('../mail.js'),
|
||||
router = require('express').Router(),
|
||||
request = require('request'),
|
||||
slug = require('slug'),
|
||||
xss = require('xss'),
|
||||
User = require('../models.js').user;
|
||||
User = require('../models.js').user;
|
||||
|
||||
module.exports = router
|
||||
|
||||
|
@ -18,6 +21,68 @@ module.exports = router
|
|||
res.render('help');
|
||||
})
|
||||
|
||||
// Contact
|
||||
.get('/contact', (req,res)=>{
|
||||
res.render('contact',{
|
||||
sitekey: env.recaptchaSitekey
|
||||
});
|
||||
})
|
||||
.post('/contact', (req,res,next)=>{
|
||||
|
||||
// Confirm captcha
|
||||
request.post( 'https://www.google.com/recaptcha/api/siteverify', {form:{
|
||||
secret: env.recaptchaSecret,
|
||||
response: req.body['g-recaptcha-response'],
|
||||
remoteip: req.ip
|
||||
}}, (err, response, body)=>{
|
||||
|
||||
// Check for errors
|
||||
if (err){
|
||||
mw.throwErr(err,req);
|
||||
res.redirect('/contact');
|
||||
}
|
||||
if (response.statusCode!==200) {
|
||||
let err = new Error('Bad response from reCaptcha service');
|
||||
mw.throwErr(err,req);
|
||||
res.redirect('/contact');
|
||||
}
|
||||
else {
|
||||
|
||||
// Captcha succeeded
|
||||
if (JSON.parse(body).success){
|
||||
mail.send({
|
||||
from: `${req.body.name} <${req.body.email}>`,
|
||||
to: `Tracman Contact <contact@tracman.org>`,
|
||||
subject: req.body.subject||'A message',
|
||||
text: req.body.message
|
||||
})
|
||||
.then(()=>{
|
||||
req.flash('success', `Your message has been sent. `);
|
||||
res.redirect(req.session.next || '/');
|
||||
})
|
||||
.catch((err)=>{
|
||||
mw.throwErr(err,req);
|
||||
res.redirect('/contact');
|
||||
});
|
||||
}
|
||||
|
||||
// Captcha failed
|
||||
else {
|
||||
let err = new Error('Failed reCaptcha');
|
||||
mw.throwErr(err,req);
|
||||
res.redirect('/contact');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
//TODO: Check req.body.g-recaptcha-response
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
// Terms of Service and Privacy Policy
|
||||
.get('/terms', (req,res)=>{
|
||||
res.render('terms');
|
||||
|
|
|
@ -71,7 +71,7 @@ router.route('/')
|
|||
debug(`Mailing new email token to ${req.body.email}...`);
|
||||
mail.send({
|
||||
to: `"${req.user.name}" <${req.body.email}>`,
|
||||
from: mail.from,
|
||||
from: mail.noReply,
|
||||
subject: 'Confirm your new email address for Tracman',
|
||||
text: mail.text(`A request has been made to change your Tracman email address. If you did not initiate this request, please disregard it. \n\nTo confirm your email, follow this link:\n${env.url}/settings/email/${token}. `),
|
||||
html: mail.html(`<p>A request has been made to change your Tracman email address. If you did not initiate this request, please disregard it. </p><p>To confirm your email, follow this link:<br><a href="${env.url}/settings/email/${token}">${env.url}/settings/email/${token}</a>. </p>`)
|
||||
|
@ -241,7 +241,7 @@ router.route('/password')
|
|||
// Confirm password change request by email.
|
||||
mail.send({
|
||||
to: mail.to(req.user),
|
||||
from: mail.from,
|
||||
from: mail.noReply,
|
||||
subject: 'Request to change your Tracman password',
|
||||
text: mail.text(`A request has been made to change your tracman password. If you did not initiate this request, please contact support at keith@tracman.org. \n\nTo change your password, follow this link:\n${env.url}/settings/password/${token}. \n\nThis request will expire at ${expirationTimeString}. `),
|
||||
html: mail.html(`<p>A request has been made to change your tracman password. If you did not initiate this request, please contact support at <a href="mailto:keith@tracman.org">keith@tracman.org</a>. </p><p>To change your password, follow this link:<br><a href="${env.url}/settings/password/${token}">${env.url}/settings/password/${token}</a>. </p><p>This request will expire at ${expirationTimeString}. </p>`)
|
||||
|
|
|
@ -10,7 +10,7 @@ router
|
|||
.get('/mail', (req,res,next)=>{
|
||||
mail.send({
|
||||
to: `"Keith Irwin" <hypergeek14@gmail.com>`,
|
||||
from: mail.from,
|
||||
from: mail.noReply,
|
||||
subject: 'Test email',
|
||||
text: mail.text("Looks like everything's working! "),
|
||||
html: mail.html("<p>Looks like everything's working! </p>")
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
"passport-local": "^1.0.0",
|
||||
"passport-twitter": "^1.0.4",
|
||||
"passport-twitter-token": "^1.3.0",
|
||||
"request": "^2.81.0",
|
||||
"slug": "^0.9.1",
|
||||
"socket.io": "^1.4.4",
|
||||
"xss": "^0.3.3"
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
input, textarea {
|
||||
margin-bottom: 3%;
|
||||
}
|
||||
|
||||
#subject, #message {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width:600px) {
|
||||
#name, #email {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
@media (min-width:600px) {
|
||||
#name, #email {
|
||||
min-width: 45%;
|
||||
}
|
||||
#name {
|
||||
float: left;
|
||||
}
|
||||
#email {
|
||||
float: right;
|
||||
}
|
||||
}
|
||||
|
||||
button.btn {
|
||||
display: block;
|
||||
margin: auto;
|
||||
min-width: 60%;
|
||||
min-height: 12vh;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
{% extends 'templates/base.html' %}
|
||||
{% block title %}{{super()}} | Contact{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
{{super()}}
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/.form.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/.contact.min.css">
|
||||
<script src='https://www.google.com/recaptcha/api.js'></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<section class='container'>
|
||||
|
||||
<h1>Contact</h1>
|
||||
|
||||
<form id='contact-form' role="form" method="POST">
|
||||
|
||||
<input name="subject" id='subject' type="text" maxlength="160" value="{{subject}}" placeholder="Subject">
|
||||
<textarea name="message" id='message' rows="10" maxlength="5000" placeholder="Message" required>{{message}}</textarea>
|
||||
|
||||
<input name="name" id='name' type="text" maxlength="160" value="{{name}}" placeholder="Name">
|
||||
<input name="email" id='email' type="email" maxlength="160" value="{{email}}" placeholder="Email" required>
|
||||
|
||||
<button class='g-recaptcha main btn' data-sitekey="{{sitekey}}" data-callback="onSubmit">Submit</button>
|
||||
</form>
|
||||
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
{% block javascript %}
|
||||
{{super()}}
|
||||
<script type="application/javascript">
|
||||
/* global $ */
|
||||
function onSubmit() {
|
||||
$('#contact-form').submit();
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
|
@ -13,6 +13,7 @@
|
|||
<!-- Navigation -->
|
||||
<nav id='navigation'><ul>
|
||||
<li><a href="/">About</a></li>
|
||||
<li><a href="/contact">Contact</a></li>
|
||||
{% if user %}
|
||||
<li><a href="/map">Map</a></li>
|
||||
<li><a href="/settings">Settings</a></li>
|
||||
|
|
Loading…
Reference in New Issue