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) {
// ...
});
});
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');
}
That's all.