2016-04-07 13:00:51 -07:00
|
|
|
import request from 'request';
|
|
|
|
import constantStrings from '../utils/constantStrings.json';
|
|
|
|
import testimonials from '../resources/testimonials.json';
|
|
|
|
import secrets from '../../config/secrets';
|
2015-06-01 16:48:16 -07:00
|
|
|
|
2015-06-03 16:19:23 -07:00
|
|
|
module.exports = function(app) {
|
2016-04-07 13:00:51 -07:00
|
|
|
const router = app.loopback.Router();
|
|
|
|
const User = app.models.User;
|
2016-06-17 12:35:10 -07:00
|
|
|
const noLangRouter = app.loopback.Router();
|
|
|
|
noLangRouter.get('/api/github', githubCalls);
|
|
|
|
noLangRouter.get('/chat', chat);
|
|
|
|
noLangRouter.get('/twitch', twitch);
|
|
|
|
noLangRouter.get('/unsubscribe/:email', unsubscribeMonthly);
|
|
|
|
noLangRouter.get(
|
|
|
|
'/unsubscribe-notifications/:email',
|
|
|
|
unsubscribeNotifications
|
|
|
|
);
|
|
|
|
noLangRouter.get('/unsubscribe-quincy/:email', unsubscribeQuincy);
|
|
|
|
noLangRouter.get('/submit-cat-photo', submitCatPhoto);
|
|
|
|
noLangRouter.get(
|
|
|
|
'/the-fastest-web-page-on-the-internet',
|
|
|
|
theFastestWebPageOnTheInternet
|
|
|
|
);
|
|
|
|
noLangRouter.get('/shop/cancel-stickers', cancelStickers);
|
|
|
|
noLangRouter.get('/shop/confirm-stickers', confirmStickers);
|
|
|
|
|
|
|
|
router.get('/unsubscribed', unsubscribed);
|
2015-06-03 16:19:23 -07:00
|
|
|
router.get('/nonprofits', nonprofits);
|
|
|
|
router.get('/nonprofits-form', nonprofitsForm);
|
2016-06-17 12:35:10 -07:00
|
|
|
router.get('/pmi-acp-agile-project-managers', agileProjectManagers);
|
|
|
|
router.get('/pmi-acp-agile-project-managers-form', agileProjectManagersForm);
|
|
|
|
router.get('/coding-bootcamp-cost-calculator', bootcampCalculator);
|
2015-10-07 00:26:17 -07:00
|
|
|
router.get('/stories', showTestimonials);
|
2016-02-05 21:06:30 -08:00
|
|
|
router.get('/shop', showShop);
|
2015-11-03 17:39:02 -08:00
|
|
|
router.get('/all-stories', showAllTestimonials);
|
2016-01-13 15:37:00 -06:00
|
|
|
router.get('/terms', terms);
|
|
|
|
router.get('/privacy', privacy);
|
2016-02-19 17:36:03 -08:00
|
|
|
router.get('/how-nonprofit-projects-work', howNonprofitProjectsWork);
|
2016-07-28 00:12:32 -07:00
|
|
|
router.get(
|
|
|
|
'/software-resources-for-nonprofits',
|
|
|
|
softwareResourcesForNonprofits
|
|
|
|
);
|
2016-01-13 15:37:00 -06:00
|
|
|
router.get('/code-of-conduct', codeOfConduct);
|
2016-02-13 16:32:14 -08:00
|
|
|
router.get('/academic-honesty', academicHonesty);
|
2015-06-03 16:19:23 -07:00
|
|
|
|
2016-06-17 12:35:10 -07:00
|
|
|
app.use(noLangRouter);
|
|
|
|
app.use('/:lang', router);
|
2015-06-03 16:31:42 -07:00
|
|
|
|
2015-06-03 16:19:23 -07:00
|
|
|
function chat(req, res) {
|
2015-07-31 17:30:27 -07:00
|
|
|
res.redirect('https://gitter.im/FreeCodeCamp/FreeCodeCamp');
|
2015-06-15 21:44:19 -07:00
|
|
|
}
|
|
|
|
|
2016-01-13 15:37:00 -06:00
|
|
|
function terms(req, res) {
|
|
|
|
res.render('resources/terms-of-service', {
|
|
|
|
title: 'Terms of Service'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function privacy(req, res) {
|
|
|
|
res.render('resources/privacy', {
|
2016-02-13 21:26:59 -05:00
|
|
|
title: 'Privacy policy'
|
2016-01-13 15:37:00 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-19 17:36:03 -08:00
|
|
|
function howNonprofitProjectsWork(req, res) {
|
|
|
|
res.render('resources/how-nonprofit-projects-work', {
|
|
|
|
title: 'How our nonprofit projects work'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-28 00:12:32 -07:00
|
|
|
function softwareResourcesForNonprofits(req, res) {
|
|
|
|
res.render('resources/software-resources-for-nonprofits', {
|
|
|
|
title: 'Software Resources for Nonprofits'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-13 15:37:00 -06:00
|
|
|
function codeOfConduct(req, res) {
|
|
|
|
res.render('resources/code-of-conduct', {
|
|
|
|
title: 'Code of Conduct'
|
|
|
|
});
|
|
|
|
}
|
2016-01-09 02:30:12 -06:00
|
|
|
|
2016-02-13 16:32:14 -08:00
|
|
|
function academicHonesty(req, res) {
|
|
|
|
res.render('resources/academic-honesty', {
|
|
|
|
title: 'Academic Honesty policy'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-11-25 10:23:35 -06:00
|
|
|
function theFastestWebPageOnTheInternet(req, res) {
|
|
|
|
res.render('resources/the-fastest-web-page-on-the-internet', {
|
|
|
|
title: 'This is the fastest web page on the internet'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-10-07 00:26:17 -07:00
|
|
|
function showTestimonials(req, res) {
|
2015-10-06 21:28:00 -07:00
|
|
|
res.render('resources/stories', {
|
2015-11-03 21:51:16 -08:00
|
|
|
title: 'Testimonials from Happy Free Code Camp Students ' +
|
|
|
|
'who got Software Engineer Jobs',
|
2015-11-03 17:58:47 -08:00
|
|
|
stories: testimonials.slice(0, 72),
|
2015-11-03 17:39:02 -08:00
|
|
|
moreStories: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function showAllTestimonials(req, res) {
|
|
|
|
res.render('resources/stories', {
|
2015-11-03 21:51:16 -08:00
|
|
|
title: 'Testimonials from Happy Free Code Camp Students ' +
|
|
|
|
'who got Software Engineer Jobs',
|
2015-11-03 17:39:02 -08:00
|
|
|
stories: testimonials,
|
|
|
|
moreStories: false
|
2015-10-06 18:19:43 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-05 21:06:30 -08:00
|
|
|
function showShop(req, res) {
|
|
|
|
res.render('resources/shop', {
|
|
|
|
title: 'Support Free Code Camp by Buying t-shirts, ' +
|
|
|
|
'stickers, and other goodies'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-17 15:07:12 -08:00
|
|
|
function confirmStickers(req, res) {
|
2016-03-02 20:54:14 -08:00
|
|
|
req.flash('success', {
|
|
|
|
msg: 'Thank you for supporting our community! You should receive ' +
|
|
|
|
'your stickers in the mail soon!'
|
|
|
|
});
|
|
|
|
res.redirect('/shop');
|
2016-02-17 15:07:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function cancelStickers(req, res) {
|
2016-03-02 20:54:14 -08:00
|
|
|
req.flash('info', {
|
|
|
|
msg: 'You\'ve cancelled your purchase of our stickers. You can ' +
|
|
|
|
'support our community any time by buying some.'
|
|
|
|
});
|
2016-02-17 15:07:12 -08:00
|
|
|
res.redirect('/shop');
|
|
|
|
}
|
2015-08-13 17:20:52 -07:00
|
|
|
function submitCatPhoto(req, res) {
|
|
|
|
res.send('Submitted!');
|
|
|
|
}
|
|
|
|
|
2015-07-31 17:30:27 -07:00
|
|
|
function bootcampCalculator(req, res) {
|
|
|
|
res.render('resources/calculator', {
|
|
|
|
title: 'Coding Bootcamp Cost Calculator'
|
|
|
|
});
|
2015-06-20 18:40:43 -07:00
|
|
|
}
|
|
|
|
|
2015-06-03 16:19:23 -07:00
|
|
|
function nonprofits(req, res) {
|
|
|
|
res.render('resources/nonprofits', {
|
2015-10-31 02:59:09 -07:00
|
|
|
title: 'Your Nonprofit Can Get Pro Bono Code'
|
2015-06-03 16:19:23 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function nonprofitsForm(req, res) {
|
|
|
|
res.render('resources/nonprofits-form', {
|
|
|
|
title: 'Nonprofit Projects Proposal Form'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function agileProjectManagers(req, res) {
|
|
|
|
res.render('resources/pmi-acp-agile-project-managers', {
|
|
|
|
title: 'Get Agile Project Management Experience for the PMI-ACP'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function agileProjectManagersForm(req, res) {
|
|
|
|
res.render('resources/pmi-acp-agile-project-managers-form', {
|
|
|
|
title: 'Agile Project Management Program Application Form'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function twitch(req, res) {
|
2016-03-06 06:20:34 +07:00
|
|
|
res.redirect('https://twitch.tv/freecodecamp');
|
2015-06-03 16:19:23 -07:00
|
|
|
}
|
|
|
|
|
2016-03-14 23:57:04 -07:00
|
|
|
function unsubscribeMonthly(req, res, next) {
|
2016-03-15 11:22:54 -07:00
|
|
|
req.checkParams('email', 'Must send a valid email').isEmail();
|
|
|
|
return User.findOne({ where: { email: req.params.email } }, (err, user) => {
|
|
|
|
if (err) { return next(err); }
|
2016-03-21 22:14:48 +00:00
|
|
|
if (!user) {
|
|
|
|
req.flash('info', {
|
|
|
|
msg: 'Email address not found. ' +
|
|
|
|
'Please update your Email preferences from your profile.'
|
|
|
|
});
|
|
|
|
return res.redirect('/map');
|
|
|
|
}
|
2016-04-15 21:38:03 +08:00
|
|
|
return user.updateAttributes({
|
2016-04-15 23:06:03 +08:00
|
|
|
sendMonthlyEmail: false,
|
|
|
|
sendQuincyEmail: false,
|
|
|
|
sendNotificationEmail: false
|
2016-04-15 21:38:03 +08:00
|
|
|
}, (err) => {
|
2016-03-02 20:54:14 -08:00
|
|
|
if (err) { return next(err); }
|
2016-03-15 11:22:54 -07:00
|
|
|
req.flash('info', {
|
|
|
|
msg: 'We\'ve successfully updated your Email preferences.'
|
|
|
|
});
|
|
|
|
return res.redirect('/unsubscribed');
|
2016-03-14 23:57:04 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function unsubscribeNotifications(req, res, next) {
|
2016-03-15 11:22:54 -07:00
|
|
|
req.checkParams('email', 'Must send a valid email').isEmail();
|
|
|
|
return User.findOne({ where: { email: req.params.email } }, (err, user) => {
|
|
|
|
if (err) { return next(err); }
|
2016-03-21 22:14:48 +00:00
|
|
|
if (!user) {
|
|
|
|
req.flash('info', {
|
|
|
|
msg: 'Email address not found. ' +
|
|
|
|
'Please update your Email preferences from your profile.'
|
|
|
|
});
|
|
|
|
return res.redirect('/map');
|
|
|
|
}
|
2016-03-15 11:22:54 -07:00
|
|
|
return user.updateAttribute('sendNotificationEmail', false, (err) => {
|
2016-03-14 23:57:04 -07:00
|
|
|
if (err) { return next(err); }
|
2016-03-15 11:22:54 -07:00
|
|
|
req.flash('info', {
|
|
|
|
msg: 'We\'ve successfully updated your Email preferences.'
|
|
|
|
});
|
|
|
|
return res.redirect('/unsubscribed');
|
2016-03-14 23:57:04 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function unsubscribeQuincy(req, res, next) {
|
2016-03-15 11:22:54 -07:00
|
|
|
req.checkParams('email', 'Must send a valid email').isEmail();
|
|
|
|
return User.findOne({ where: { email: req.params.email } }, (err, user) => {
|
|
|
|
if (err) { return next(err); }
|
2016-03-21 22:14:48 +00:00
|
|
|
if (!user) {
|
|
|
|
req.flash('info', {
|
|
|
|
msg: 'Email address not found. ' +
|
|
|
|
'Please update your Email preferences from your profile.'
|
|
|
|
});
|
|
|
|
return res.redirect('/map');
|
|
|
|
}
|
2016-04-15 21:38:03 +08:00
|
|
|
return user.updateAttributes({
|
2016-04-15 23:06:03 +08:00
|
|
|
sendQuincyEmail: false,
|
|
|
|
sendMonthlyEmail: false,
|
|
|
|
sendNotificationEmail: false
|
2016-04-15 21:38:03 +08:00
|
|
|
}, (err) => {
|
2016-03-14 23:57:04 -07:00
|
|
|
if (err) { return next(err); }
|
2016-03-15 11:22:54 -07:00
|
|
|
req.flash('info', {
|
|
|
|
msg: 'We\'ve successfully updated your Email preferences.'
|
|
|
|
});
|
|
|
|
return res.redirect('/unsubscribed');
|
2016-03-14 23:57:04 -07:00
|
|
|
});
|
2015-06-01 18:30:43 -04:00
|
|
|
});
|
2015-06-03 16:19:23 -07:00
|
|
|
}
|
2015-06-01 18:30:43 -04:00
|
|
|
|
2015-06-03 16:19:23 -07:00
|
|
|
function unsubscribed(req, res) {
|
|
|
|
res.render('resources/unsubscribed', {
|
|
|
|
title: 'You have been unsubscribed'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function githubCalls(req, res, next) {
|
|
|
|
var githubHeaders = {
|
|
|
|
headers: {
|
|
|
|
'User-Agent': constantStrings.gitHubUserAgent
|
2015-06-01 18:30:43 -04:00
|
|
|
},
|
2015-06-03 16:19:23 -07:00
|
|
|
port: 80
|
|
|
|
};
|
|
|
|
request(
|
|
|
|
[
|
|
|
|
'https://api.github.com/repos/freecodecamp/',
|
|
|
|
'freecodecamp/pulls?client_id=',
|
|
|
|
secrets.github.clientID,
|
|
|
|
'&client_secret=',
|
|
|
|
secrets.github.clientSecret
|
|
|
|
].join(''),
|
|
|
|
githubHeaders,
|
|
|
|
function(err, status1, pulls) {
|
|
|
|
if (err) { return next(err); }
|
|
|
|
pulls = pulls ?
|
|
|
|
Object.keys(JSON.parse(pulls)).length :
|
|
|
|
'Can\'t connect to github';
|
|
|
|
|
2016-03-02 20:54:14 -08:00
|
|
|
return request(
|
2015-06-03 16:19:23 -07:00
|
|
|
[
|
|
|
|
'https://api.github.com/repos/freecodecamp/',
|
|
|
|
'freecodecamp/issues?client_id=',
|
|
|
|
secrets.github.clientID,
|
|
|
|
'&client_secret=',
|
|
|
|
secrets.github.clientSecret
|
|
|
|
].join(''),
|
|
|
|
githubHeaders,
|
2015-10-07 00:28:42 -07:00
|
|
|
function(err, status2, issues) {
|
2015-06-03 16:19:23 -07:00
|
|
|
if (err) { return next(err); }
|
|
|
|
issues = ((pulls === parseInt(pulls, 10)) && issues) ?
|
|
|
|
Object.keys(JSON.parse(issues)).length - pulls :
|
|
|
|
"Can't connect to GitHub";
|
2016-03-02 20:54:14 -08:00
|
|
|
return res.send({
|
2015-06-03 16:19:23 -07:00
|
|
|
issues: issues,
|
|
|
|
pulls: pulls
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|