Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Total.js: A workflow and controller with implementation of reCAPTCHA.
exports.install = function() {
F.route('/api/signup/', json_signup, ['*SignUp', 'post']);
};
function json_signup() {
var self = this;
self.$async(self.callback(), 1).$workflow('recaptcha').$save().$workflow('notify');
}
NEWSCHEMA('SignUp').make(function(schema) {
// ...
schema.define('email', 'Email', true);
schema.define('recaptcha', 'String', true);
// ...
schema.addWorkflow('reCAPTCHA', function(error, model, options, callback, controller) {
RESTBuilder.make(function(builder) {
builder.url('https://www.google.com/recaptcha/api/siteverify');
builder.set('secret', 'YOUR SECRET FROM GOOGLE');
builder.set('response', model.recaptcha);
controller && builder.set('remoteip', controller.ip);
builder.urlencoded();
builder.exec(function(err, response) {
if (err || !response.success)
error.push('error-recaptcha');
callback(SUCCESS(true));
});
});
});
schema.addWorkflow('notify', function(error, model, options, callback, controller) {
// ...
});
schema.setSave(function(error, model, options, callback, controller) {
// ...
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.