setting to make mail required on signup

This commit is contained in:
Matthias 2021-09-06 22:07:50 +02:00
parent 3963ece6d2
commit a4209d38cc
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
4 changed files with 32 additions and 1 deletions

View File

@ -13,8 +13,10 @@ from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Field
from crispy_forms.bootstrap import PrependedText, AppendedText, PrependedAppendedText, StrictButton, Div
from part.models import PartCategory
from allauth.account.forms import SignupForm
from part.models import PartCategory
from common.models import InvenTreeSetting
class HelperForm(forms.ModelForm):
""" Provides simple integration of crispy_forms extension. """
@ -203,3 +205,13 @@ class SettingCategorySelectForm(forms.ModelForm):
css_class='row',
),
)
# override allauth forms
class CustomSignupForm(SignupForm):
"""
Override to use dynamic settings
"""
def __init__(self, *args, **kwargs):
kwargs['email_required'] = InvenTreeSetting.get_setting('LOGIN_MAIL_REQUIRED')
super().__init__(*args, **kwargs)

View File

@ -660,3 +660,15 @@ SITE_ID = 1
SOCIAL_BACKENDS = CONFIG.get('social_backends', [])
for app in SOCIAL_BACKENDS:
INSTALLED_APPS.append(app)
# settings for allauth
ACCOUNT_FORMS = {
'login': 'allauth.account.forms.LoginForm',
'signup': 'InvenTree.forms.CustomSignupForm',
'add_email': 'allauth.account.forms.AddEmailForm',
'change_password': 'allauth.account.forms.ChangePasswordForm',
'set_password': 'allauth.account.forms.SetPasswordForm',
'reset_password': 'allauth.account.forms.ResetPasswordForm',
'reset_password_from_key': 'allauth.account.forms.ResetPasswordKeyForm',
'disconnect': 'allauth.socialaccount.forms.DisconnectForm',
}

View File

@ -846,6 +846,12 @@ class InvenTreeSetting(BaseInvenTreeSetting):
'default': False,
'validator': bool,
},
'LOGIN_MAIL_REQUIRED': {
'name': _('E-Mail required'),
'description': _('Require user to supply mail on signup'),
'default': False,
'validator': bool,
},
}
class Meta:

View File

@ -17,6 +17,7 @@
{% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_REG" icon="fa-info-circle" %}
{% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_SSO" icon="fa-info-circle" %}
{% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_PWD_FORGOT" icon="fa-info-circle" %}
{% include "InvenTree/settings/setting.html" with key="LOGIN_MAIL_REQUIRED" icon="fa-info-circle" %}
</tbody>
</table>