-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
recaptchaVerification #2417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
recaptchaVerification #2417
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d6f764b
recaptchaVerification
santoshrajkumar d27fe09
recaptchaVerification
santoshrajkumar e0c8abc
recaptchaVerification1
santoshrajkumar c0ab086
recaptchaVerification2
santoshrajkumar e238701
recaptchaVerification3
santoshrajkumar d120d8c
recaptchaVerification4
santoshrajkumar 9c2f389
recaptchaVerificatio5
santoshrajkumar bd5162f
recaptchaVerificatio5
santoshrajkumar 7311e4e
recaptchaVerificatio6
santoshrajkumar 26b90fb
drawOnVideoStreamOpenCV
santoshrajkumar 3690d85
matrixInverseMCAmethod
santoshrajkumar 64ccb63
fixingImports
santoshrajkumar ad3eeaa
recaptchaVerificationfixes
santoshrajkumar 8cf1c3d
recaptchaVerificationfixes
santoshrajkumar 1ec029b
recaptchaVerificationfixes
santoshrajkumar 1852db7
recaptchaVerificationfixes
santoshrajkumar 7172108
recaptchaVerificationfixes1
santoshrajkumar a8b2810
recaptchaVerificationfixes1
santoshrajkumar 042e449
authenticate = login = render = redirect = print
cclauss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,89 @@ | ||||||
""" | ||||||
Recaptcha is a free captcha service offered by Google in order to secure websites / forms | ||||||
https://www.google.com/recaptcha/admin/create (This is the site where you can get your recaptcha keys created) | ||||||
* Keep in mind that recaptcha doesn't work with localhost | ||||||
When you register recaptcha for your site, you'll get two keys: ClientKey & SecretKey. | ||||||
ClientKey is to be kept in the front end | ||||||
SecretKey is to be kept at backend | ||||||
""" | ||||||
|
||||||
import json | ||||||
import requests | ||||||
|
||||||
""" | ||||||
|
||||||
# An example HTML login form with recaptcha tag is shown below | ||||||
|
||||||
<form action="" method="post"> | ||||||
<h2 class="text-center">Log in</h2> | ||||||
{% csrf_token %} | ||||||
<div class="form-group"> | ||||||
<input type="text" name="username" class="form-control" placeholder="Username" required="required"> | ||||||
</div> | ||||||
<div class="form-group"> | ||||||
<input type="password" name="password" class="form-control" placeholder="Password" required="required"> | ||||||
</div> | ||||||
|
||||||
<div class="form-group"> | ||||||
<button type="submit" class="btn btn-primary btn-block">Log in</button> | ||||||
</div> | ||||||
|
||||||
<!-- Below is the recaptcha tag of html --> | ||||||
<div class="g-recaptcha" data-sitekey="ClientKey"></div> | ||||||
|
||||||
|
||||||
</form> | ||||||
|
||||||
<!-- Below is the recaptcha script to be kept inside html tag --> | ||||||
<script src="https://www.google.com/recaptcha/api.js" async defer></script> | ||||||
|
||||||
""" | ||||||
|
||||||
""" | ||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
Below one Django function based code for views.py file for a login form has been shown with recaptcha verification | ||||||
""" | ||||||
|
||||||
|
||||||
def login_using_recaptcha(request): | ||||||
|
||||||
# When Submit button is clicked | ||||||
if request.method == "POST": | ||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
# get username, password & client_key from frontend | ||||||
username = request.POST.get("username") | ||||||
password = request.POST.get("password") | ||||||
client_key = request.POST.get("g-recaptcha-response") | ||||||
|
||||||
# Keep your recaptcha secret key here | ||||||
secret_key = "secretKey" | ||||||
|
||||||
# make json of your captcha data | ||||||
captchaData = {"secret": secret_key, "response": client_key} | ||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
# post recaptcha response to Google recaptcha api | ||||||
post = requests.post( | ||||||
"https://www.google.com/recaptcha/api/siteverify", data=captchaData | ||||||
) | ||||||
|
||||||
# read the json response from recaptcha api | ||||||
response = json.loads(post.text) | ||||||
verify = response["success"] | ||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
# if verify is true | ||||||
if verify == True: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See PEP8...
Suggested change
|
||||||
# authenticate user | ||||||
user = authenticate(request, username=username, password=password) | ||||||
|
||||||
# if user is in database | ||||||
if user is not None: | ||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
# login user | ||||||
login(request, user) | ||||||
return redirect("/your-webpage") | ||||||
else: | ||||||
# else send user back to the login page again | ||||||
return render(request, "login.html") | ||||||
else: | ||||||
# if verify is not true, send user back to login page | ||||||
return render(request, "login.html") | ||||||
|
||||||
# return the login page when loading or when submit is not pressed direct user to login page | ||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
return render(request, "login.html") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.