Skip to content

Commit 3e69979

Browse files
committed
Added captcha
1 parent ff0b6e2 commit 3e69979

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

main_app/templates/main_app/create_contact.html

+14-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414

1515
font-size: 18px;
16-
color: black
16+
color: black;
1717
}
1818
.jumbotron {
1919
background-color: #f3f3f3;
@@ -78,8 +78,21 @@ <h1 class="display-4" style="color: black; font-family: 'Bangers', cursive; marg
7878
<div class="text-center " style="padding-bottom: 8%; padding-top: 5%; color: rgb(50, 192, 192); ">
7979
<button style="color:white; border-radius: 25px; padding-bottom:35px " class="btn btn-success btn-lg " name="submit " type="submit "><b>Create</b></button></div>
8080
</form>
81+
82+
83+
84+
8185
</div>
8286
</div>
87+
<script src='https://www.google.com/recaptcha/api.js' style="position: absolute; margin-left: 25px;"></script>
88+
89+
90+
<div class="g-recaptcha" id="rcaptcha" data-sitekey="6LfGawkbAAAAAEwMU9ElnUNXMSG5Az8uXGLRvXZs"></div>
91+
<span id="captcha" style="color:red"></span>
92+
<!-- this will show captcha errors -->
93+
94+
95+
8396
</body>
8497

8598
{% endblock %}

main_app/views.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,10 @@ def create_contact(request):
226226
messages.info(request, "An email has been sent to your contact!!")
227227
return redirect("main_app:emergency_contact")
228228
messages.error(request, "Invalid username or password")
229-
context = {"form": form}
230-
return render(request, "main_app/create_contact.html", context)
229+
230+
231+
return render(request, "main_app/create_contact.html", {'form':form, 'recaptcha_site_key':settings.GOOGLE_RECAPTCHA_SITE_KEY})
232+
231233

232234

233235
def update_contact(request, pk):

mysite/settings.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,16 @@
185185
}
186186
}
187187

188-
GOOGLE_RECAPTCHA_SECRET_KEY = "6Ldj7dkaAAAAALd12sHuTm4kLr3FmAqD5chszUjH"
188+
189+
...
190+
191+
# SECURITY WARNING: keep the secret key used in production secret!
192+
...
193+
GOOGLE_RECAPTCHA_SITE_KEY = '6LfGawkbAAAAAEwMU9ElnUNXMSG5Az8uXGLRvXZs' #your reCAPTCHA SITE key
194+
195+
GOOGLE_RECAPTCHA_SECRET_KEY = '6LfGawkbAAAAAEXmouoGwTWgBV2__O-2lbOcN9iF' #your reCAPTCHA SECRET key
196+
197+
# SECURITY WARNING: don't run with debug turned on in production!
198+
DEBUG = False
199+
200+
...

0 commit comments

Comments
 (0)