mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
settings for auto-fill on sso
This commit is contained in:
parent
e380f94e01
commit
1f03d43b92
@ -14,6 +14,7 @@ from crispy_forms.layout import Layout, Field
|
|||||||
from crispy_forms.bootstrap import PrependedText, AppendedText, PrependedAppendedText, StrictButton, Div
|
from crispy_forms.bootstrap import PrependedText, AppendedText, PrependedAppendedText, StrictButton, Div
|
||||||
|
|
||||||
from allauth.account.forms import SignupForm
|
from allauth.account.forms import SignupForm
|
||||||
|
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
|
||||||
|
|
||||||
from part.models import PartCategory
|
from part.models import PartCategory
|
||||||
from common.models import InvenTreeSetting
|
from common.models import InvenTreeSetting
|
||||||
@ -208,7 +209,7 @@ class SettingCategorySelectForm(forms.ModelForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# override allauth forms
|
# override allauth
|
||||||
class CustomSignupForm(SignupForm):
|
class CustomSignupForm(SignupForm):
|
||||||
"""
|
"""
|
||||||
Override to use dynamic settings
|
Override to use dynamic settings
|
||||||
@ -216,3 +217,13 @@ class CustomSignupForm(SignupForm):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
kwargs['email_required'] = InvenTreeSetting.get_setting('LOGIN_MAIL_REQUIRED')
|
kwargs['email_required'] = InvenTreeSetting.get_setting('LOGIN_MAIL_REQUIRED')
|
||||||
super().__init__(*args, **kwargs)
|
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
|
||||||
|
@ -664,6 +664,8 @@ for app in SOCIAL_BACKENDS:
|
|||||||
# settings for allauth
|
# settings for allauth
|
||||||
ACCOUNT_LOGOUT_ON_PASSWORD_CHANGE = True
|
ACCOUNT_LOGOUT_ON_PASSWORD_CHANGE = True
|
||||||
|
|
||||||
|
|
||||||
|
# override forms / adapters
|
||||||
ACCOUNT_FORMS = {
|
ACCOUNT_FORMS = {
|
||||||
'login': 'allauth.account.forms.LoginForm',
|
'login': 'allauth.account.forms.LoginForm',
|
||||||
'signup': 'InvenTree.forms.CustomSignupForm',
|
'signup': 'InvenTree.forms.CustomSignupForm',
|
||||||
@ -674,3 +676,5 @@ ACCOUNT_FORMS = {
|
|||||||
'reset_password_from_key': 'allauth.account.forms.ResetPasswordKeyForm',
|
'reset_password_from_key': 'allauth.account.forms.ResetPasswordKeyForm',
|
||||||
'disconnect': 'allauth.socialaccount.forms.DisconnectForm',
|
'disconnect': 'allauth.socialaccount.forms.DisconnectForm',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SOCIALACCOUNT_ADAPTER = 'InvenTree.forms.CustomSocialAccountAdapter'
|
||||||
|
@ -852,6 +852,12 @@ class InvenTreeSetting(BaseInvenTreeSetting):
|
|||||||
'default': False,
|
'default': False,
|
||||||
'validator': bool,
|
'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:
|
class Meta:
|
||||||
|
@ -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_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_ENABLE_PWD_FORGOT" icon="fa-info-circle" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="LOGIN_MAIL_REQUIRED" 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>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user