GithubHelp home page GithubHelp logo

mshekera / meteor-recaptcha Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ecsmyth/meteor-recaptcha

0.0 2.0 0.0 167 KB

Google reCAPTCHA V2 for Meteor

License: Other

HTML 3.71% JavaScript 96.29%

meteor-recaptcha's Introduction

Google reCAPTCHA V2 for Meteor

This package implements the version 2 of Google reCAPTCHA. This is a fork of the packages Altapp/Meteor-reCAPTCHA which implements Google reCAPTCHA version 1 and package yuea/Meteor-reCAPTCHA for version 2.

Google reCAPTCHA is a free CAPTCHA service that protects your site against spam, malicious registrations and other forms of attacks where computers try to disguise themselves as a human. In addition to protecting your site, reCAPTCHA also helps digitize old books and newspapers.

Google reCAPTCHA documentation is available at https://developers.google.com/recaptcha

You will need to sign up for an API key at https://www.google.com/recaptcha/admin

Installation

$ meteor add appshore:recaptcha

Setup

###On The Client

Add your reCAPTCHA public key (from Google) to the package. Do this in client-side code.

Meteor.startup(function() {
    reCAPTCHA.config({
        theme: 'light'  // 'light' default or 'dark'
        publickey: 'your_public_key_from_google'
    });
});

###On The Server

Add your reCAPTCHA private key (from Google) to the package. Do this in server-only code (not just an 'isServer' block) to keep your key secret.

Meteor.startup(function() {
    reCAPTCHA.config({
        privatekey: 'your_private_key_from_google'
    });
});

Usage

###On The Client

Include the {{> reCAPTCHA}} template block in your form template.

<template name="myTemplate">
    <form>
    	<!-- your form fields... -->

    	{{> reCAPTCHA}}

    	<button type="submit">Submit</button>
    </form>
</template>

In your submit event, include the reCAPTCHA data in your method call.

Template.myTemplate.events({
    'submit form': function(evt) {
        evt.preventDefault();

        
        //console.log('g-recaptcha-response', $('#g-recaptcha-response').val(), evt);

        var formData = {
            //get the data from your form fields
            ...
            
            // and the recaptcha response
            g-recaptcha-response : $('#g-recaptcha-response').val()
        };

        Meteor.call('formSubmissionMethod', formData, function (error, result) {
            // recaptcha server response will be in result
            console.log('result: ', error, result);
        });
    }
});

###On The Server

In the server method, pass the captcha data and the user's IP address to reCAPTCHA.verifyCaptcha(clientIP, captchaData) to verify that the user entered the correct text.

Meteor.methods({
    formSubmissionMethod: function(formData) {

        var verifyCaptchaResponse = reCAPTCHA.verifyCaptcha(this.connection.clientAddress, formData.g-recaptcha-response);

        //console.log('reCAPTCHA response', verifyCaptchaResponse.data);
        /* verifyCaptchaResponse.data returns a json {
                'success': true|false,
                'error-codes': an-error-code
            };
            // check at https://developers.google.com/recaptcha/docs/verify
        */
        
        if( verifyCaptchaResponse.data.success === false ){
            return verifyCaptchaResponse.data;
        }

        //do stuff with your formData

        return true;
    }
});

meteor-recaptcha's People

Contributors

appshore avatar jordangarside avatar manybothans avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.