2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-30 20:46:47 +00:00

[SSO] Separate settings for local and social signup (#4171)

* [SSO] Separate settings for local and social signup
Fixes #4166

* make registration setting configruable

* extend docstring

* add setting to settigns screen

* update check ref

* both settign most be checked
This commit is contained in:
Matthias Mair 2023-01-09 14:20:05 +01:00 committed by GitHub
parent 0ed2aa3a4d
commit ac92471dcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 5 deletions

View File

@ -210,8 +210,11 @@ class RegistratonMixin:
"""Mixin to check if registration should be enabled."""
def is_open_for_signup(self, request, *args, **kwargs):
"""Check if signup is enabled in settings."""
if settings.EMAIL_HOST and InvenTreeSetting.get_setting('LOGIN_ENABLE_REG', True):
"""Check if signup is enabled in settings.
Configure the class variable `REGISTRATION_SETTING` to set which setting should be used, defualt: `LOGIN_ENABLE_REG`.
"""
if settings.EMAIL_HOST and (InvenTreeSetting.get_setting('LOGIN_ENABLE_REG') or InvenTreeSetting.get_setting('LOGIN_ENABLE_SSO_REG')):
return super().is_open_for_signup(request, *args, **kwargs)
return False

View File

@ -1375,6 +1375,13 @@ class InvenTreeSetting(BaseInvenTreeSetting):
'validator': bool,
},
'LOGIN_ENABLE_SSO_REG': {
'name': _('Enable SSO registration'),
'description': _('Enable self-registration via SSO for users on the login pages'),
'default': False,
'validator': bool,
},
'LOGIN_MAIL_REQUIRED': {
'name': _('Email required'),
'description': _('Require user to supply mail on signup'),

View File

@ -27,6 +27,7 @@
<td colspan='4'></td>
</tr>
{% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_REG" icon="fa-user-plus" %}
{% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_SSO_REG" icon="fa-user-plus" %}
{% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_MAIL_TWICE" icon="fa-at" %}
{% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_PWD_TWICE" icon="fa-user-lock" %}
{% include "InvenTree/settings/setting.html" with key="SIGNUP_GROUP" icon="fa-users" %}

View File

@ -6,7 +6,7 @@
{% block content %}
{% settings_value 'LOGIN_ENABLE_REG' as enable_reg %}
{% settings_value 'LOGIN_ENABLE_SSO' as enable_sso %}
{% settings_value 'LOGIN_ENABLE_SSO_REG' as enable_sso %}
<h3>{% trans "Sign Up" %}</h3>
@ -21,17 +21,18 @@
{% endif %}
<button type="submit" class="btn btn-primary btn-block">{% trans "Sign Up" %}</button>
</form>
{% endif %}
{% if enable_sso %}
<br>
<h4>{% trans 'Or use a SSO-provider for signup' %}</h4>
<h4>{% trans 'Use a SSO-provider for signup' %}</h4>
<div>
{% include "socialaccount/snippets/provider_list.html" with process="login" %}
</div>
{% include "socialaccount/snippets/login_extra.html" %}
{% endif %}
{% else %}
{% if not enable_reg and not enable_sso %}
<div class='alert alert-block alert-danger'>
<p>{% trans "This function is currently disabled. Please contact an administrator." %}</p>
</div>