|  | @@ -6,45 +6,71 @@ var config = require('../config');
 | 
	
		
			
				|  |  |  router.get('/', function(req, res) {
 | 
	
		
			
				|  |  |    res.setLocale(config.locale);
 | 
	
		
			
				|  |  |    res.render('index', { community: config.community,
 | 
	
		
			
				|  |  | -                        tokenRequired: !!config.inviteToken });
 | 
	
		
			
				|  |  | +                        tokenRequired: !!config.inviteToken,
 | 
	
		
			
				|  |  | +                        recaptchaSiteKey: config.recaptchaSiteKey });
 | 
	
		
			
				|  |  |  });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  router.post('/invite', function(req, res) {
 | 
	
		
			
				|  |  |    if (req.body.email && (!config.inviteToken || (!!config.inviteToken && req.body.token === config.inviteToken))) {
 | 
	
		
			
				|  |  | -    request.post({
 | 
	
		
			
				|  |  | -        url: 'https://'+ config.slackUrl + '/api/users.admin.invite',
 | 
	
		
			
				|  |  | -        form: {
 | 
	
		
			
				|  |  | -          email: req.body.email,
 | 
	
		
			
				|  |  | -          token: config.slacktoken,
 | 
	
		
			
				|  |  | -          set_active: true
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -      }, function(err, httpResponse, body) {
 | 
	
		
			
				|  |  | -        // body looks like:
 | 
	
		
			
				|  |  | -        //   {"ok":true}
 | 
	
		
			
				|  |  | -        //       or
 | 
	
		
			
				|  |  | -        //   {"ok":false,"error":"already_invited"}
 | 
	
		
			
				|  |  | -        if (err) { return res.send('Error:' + err); }
 | 
	
		
			
				|  |  | -        body = JSON.parse(body);
 | 
	
		
			
				|  |  | -        if (body.ok) {
 | 
	
		
			
				|  |  | -          res.render('result', {
 | 
	
		
			
				|  |  | -            community: config.community,
 | 
	
		
			
				|  |  | -            message: 'Success! Check “'+ req.body.email +'” for an invite from Slack.'
 | 
	
		
			
				|  |  | -          });
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -          var error = body.error;
 | 
	
		
			
				|  |  | -          if (error === 'already_invited' || error === 'already_in_team') {
 | 
	
		
			
				|  |  | +    function doInvite() {
 | 
	
		
			
				|  |  | +      request.post({
 | 
	
		
			
				|  |  | +          url: 'https://'+ config.slackUrl + '/api/users.admin.invite',
 | 
	
		
			
				|  |  | +          form: {
 | 
	
		
			
				|  |  | +            email: req.body.email,
 | 
	
		
			
				|  |  | +            token: config.slacktoken,
 | 
	
		
			
				|  |  | +            set_active: true
 | 
	
		
			
				|  |  | +          }
 | 
	
		
			
				|  |  | +        }, function(err, httpResponse, body) {
 | 
	
		
			
				|  |  | +          // body looks like:
 | 
	
		
			
				|  |  | +          //   {"ok":true}
 | 
	
		
			
				|  |  | +          //       or
 | 
	
		
			
				|  |  | +          //   {"ok":false,"error":"already_invited"}
 | 
	
		
			
				|  |  | +          if (err) { return res.send('Error:' + err); }
 | 
	
		
			
				|  |  | +          body = JSON.parse(body);
 | 
	
		
			
				|  |  | +          if (body.ok) {
 | 
	
		
			
				|  |  |              res.render('result', {
 | 
	
		
			
				|  |  |                community: config.community,
 | 
	
		
			
				|  |  | -              message: 'Success! You were already invited.<br>' +
 | 
	
		
			
				|  |  | -                       'Visit <a href="https://'+ config.slackUrl +'">'+ config.community +'</a>'
 | 
	
		
			
				|  |  | +              message: 'Success! Check “'+ req.body.email +'” for an invite from Slack.'
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +          } else {
 | 
	
		
			
				|  |  | +            var error = body.error;
 | 
	
		
			
				|  |  | +            if (error === 'already_invited' || error === 'already_in_team') {
 | 
	
		
			
				|  |  | +              res.render('result', {
 | 
	
		
			
				|  |  | +                community: config.community,
 | 
	
		
			
				|  |  | +                message: 'Success! You were already invited.<br>' +
 | 
	
		
			
				|  |  | +                        'Visit <a href="https://'+ config.slackUrl +'">'+ config.community +'</a>'
 | 
	
		
			
				|  |  | +              });
 | 
	
		
			
				|  |  | +              return;
 | 
	
		
			
				|  |  | +            } else if (error === 'invalid_email') {
 | 
	
		
			
				|  |  | +              error = 'The email you entered is an invalid email.';
 | 
	
		
			
				|  |  | +            } else if (error === 'invalid_auth') {
 | 
	
		
			
				|  |  | +              error = 'Something has gone wrong. Please contact a system administrator.';
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            res.render('result', {
 | 
	
		
			
				|  |  | +              community: config.community,
 | 
	
		
			
				|  |  | +              message: 'Failed! ' + error,
 | 
	
		
			
				|  |  | +              isFailed: true
 | 
	
		
			
				|  |  |              });
 | 
	
		
			
				|  |  | -            return;
 | 
	
		
			
				|  |  | -          } else if (error === 'invalid_email') {
 | 
	
		
			
				|  |  | -            error = 'The email you entered is an invalid email.';
 | 
	
		
			
				|  |  | -          } else if (error === 'invalid_auth') {
 | 
	
		
			
				|  |  | -            error = 'Something has gone wrong. Please contact a system administrator.';
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    if (!!config.recaptchaSiteKey && !!config.recaptchaSecretKey) {
 | 
	
		
			
				|  |  | +      request.post({
 | 
	
		
			
				|  |  | +        url: 'https://www.google.com/recaptcha/api/siteverify',
 | 
	
		
			
				|  |  | +        form: {
 | 
	
		
			
				|  |  | +          response: req.body['g-recaptcha-response'],
 | 
	
		
			
				|  |  | +          secret: config.recaptchaSecretKey
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +      }, function(err, httpResponse, body) {
 | 
	
		
			
				|  |  | +        if (typeof body === "string") {
 | 
	
		
			
				|  |  | +          body = JSON.parse(body);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        if (body.success) {
 | 
	
		
			
				|  |  | +          doInvite();
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +          error = 'Invalid captcha.';
 | 
	
		
			
				|  |  |            res.render('result', {
 | 
	
		
			
				|  |  |              community: config.community,
 | 
	
		
			
				|  |  |              message: 'Failed! ' + error,
 | 
	
	
		
			
				|  | @@ -52,6 +78,9 @@ router.post('/invite', function(req, res) {
 | 
	
		
			
				|  |  |            });
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |        });
 | 
	
		
			
				|  |  | +    } else {
 | 
	
		
			
				|  |  | +      doInvite();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |    } else {
 | 
	
		
			
				|  |  |      var errMsg = [];
 | 
	
		
			
				|  |  |      if (!req.body.email) {
 |