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'),
|
passport = require('passport'),
|
||||||
expressValidator = require('express-validator'),
|
expressValidator = require('express-validator'),
|
||||||
connectAssets = require('connect-assets'),
|
connectAssets = require('connect-assets'),
|
||||||
|
request = require('request'),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controllers (route handlers).
|
* Controllers (route handlers).
|
||||||
@ -46,7 +47,7 @@ var express = require('express'),
|
|||||||
/**
|
/**
|
||||||
* Stories
|
* Stories
|
||||||
*/
|
*/
|
||||||
storyController = require('./controllers/story');
|
storyController = require('./controllers/story'),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API keys and Passport configuration.
|
* API keys and Passport configuration.
|
||||||
@ -292,6 +293,60 @@ app.post(
|
|||||||
userController.updateProgress
|
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.
|
* Main routes.
|
||||||
*/
|
*/
|
||||||
|
@ -10,7 +10,11 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
blogger: {
|
blogger: {
|
||||||
key: process.env.BLOGGER_KEY,
|
key: process.env.BLOGGER_KEY
|
||||||
|
},
|
||||||
|
|
||||||
|
slack: {
|
||||||
|
key: process.env.SLACK_KEY
|
||||||
},
|
},
|
||||||
|
|
||||||
mandrill: {
|
mandrill: {
|
||||||
|
@ -74,9 +74,13 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
chat: function chat(req, res) {
|
chat: function chat(req, res) {
|
||||||
res.render('resources/chat', {
|
if (req.user && req.user.sentSlackInvite) {
|
||||||
title: "Enter Free Code Camp's Chat Rooms"
|
res.redirect('https://freecode.slack.com/messages/general/');
|
||||||
});
|
} else {
|
||||||
|
res.render('resources/chat', {
|
||||||
|
title: "Join our chat room"
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
nonprofitProjectInstructions: function nonprofitProjectInstructions(req, res) {
|
nonprofitProjectInstructions: function nonprofitProjectInstructions(req, res) {
|
||||||
|
@ -348,6 +348,7 @@ var userSchema = new mongoose.Schema({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
resetPasswordToken: String,
|
resetPasswordToken: String,
|
||||||
|
sentSlackInvite: false,
|
||||||
resetPasswordExpires: Date,
|
resetPasswordExpires: Date,
|
||||||
uncompletedBonfires: Array,
|
uncompletedBonfires: Array,
|
||||||
completedBonfires: Array,
|
completedBonfires: Array,
|
||||||
|
@ -50,7 +50,7 @@ block content
|
|||||||
.success(
|
.success(
|
||||||
function (data) {
|
function (data) {
|
||||||
console.log(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);
|
$('.btn-twitter').attr('href', url);
|
||||||
}
|
}
|
||||||
);
|
);
|
@ -14,7 +14,7 @@
|
|||||||
li
|
li
|
||||||
a(href='/challenges') Challenges
|
a(href='/challenges') Challenges
|
||||||
li
|
li
|
||||||
a(href='/chat') Chat
|
a(href='/chat', target='_blank') Chat
|
||||||
li
|
li
|
||||||
a(href='/stories/hot') News
|
a(href='/stories/hot') News
|
||||||
li
|
li
|
||||||
|
@ -15,3 +15,19 @@ script.
|
|||||||
ga('create', 'UA-55446531-1', 'auto');
|
ga('create', 'UA-55446531-1', 'auto');
|
||||||
ga('require', 'displayfeatures');
|
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
|
br
|
||||||
.text-center
|
.text-center
|
||||||
if (user)
|
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
|
a.btn.btn-cta.signup-btn.next-challenge-button(href="/challenges") Take me to my next challenge
|
||||||
else
|
else
|
||||||
a.btn.btn-cta.signup-btn.next-challenge-button(href="/signin") Start learning to code (it's free)
|
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