settings for auto-fill on sso

This commit is contained in:
Matthias 2021-09-07 01:19:44 +02:00
parent e380f94e01
commit 1f03d43b92
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
4 changed files with 27 additions and 1 deletions

View File

@ -14,6 +14,7 @@ from crispy_forms.layout import Layout, Field
from crispy_forms.bootstrap import PrependedText, AppendedText, PrependedAppendedText, StrictButton, Div
from allauth.account.forms import SignupForm
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
from part.models import PartCategory
from common.models import InvenTreeSetting
@ -208,7 +209,7 @@ class SettingCategorySelectForm(forms.ModelForm):
)
# override allauth forms
# override allauth
class CustomSignupForm(SignupForm):
"""
Override to use dynamic settings
@ -216,3 +217,13 @@ class CustomSignupForm(SignupForm):
def __init__(self, *args, **kwargs):
kwargs['email_required'] = InvenTreeSetting.get_setting('LOGIN_MAIL_REQUIRED')
super().__init__(*args, **kwargs)
class CustomSocialAccountAdapter(DefaultSocialAccountAdapter):
"""
Override of adapter to use dynamic settings
"""
def is_auto_signup_allowed(self, request, sociallogin):
if InvenTreeSetting.get_setting('LOGIN_SIGNUP_SSO_AUTO', True):
return super().is_auto_signup_allowed(request, sociallogin)
return False

View File

@ -664,6 +664,8 @@ for app in SOCIAL_BACKENDS:
# settings for allauth
ACCOUNT_LOGOUT_ON_PASSWORD_CHANGE = True
# override forms / adapters
ACCOUNT_FORMS = {
'login': 'allauth.account.forms.LoginForm',
'signup': 'InvenTree.forms.CustomSignupForm',
@ -674,3 +676,5 @@ ACCOUNT_FORMS = {
'reset_password_from_key': 'allauth.account.forms.ResetPasswordKeyForm',
'disconnect': 'allauth.socialaccount.forms.DisconnectForm',
}
SOCIALACCOUNT_ADAPTER = 'InvenTree.forms.CustomSocialAccountAdapter'

View File

@ -852,6 +852,12 @@ class InvenTreeSetting(BaseInvenTreeSetting):
'default': False,
'validator': bool,
},
'LOGIN_SIGNUP_SSO_AUTO': {
'name': _('Auto-fill SSO users'),
'description': _('Automatically fill out user-details from SSO account-data'),
'default': True,
'validator': bool,
},
}
class Meta:

View File

@ -18,6 +18,11 @@
{% 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" %}
<tr>
<td>{% trans 'Signup' %}</td>
<td colspan='4'></td>
</tr>
{% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_SSO_AUTO" icon="fa-info-circle" %}
</tbody>
</table>