From 13faedc86ee60b0f579f07c95d5124bd22956f15 Mon Sep 17 00:00:00 2001 From: Michael Q Larson Date: Wed, 14 Jan 2015 13:28:20 -0800 Subject: [PATCH] Add email functionality to done-with-first-100-hours page and refactor nonprofit link to be on same controller in same view folder --- app.js | 24 ++--- controllers/contact.js | 93 +++++++++++-------- controllers/resources.js | 7 -- public/css/main.less | 5 + public/js/main.js | 6 ++ views/contact/done-with-first-100-hours.jade | 28 ++++++ .../{contact.jade => contact/nonprofits.jade} | 2 +- .../resources/done-with-first-100-hours.jade | 6 -- 8 files changed, 108 insertions(+), 63 deletions(-) create mode 100644 views/contact/done-with-first-100-hours.jade rename views/{contact.jade => contact/nonprofits.jade} (99%) delete mode 100644 views/resources/done-with-first-100-hours.jade diff --git a/app.js b/app.js index 025a668dec..b52cfe2186 100644 --- a/app.js +++ b/app.js @@ -197,8 +197,8 @@ app.use( /** * Main routes. */ -app.get('/', homeController.index); +app.get('/', homeController.index); app.get( '/resources/interview-questions', resourcesController.interviewQuestions); @@ -213,20 +213,14 @@ app.get('/gmail-shortcuts', resourcesController.gmailShortcuts); app.get('/control-shortcuts', resourcesController.controlShortcuts); app.get('/control-shortcuts', resourcesController.deployAWebsite); app.get('/stats', resourcesController.stats); - app.get( '/pair-program-with-team-viewer', resourcesController.pairProgramWithTeamViewer ); -app.get( - '/done-with-first-100-hours', - resourcesController.doneWithFirst100Hours -); app.get( '/programmer-interview-questions-app', resourcesController.programmerInterviewQuestionsApp ); - app.get('/about', resourcesController.about); app.get('/login', userController.getLogin); app.post('/login', userController.postLogin); @@ -239,8 +233,16 @@ app.get('/email-signup', userController.getEmailSignup); app.get('/email-signin', userController.getEmailSignin); app.post('/email-signup', userController.postEmailSignup); app.post('/email-signin', userController.postLogin); -app.get('/nonprofits', contactController.getContact); -app.post('/nonprofits', contactController.postContact); +app.get('/nonprofits', contactController.getNonprofitsForm); +app.post('/nonprofits', contactController.postNonprofitsForm); +app.get( + '/done-with-first-100-hours', + contactController.getDoneWithFirst100Hours +); +app.post( + '/done-with-first-100-hours', + contactController.postDoneWithFirst100Hours +); // # Protected routes, user must be logged in. app.post( @@ -248,13 +250,13 @@ app.post( passportConf.isAuthenticated, userController.updateProgress ); - app.get( '/challenges/:challengeNumber', challengesController.returnChallenge ); app.all('/account', passportConf.isAuthenticated); app.get('/account/api', userController.getAccountAngular); + // Unique Check API route app.get('/api/checkUniqueUsername/:username', userController.checkUniqueUsername); app.get('/api/checkUniqueEmail/:email', userController.checkUniqueEmail); @@ -264,8 +266,6 @@ app.post('/account/password', userController.postUpdatePassword); app.post('/account/delete', userController.postDeleteAccount); app.get('/account/unlink/:provider', userController.getOauthUnlink); - - //put this route last app.get( '/:username', diff --git a/controllers/contact.js b/controllers/contact.js index 392a91ee6c..5406c5cda1 100644 --- a/controllers/contact.js +++ b/controllers/contact.js @@ -10,46 +10,65 @@ var transporter = nodemailer.createTransport({ } }); -/** - * GET /contact - * Contact form page. - */ +module.exports = { + /** + * GET /contact + * Contact form page. + */ -exports.getContact = function(req, res) { - res.render('contact', { - title: 'Free Code Work for Nonprofits Project Submission 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. - */ + /** + * POST /contact + * Send a contact form via Nodemailer. + */ -exports.postContact = function(req, res) { - req.assert('name', 'Name cannot be blank').notEmpty(); - req.assert('email', 'Email is not valid').isEmail(); - req.assert('message', 'Message cannot be blank').notEmpty(); + postNonprofitsForm: function(req, res) { + var mailOptions = { + to: 'team@freecodecamp.com', + name: req.body.name, + from: req.body.email, + subject: 'CodeNonprofit Project Idea from ' + req.body.name, + text: req.body.message + }; - if (req.validationErrors()) { - req.flash('errors', errors); - return res.redirect('/nonprofits'); + 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) { + res.render('contact/done-with-first-100-hours', { + title: + 'Congratulations on finishing the first 100 hours of Free Code Camp!' + }); + }, + + postDoneWithFirst100Hours: function(req, res) { + var mailOptions = { + to: 'team@freecodecamp.com', + name: 'Completionist', + from: req.body.email, + subject: 'Code 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('/'); + }); } - - var mailOptions = { - to: 'team@freecodecamp.com', - 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'); - }); }; diff --git a/controllers/resources.js b/controllers/resources.js index 16ef1ef231..8f59cd6671 100644 --- a/controllers/resources.js +++ b/controllers/resources.js @@ -175,13 +175,6 @@ module.exports = { }); }, - doneWithFirst100Hours: function(req, res) { - res.render('resources/done-with-first-100-hours', { - title: - 'Congratulations on finishing the first 100 hours of Free Code Camp!' - }); - }, - interviewQuestions: function(req, res) { res.json(questions); } diff --git a/public/css/main.less b/public/css/main.less index 11391a8637..a6e05865cb 100644 --- a/public/css/main.less +++ b/public/css/main.less @@ -194,6 +194,11 @@ ul { animation-delay: 2s; } +.delay-4 { + -webkit-animation-delay: 4s; + animation-delay: 4s; +} + .delay-10 { -webkit-animation-delay: 10s; animation-delay: 10s; diff --git a/public/js/main.js b/public/js/main.js index 829a416b63..431cb9a5f7 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -74,6 +74,12 @@ profileValidation.controller('nonprofitFormController', ['$scope', } ]); +profileValidation.controller('doneWithFirst100HoursFormController', ['$scope', + function($scope) { + + } +]); + profileValidation.directive('uniqueUsername', function($http) { return { restrict: 'A', diff --git a/views/contact/done-with-first-100-hours.jade b/views/contact/done-with-first-100-hours.jade new file mode 100644 index 0000000000..e4cc37079b --- /dev/null +++ b/views/contact/done-with-first-100-hours.jade @@ -0,0 +1,28 @@ +extends ../layout +block content + .jumbotron.text-center + h1.animated.lightSpeedIn Congratulations! + .animated.fadeIn.delay-2 + h2 You've completed the first 100 hours of Free Code Camp! + .animated.fadeIn.delay-4 + h3 Now you're ready to continue your learning by building solutions for nonprofits! If you've completed all the Free Code Camp challenges and the Easy and Medium CoderByte challenges, enter your email below. We'll send you an email with the next steps. + br + form.form-horizontal(role='form', action="/done-with-first-100-hours/", method='POST', novalidate='novalidate', name='doneWithFirst100HoursForm') + input(type='hidden', name='_csrf', value=_csrf) + .form-group + label(class='col-sm-3 control-label', for='email') Your email * + .col-sm-8 + input.form-control(type='text', name='email', id='email', autocomplete="off", ng-model='email', required='required', ng-keypress='') + .col-sm-8.col-sm-offset-3(ng-show="doneWithFirst100HoursForm.$error.email && !doneWithFirst100HoursForm.email.$pristine") + alert(type='danger') + span.ion-close-circled + | Please enter a valid email format. + .col-sm-8.col-sm-offset-3(ng-show="doneWithFirst100HoursForm.email.$invalid && doneWithFirst100HoursForm.email.$error.required && !doneWithFirst100HoursForm.email.$pristine") + alert(type='danger') + span.ion-close-circled(id='#email-error'). + Your email is required. + .form-group + .col-sm-offset-2.col-sm-8 + button.btn.btn-primary(type='submit', ng-disabled='doneWithFirst100HoursForm.$invalid') + span.ion-paper-airplane + | Submit \ No newline at end of file diff --git a/views/contact.jade b/views/contact/nonprofits.jade similarity index 99% rename from views/contact.jade rename to views/contact/nonprofits.jade index 9695d21333..689d03f785 100644 --- a/views/contact.jade +++ b/views/contact/nonprofits.jade @@ -1,4 +1,4 @@ -extends layout +extends ../layout block content .jumbotron diff --git a/views/resources/done-with-first-100-hours.jade b/views/resources/done-with-first-100-hours.jade deleted file mode 100644 index 47252d5d88..0000000000 --- a/views/resources/done-with-first-100-hours.jade +++ /dev/null @@ -1,6 +0,0 @@ -extends ../layout -block content - .jumbotron.text-center - h1.hug-top Congratulations on finishing the first 100 hours of Free Code Camp! - h2 Now you're ready to continue your learning by building solutions for nonprofits! - h3 Private message Quincy Larson in the Free Code Camp Chatroom and he'll help you get started on your first project. \ No newline at end of file