Created
May 20, 2017 07:04
-
-
Save sameerkumar18/36ee1ee98ae60eb32bffb1b4fc77bbae to your computer and use it in GitHub Desktop.
A Simple Python Flask Example for Google Recaptcha (implemented on http://ipusearch.herokuapp.com)
This file contains 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
RECAPTCHA_PUBLIC_KEY = '<public key>' | |
RECAPTCHA_PRIVATE_KEY = '<private key>' | |
def checkRecaptcha(response, secretkey): | |
url = 'https://www.google.com/recaptcha/api/siteverify?' | |
url = url + 'secret=' + str(secretkey) | |
url = url + '&response=' +str(response) | |
jsonobj = json.loads(urllib2.urlopen(url).read()) | |
print jsonobj['success'] | |
if jsonobj['success']: | |
print jsonobj['success'] | |
return True | |
else: | |
return False | |
@app.route('/bca/2016',methods=['GET','POST']) | |
def search_bca_2016(): | |
if request.method == 'POST': | |
response = request.form.get('g-recaptcha-response') | |
if checkRecaptcha(response, RECAPTCHA_PRIVATE_KEY): | |
msg = 'You are human.' | |
print msg | |
else: | |
msg = 'You are bot.' | |
print msg | |
return render_template('search.html') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment