Skip to content

Commit

Permalink
fixed social signup form
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Dec 29, 2024
1 parent f5d7919 commit 359fcb2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
38 changes: 25 additions & 13 deletions cookbook/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from datetime import datetime


from allauth.account.forms import ResetPasswordForm, SignupForm
from allauth.socialaccount.forms import SignupForm as SocialSignupForm
from django import forms
from django.conf import settings
from django.core.exceptions import ValidationError
Expand All @@ -14,15 +16,13 @@


class SelectWidget(widgets.Select):

class Media:
js = ('custom/js/form_select.js', )
js = ('custom/js/form_select.js',)


class MultiSelectWidget(widgets.SelectMultiple):

class Media:
js = ('custom/js/form_multiselect.js', )
js = ('custom/js/form_multiselect.js',)


# Yes there are some stupid browsers that still dont support this but
Expand Down Expand Up @@ -139,7 +139,7 @@ class CommentForm(forms.ModelForm):

class Meta:
model = Comment
fields = ('text', )
fields = ('text',)

labels = {'text': _('Add your comment: '), }
widgets = {'text': forms.Textarea(attrs={'rows': 2, 'cols': 15}), }
Expand All @@ -161,7 +161,6 @@ class Meta:
help_texts = {'url': _('Leave empty for dropbox and enter only base url for nextcloud (<code>/remote.php/webdav/</code> is added automatically)'), }



class ConnectorConfigForm(forms.ModelForm):
enabled = forms.BooleanField(
help_text="Is the connector enabled",
Expand Down Expand Up @@ -315,6 +314,18 @@ def signup(self, request, user):
pass


class AllAuthSocialSignupForm(SocialSignupForm):
terms = forms.BooleanField(label=_('Accept Terms and Privacy'))

def __init__(self, **kwargs):
super().__init__(**kwargs)
if settings.PRIVACY_URL == '' and settings.TERMS_URL == '':
self.fields.pop('terms')

def signup(self, request, user):
pass


class CustomPasswordResetForm(ResetPasswordForm):
captcha = hCaptchaField()

Expand Down Expand Up @@ -345,12 +356,13 @@ class Meta:

help_texts = {
'search': _('Select type method of search. Click <a href="/docs/search/">here</a> for full description of choices.'), 'lookup':
_('Use fuzzy matching on units, keywords and ingredients when editing and importing recipes.'), 'unaccent':
_('Fields to search ignoring accents. Selecting this option can improve or degrade search quality depending on language'), 'icontains':
_("Fields to search for partial matches. (e.g. searching for 'Pie' will return 'pie' and 'piece' and 'soapie')"), 'istartswith':
_("Fields to search for beginning of word matches. (e.g. searching for 'sa' will return 'salad' and 'sandwich')"), 'trigram':
_("Fields to 'fuzzy' search. (e.g. searching for 'recpie' will find 'recipe'.) Note: this option will conflict with 'web' and 'raw' methods of search."), 'fulltext':
_("Fields to full text search. Note: 'web', 'phrase', and 'raw' search methods only function with fulltext fields."),
_('Use fuzzy matching on units, keywords and ingredients when editing and importing recipes.'), 'unaccent':
_('Fields to search ignoring accents. Selecting this option can improve or degrade search quality depending on language'), 'icontains':
_("Fields to search for partial matches. (e.g. searching for 'Pie' will return 'pie' and 'piece' and 'soapie')"), 'istartswith':
_("Fields to search for beginning of word matches. (e.g. searching for 'sa' will return 'salad' and 'sandwich')"), 'trigram':
_("Fields to 'fuzzy' search. (e.g. searching for 'recpie' will find 'recipe'.) Note: this option will conflict with 'web' and 'raw' methods of search."),
'fulltext':
_("Fields to full text search. Note: 'web', 'phrase', and 'raw' search methods only function with fulltext fields."),
}

labels = {
Expand All @@ -360,5 +372,5 @@ class Meta:

widgets = {
'search': SelectWidget, 'unaccent': MultiSelectWidget, 'icontains': MultiSelectWidget, 'istartswith': MultiSelectWidget, 'trigram': MultiSelectWidget, 'fulltext':
MultiSelectWidget,
MultiSelectWidget,
}
1 change: 0 additions & 1 deletion cookbook/templates/account/signup.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends "base.html" %}
{% load crispy_forms_filters %}
{% load crispy_forms_filters %}
{% load i18n %}

{% block title %}{% trans 'Register' %}{% endblock %}
Expand Down
3 changes: 1 addition & 2 deletions cookbook/templates/socialaccount/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ <h1>{% trans "Sign Up" %}</h1>
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}"/>
{% endif %}

<div class="form-group">
{{ form.username |as_crispy_field }}
</div>
Expand All @@ -30,7 +29,7 @@ <h1>{% trans "Sign Up" %}</h1>
<div class="form-group">
{{ form.terms |as_crispy_field }}
<small>
{% trans 'I accept the follwoing' %}
{% trans 'I accept the following' %}
{% if TERMS_URL != '' %}
<a href="{{ TERMS_URL }}" target="_blank"
rel="noreferrer nofollow">{% trans 'Terms and Conditions' %}</a>
Expand Down
11 changes: 6 additions & 5 deletions recipes/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
},
}


# allow djangos wsgi server to server mediafiles
GUNICORN_MEDIA = bool(int(os.getenv('GUNICORN_MEDIA', False)))

Expand Down Expand Up @@ -247,14 +246,14 @@
]

if DEBUG_TOOLBAR:
MIDDLEWARE += ('debug_toolbar.middleware.DebugToolbarMiddleware', )
INSTALLED_APPS += ('debug_toolbar', )
MIDDLEWARE += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
INSTALLED_APPS += ('debug_toolbar',)

SORT_TREE_BY_NAME = bool(int(os.getenv('SORT_TREE_BY_NAME', False)))
DISABLE_TREE_FIX_STARTUP = bool(int(os.getenv('DISABLE_TREE_FIX_STARTUP', False)))

if bool(int(os.getenv('SQL_DEBUG', False))):
MIDDLEWARE += ('recipes.middleware.SqlPrintingMiddleware', )
MIDDLEWARE += ('recipes.middleware.SqlPrintingMiddleware',)

if ENABLE_METRICS:
MIDDLEWARE += 'django_prometheus.middleware.PrometheusAfterMiddleware',
Expand Down Expand Up @@ -294,7 +293,6 @@
"handlers": ["console"]
}


AUTHENTICATION_BACKENDS += [
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
Expand Down Expand Up @@ -564,6 +562,9 @@ def setup_database(db_url=None, db_options=None, db_engine=None, pg_host=None, p

# ACCOUNT_SIGNUP_FORM_CLASS = 'cookbook.forms.AllAuthSignupForm'
ACCOUNT_FORMS = {'signup': 'cookbook.forms.AllAuthSignupForm', 'reset_password': 'cookbook.forms.CustomPasswordResetForm'}
SOCIALACCOUNT_FORMS = {
'signup': 'cookbook.forms.AllAuthSocialSignupForm',
}

ACCOUNT_EMAIL_UNKNOWN_ACCOUNTS = False
ACCOUNT_RATE_LIMITS = {
Expand Down

0 comments on commit 359fcb2

Please sign in to comment.