From 359fcb24cff4aba3454983eedc76dad1e0b680a9 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Sun, 29 Dec 2024 13:42:12 +0100 Subject: [PATCH] fixed social signup form --- cookbook/forms.py | 38 +++++++++++++------- cookbook/templates/account/signup.html | 1 - cookbook/templates/socialaccount/signup.html | 3 +- recipes/settings.py | 11 +++--- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/cookbook/forms.py b/cookbook/forms.py index bda48e3dd5..071431a4f0 100644 --- a/cookbook/forms.py +++ b/cookbook/forms.py @@ -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 @@ -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 @@ -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}), } @@ -161,7 +161,6 @@ class Meta: help_texts = {'url': _('Leave empty for dropbox and enter only base url for nextcloud (/remote.php/webdav/ is added automatically)'), } - class ConnectorConfigForm(forms.ModelForm): enabled = forms.BooleanField( help_text="Is the connector enabled", @@ -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() @@ -345,12 +356,13 @@ class Meta: help_texts = { 'search': _('Select type method of search. Click here 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 = { @@ -360,5 +372,5 @@ class Meta: widgets = { 'search': SelectWidget, 'unaccent': MultiSelectWidget, 'icontains': MultiSelectWidget, 'istartswith': MultiSelectWidget, 'trigram': MultiSelectWidget, 'fulltext': - MultiSelectWidget, + MultiSelectWidget, } diff --git a/cookbook/templates/account/signup.html b/cookbook/templates/account/signup.html index baceb2cb15..fc29ca2b2f 100644 --- a/cookbook/templates/account/signup.html +++ b/cookbook/templates/account/signup.html @@ -1,6 +1,5 @@ {% extends "base.html" %} {% load crispy_forms_filters %} -{% load crispy_forms_filters %} {% load i18n %} {% block title %}{% trans 'Register' %}{% endblock %} diff --git a/cookbook/templates/socialaccount/signup.html b/cookbook/templates/socialaccount/signup.html index 6779752fa2..79608c1ffd 100644 --- a/cookbook/templates/socialaccount/signup.html +++ b/cookbook/templates/socialaccount/signup.html @@ -16,7 +16,6 @@

{% trans "Sign Up" %}

{% if redirect_field_value %} {% endif %} -
{{ form.username |as_crispy_field }}
@@ -30,7 +29,7 @@

{% trans "Sign Up" %}

{{ form.terms |as_crispy_field }} - {% trans 'I accept the follwoing' %} + {% trans 'I accept the following' %} {% if TERMS_URL != '' %} {% trans 'Terms and Conditions' %} diff --git a/recipes/settings.py b/recipes/settings.py index 1546b320a7..4019533969 100644 --- a/recipes/settings.py +++ b/recipes/settings.py @@ -66,7 +66,6 @@ }, } - # allow djangos wsgi server to server mediafiles GUNICORN_MEDIA = bool(int(os.getenv('GUNICORN_MEDIA', False))) @@ -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', @@ -294,7 +293,6 @@ "handlers": ["console"] } - AUTHENTICATION_BACKENDS += [ 'django.contrib.auth.backends.ModelBackend', 'allauth.account.auth_backends.AuthenticationBackend', @@ -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 = {