Skip to content

Commit

Permalink
Removing captchagen due to incompatabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
sirkitree committed Feb 18, 2013
1 parent afa7058 commit 15e7361
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 52 deletions.
1 change: 0 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ app.configure('production', function(){

app.get('/', routes.index);
app.get('/partials/:name', routes.partials);
app.get('/captcha.png', routes.captcha);

// JSON API

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"dependencies": {
"express": "3.0.x",
"jade": ">= 0.0.1",
"marked": "0.2.5",
"captchagen": "0.0.2"
"marked": "0.2.5"
}
}
18 changes: 4 additions & 14 deletions public/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ function IndexCtrl($scope, $http, $location) {
$http.post('/api/post', $scope.form).
success(function(data) {

// We always want to reset the captcha, but if the previous entry was invalid,
// we should NOT reset the postbox and markdown-preview.
if (data.captcha !== false) {
// empty the postbox
$('#postbox').val('').height('50px');
// reset the preview
$('#markdown-preview').html('');
}
// empty the postbox
$('#postbox').val('').height('50px');
// reset the preview
$('#markdown-preview').html('');

$location.path('/');
$http.get('/api/posts').
Expand All @@ -29,12 +25,6 @@ function IndexCtrl($scope, $http, $location) {
});
});

// reset the captcha image
$('#captcha-image').remove();
$('#captcha-input').before('<img src="/captcha.png" id="captcha-image"></img>');
// reset the captcha input
$('#captcha-input').val('');

};

}
Expand Down
27 changes: 3 additions & 24 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,9 @@ exports.post = function (req, res) {

// POST
exports.addPost = function(req, res, next) {
console.log(req.session);
// the user's answer
var theirCaptcha = req.body.captcha;
if (!theirCaptcha) {
return next("Missing captcha input");
}
if (theirCaptcha == req.session.captcha) {
// valid human
delete req.session.captcha;
req.session.isHuman = true;

// push to posts
data.posts.push(req.body);
res.json(req.body);
} else {
// invalid human
delete req.session.isHuman;
req.session.isHuman = false;

// notify user that catcha is invalid
// should give the option to NOT remove message from #postbox
data.captcha = 'invalid';
res.json({captcha: false});
}
// push to posts
data.posts.push(req.body);
res.json(req.body);
};

// PUT
Expand Down
9 changes: 0 additions & 9 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,4 @@ exports.index = function(req, res){
exports.partials = function(req, res) {
var name = req.params.name;
res.render('partials/' + name);
};

exports.captcha = function(req, res, next) {
var c = require('captchagen'),
captcha = c.generate(),
sess = req.session;
sess.captcha = captcha.text();
res.type('image/png');
res.end(captcha.buffer());
};
2 changes: 0 additions & 2 deletions views/partials/addPost.jade
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ form(class='navbar-form pull-left')
textarea(ng-model='form.text', id='postbox', class='span4', type='text', placeholder='Whatcha workin on?', ui-jq='autosize')
include previewPost
p
img(src='/captcha.png', id='captcha-image')
input(ng-model='form.captcha', type='text', id='captcha-input')
button(ng-click='submitPost()', class='btn btn-primary pull-right', type='submit') Post

0 comments on commit 15e7361

Please sign in to comment.