Skip to content

Commit

Permalink
Update views.py
Browse files Browse the repository at this point in the history
Un-commented recaptcha function
  • Loading branch information
Freshrojek committed Apr 19, 2021
1 parent 7710ddc commit 5b16e31
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions memberships/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@
from .tokens import email_verification_token
from .tasks import task_send_email

# def validate_recaptcha(response):
# url = 'https://www.google.com/recaptcha/api/siteverify'
# secret = settings.RECAPTCHA_SECRET_KEY
# payload = {
# 'secret': secret,
# 'response': response
# }
# data = urllib.parse.urlencode(payload).encode("utf-8")
# request = urllib.request.Request(url, data=data)
# response = urllib.request.urlopen(request)
# result = json.loads(response.read().decode())
# success = result.get('success')
#
# if (not result.get('success')) or (float(result.get('score')) < 0.5):
# return 'fail'
#
# return result
def validate_recaptcha(response):
url = 'https://www.google.com/recaptcha/api/siteverify'
secret = settings.RECAPTCHA_SECRET_KEY
payload = {
'secret': secret,
'response': response
}
data = urllib.parse.urlencode(payload).encode("utf-8")
request = urllib.request.Request(url, data=data)
response = urllib.request.urlopen(request)
result = json.loads(response.read().decode())
success = result.get('success')

if (not result.get('success')) or (float(result.get('score')) < 0.5):
return 'fail'

return result


def form_valid(self, form):
Expand Down

0 comments on commit 5b16e31

Please sign in to comment.