Created
December 12, 2016 12:32
-
-
Save petersirka/e0a96ac7901c2fe4419e4419fff8483a to your computer and use it in GitHub Desktop.
Total.js: A workflow and controller with implementation of reCAPTCHA.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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