diff --git a/InvenTree/InvenTree/forms.py b/InvenTree/InvenTree/forms.py index 228eda7a3c..5cdba32014 100644 --- a/InvenTree/InvenTree/forms.py +++ b/InvenTree/InvenTree/forms.py @@ -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) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index f5d6ce9689..5f2323d986 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -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', +} diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 74d6b02f2f..25f360c0a0 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -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: diff --git a/InvenTree/templates/InvenTree/settings/login.html b/InvenTree/templates/InvenTree/settings/login.html index b3758aadf6..c13155a5ae 100644 --- a/InvenTree/templates/InvenTree/settings/login.html +++ b/InvenTree/templates/InvenTree/settings/login.html @@ -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" %}