Merge pull request #303 from FreeCodeCamp/slack
We're ready to move to slack from gitter thanks to @storbeck
This commit is contained in:
57
app.js
57
app.js
@ -31,6 +31,7 @@ var express = require('express'),
|
||||
passport = require('passport'),
|
||||
expressValidator = require('express-validator'),
|
||||
connectAssets = require('connect-assets'),
|
||||
request = require('request'),
|
||||
|
||||
/**
|
||||
* Controllers (route handlers).
|
||||
@ -46,7 +47,7 @@ var express = require('express'),
|
||||
/**
|
||||
* Stories
|
||||
*/
|
||||
storyController = require('./controllers/story');
|
||||
storyController = require('./controllers/story'),
|
||||
|
||||
/**
|
||||
* API keys and Passport configuration.
|
||||
@ -292,6 +293,60 @@ app.post(
|
||||
userController.updateProgress
|
||||
);
|
||||
|
||||
app.get('/api/slack', function(req, res) {
|
||||
if (req.user) {
|
||||
if (req.user.email) {
|
||||
var invite = {
|
||||
'email': req.user.email,
|
||||
'token': process.env.SLACK_KEY,
|
||||
'set_active': true
|
||||
};
|
||||
|
||||
var headers = {
|
||||
'User-Agent': 'Node Browser/0.0.1',
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
};
|
||||
|
||||
var options = {
|
||||
url: 'https://freecode.slack.com/api/users.admin.invite',
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
form: invite
|
||||
};
|
||||
|
||||
request(options, function (error, response, body) {
|
||||
if (!error && response.statusCode === 200) {
|
||||
req.flash('success', {
|
||||
msg: "We've successfully requested an invite for you. Please check your email and follow the instructions from Slack."
|
||||
});
|
||||
req.user.sentSlackInvite = true;
|
||||
req.user.save(function(err, user) {
|
||||
if (err) {
|
||||
next(err);
|
||||
}
|
||||
return res.redirect('back');
|
||||
});
|
||||
} else {
|
||||
req.flash('errors', {
|
||||
msg: "The invitation email did not go through for some reason. Please try again or <a href='mailto:team@freecodecamp.com?subject=slack%20invite%20failed%20to%20send>email us</a>."
|
||||
});
|
||||
return res.redirect('back');
|
||||
}
|
||||
})
|
||||
} else {
|
||||
req.flash('notice', {
|
||||
msg: "Before we can send your Slack invite, we need your email address. Please update your profile information here."
|
||||
});
|
||||
return res.redirect('/account');
|
||||
}
|
||||
} else {
|
||||
req.flash('notice', {
|
||||
msg: "You need to sign in to Free Code Camp before we can send you a Slack invite."
|
||||
});
|
||||
return res.redirect('/account');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Main routes.
|
||||
*/
|
||||
|
@ -10,7 +10,11 @@ module.exports = {
|
||||
},
|
||||
|
||||
blogger: {
|
||||
key: process.env.BLOGGER_KEY,
|
||||
key: process.env.BLOGGER_KEY
|
||||
},
|
||||
|
||||
slack: {
|
||||
key: process.env.SLACK_KEY
|
||||
},
|
||||
|
||||
mandrill: {
|
||||
|
@ -74,9 +74,13 @@ module.exports = {
|
||||
},
|
||||
|
||||
chat: function chat(req, res) {
|
||||
res.render('resources/chat', {
|
||||
title: "Enter Free Code Camp's Chat Rooms"
|
||||
});
|
||||
if (req.user && req.user.sentSlackInvite) {
|
||||
res.redirect('https://freecode.slack.com/messages/general/');
|
||||
} else {
|
||||
res.render('resources/chat', {
|
||||
title: "Join our chat room"
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
nonprofitProjectInstructions: function nonprofitProjectInstructions(req, res) {
|
||||
|
@ -348,6 +348,7 @@ var userSchema = new mongoose.Schema({
|
||||
}
|
||||
},
|
||||
resetPasswordToken: String,
|
||||
sentSlackInvite: false,
|
||||
resetPasswordExpires: Date,
|
||||
uncompletedBonfires: Array,
|
||||
completedBonfires: Array,
|
||||
|
@ -50,7 +50,7 @@ block content
|
||||
.success(
|
||||
function (data) {
|
||||
console.log(data);
|
||||
url = "https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20Bonfire:%20#{name}&url=" + data + "&hashtags=LearnToCode, JavaScript";
|
||||
url = "https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20Challenge:%20#{name}&url=" + data + "&hashtags=LearnToCode, JavaScript";
|
||||
$('.btn-twitter').attr('href', url);
|
||||
}
|
||||
);
|
@ -14,7 +14,7 @@
|
||||
li
|
||||
a(href='/challenges') Challenges
|
||||
li
|
||||
a(href='/chat') Chat
|
||||
a(href='/chat', target='_blank') Chat
|
||||
li
|
||||
a(href='/stories/hot') News
|
||||
li
|
||||
|
@ -14,4 +14,20 @@ script.
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
ga('create', 'UA-55446531-1', 'auto');
|
||||
ga('require', 'displayfeatures');
|
||||
ga('send', 'pageview');
|
||||
ga('send', 'pageview');
|
||||
script#inspectletjs(type='text/javascript').
|
||||
window.__insp = window.__insp || [];
|
||||
__insp.push(['wid', 561999918]);
|
||||
(function() {
|
||||
function __ldinsp() {
|
||||
var insp = document.createElement('script');
|
||||
insp.type = 'text/javascript';
|
||||
insp.async = true;
|
||||
insp.id = "inspsync";
|
||||
insp.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://cdn.inspectlet.com/inspectlet.js';
|
||||
var x = document.getElementsByTagName('script')[0];
|
||||
x.parentNode.insertBefore(insp, x);
|
||||
}
|
||||
if (window.attachEvent) window.attachEvent('onload', __ldinsp);
|
||||
else window.addEventListener('load', __ldinsp, false);
|
||||
})();
|
@ -4,6 +4,9 @@ block content
|
||||
br
|
||||
.text-center
|
||||
if (user)
|
||||
if (!user.sentSlackInvite)
|
||||
a.btn.btn-primary.btn-cta.next-challenge-button(href="/api/slack") Join our Slack Chat Room
|
||||
.spacer
|
||||
a.btn.btn-cta.signup-btn.next-challenge-button(href="/challenges") Take me to my next challenge
|
||||
else
|
||||
a.btn.btn-cta.signup-btn.next-challenge-button(href="/signin") Start learning to code (it's free)
|
||||
|
Reference in New Issue
Block a user