Skip to content

Commit 720c48d

Browse files
committed
Add captcha to user signup page
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent b82c0b4 commit 720c48d

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

fedcode/forms.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from django import forms
1111
from django.contrib.auth.forms import UserCreationForm
1212
from django.contrib.auth.models import User
13+
from django_recaptcha.fields import ReCaptchaField
14+
from django_recaptcha.widgets import ReCaptchaV2Checkbox
1315

1416
from .models import Note
1517
from .models import Repository
@@ -58,6 +60,9 @@ def __init__(self, *args, **kwargs):
5860

5961

6062
class PersonSignUpForm(UserCreationForm):
63+
captcha = ReCaptchaField(
64+
error_messages={"required": ("Captcha is required")}, widget=ReCaptchaV2Checkbox
65+
)
6166
email = forms.EmailField(max_length=254)
6267

6368
class Meta:

fedcode/templates/user_sign_up.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
<p>Error</p>
1818
</div>
1919
<div class="message-body">
20-
{{ form.errors }}
20+
{% for error in form.errors.values %}
21+
{{ error }}
22+
{% endfor %}
2123
</div>
2224
</article>
2325
</div>
@@ -61,6 +63,11 @@ <h2 class="title">User Signup</h2>
6163
autocomplete="new-password" required id="id_password2">
6264
</div>
6365
</div>
66+
<div class="field">
67+
<div class="control">
68+
{{ form.captcha }}
69+
</div>
70+
</div>
6471
<input class="button is-fullwidth is-info" type="submit" value="Sign Up">
6572
</form>
6673
</div>

0 commit comments

Comments
 (0)