forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.js
78 lines (69 loc) · 2.08 KB
/
contact.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var nodemailer = require('nodemailer'),
debug = require('debug')('freecc:cntr:contact'),
secrets = require('../config/secrets');
var transporter = nodemailer.createTransport({
service: 'Mandrill',
auth: {
user: secrets.mandrill.user,
pass: secrets.mandrill.password
}
});
module.exports = {
/**
* GET /contact
* Contact form page.
*/
getNonprofitsForm: function(req, res) {
res.render('contact/nonprofits', {
title: 'Free Code Work for Nonprofits Project Submission Page'
});
},
/**
* POST /contact
* Send a contact form via Nodemailer.
*/
postNonprofitsForm: function(req, res) {
var mailOptions = {
to: '[email protected]',
name: req.body.name,
from: req.body.email,
subject: 'CodeNonprofit Project Idea from ' + req.body.name,
text: req.body.message
};
transporter.sendMail(mailOptions, function (err) {
if (err) {
req.flash('errors', {msg: err.message});
return res.redirect('/nonprofits');
}
req.flash('success', {msg: 'Email has been sent successfully!'});
res.redirect('/nonprofits');
});
},
getDoneWithFirst100Hours: function(req, res) {
if (req.user.points >= 53) {
res.render('contact/done-with-first-100-hours', {
title: 'Congratulations on finishing the first 100 hours of Free Code Camp!'
});
} else {
req.flash('errors', {msg: 'Hm... have you finished all the challenges?'});
res.redirect('/');
}
},
postDoneWithFirst100Hours: function(req, res) {
var mailOptions = {
to: '[email protected]',
name: 'Completionist',
from: req.body.email,
subject: 'Camper at ' + req.body.email + ' has completed the first 100 hours',
text: ''
};
transporter.sendMail(mailOptions, function (err) {
if (err) {
req.flash('errors', {msg: err.message});
return res.redirect('/done-with-first-100-hours');
}
req.flash('success', {msg: 'Email has been sent successfully!'});
res.redirect('/nonprofit-project-instructions');
});
}
};