From a60feec631c700f85c51ab251b71139d9517ef39 Mon Sep 17 00:00:00 2001 From: Stefano Alberto Russo <stefano.russo@gmail.com> Date: Mon, 15 Nov 2021 19:39:18 +0100 Subject: [PATCH] Added switch for disabling local auth. --- .../webapp/code/rosetta/context_processors.py | 8 +++++++- .../rosetta/core_app/templates/navigation.html | 18 +++++++++++++++--- services/webapp/code/rosetta/settings.py | 4 +++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/services/webapp/code/rosetta/context_processors.py b/services/webapp/code/rosetta/context_processors.py index 67c4435..0d563a3 100644 --- a/services/webapp/code/rosetta/context_processors.py +++ b/services/webapp/code/rosetta/context_processors.py @@ -8,7 +8,13 @@ def export_vars(request): data['OPENID_ENABLED'] = True else: data['OPENID_ENABLED'] = False - + + # Set local auth enabled or not + if settings.DISABLE_LOCAL_AUTH: + data['LOCAL_AUTH_ENABLED'] = False + else: + data['LOCAL_AUTH_ENABLED'] = True + # Set invitation code required or not if settings.INVITATION_CODE: data['INVITATION_CODE_ENABLED'] = True diff --git a/services/webapp/code/rosetta/core_app/templates/navigation.html b/services/webapp/code/rosetta/core_app/templates/navigation.html index 3004bdb..ecc8fbf 100644 --- a/services/webapp/code/rosetta/core_app/templates/navigation.html +++ b/services/webapp/code/rosetta/core_app/templates/navigation.html @@ -36,6 +36,9 @@ <a href="/account" onclick = $("#menu-close").click(); >Account</a> </li> {% else %} + + + {% if LOCAL_AUTH_ENABLED %} <li> <center> <form class="form-signin" role="form" action='/login/' method='POST'> @@ -44,19 +47,28 @@ <input type="password" class="form-control" placeholder="Password" name='password'> <input type='submit' class="btn btn-lg ha-btn-lg" value='Login' /> </form> - {% if OPENID %} - {% endif %} </center> </li> + + {% if OPENID_ENABLED %} + <center><div style="margin-top:15px;margin-bottom:10px"><font color="#a9a9a9"> — OR —</font></div></center> + {% endif %} + + {% endif %} <center> {% if OPENID_ENABLED %} - <div style="margin-top:15px;margin-bottom:10px"><font color="#a9a9a9"> — OR —</font></div> + {% if LOCAL_AUTH_ENABLED %} <li style="padding-left:0; text-indent: 0"> <a href="{% url 'oidc_authentication_init' %}" style="padding-left:0; text-indent: 0">Login with OpenID Connect</a></li> + {% else %} + <li style="padding-left:0; text-indent: 0"> <a href="{% url 'oidc_authentication_init' %}" style="padding-left:0; text-indent: 0">Login</a></li> {% endif %} + {% endif %} + {% if LOCAL_AUTH_ENABLED %} <div style="padding:10px;"> <font color="gray">Forgot password? Just leave it empty to get a login link by email. Or, <a href="/register" style="color: #c0c0c0" onclick = $("#menu-close").click(); >Register</a>.</font> </div> + {% endif %} </center> {% endif %} diff --git a/services/webapp/code/rosetta/settings.py b/services/webapp/code/rosetta/settings.py index 464cd04..b774e15 100644 --- a/services/webapp/code/rosetta/settings.py +++ b/services/webapp/code/rosetta/settings.py @@ -235,7 +235,9 @@ INVITATION_CODE = os.environ.get('INVITATION_CODE', None) # Auth #=============================== -OIDC_RP_CLIENT_ID = os.environ.get('OIDC_RP_CLIENT_ID', None) +DISABLE_LOCAL_AUTH = booleanize(os.environ.get('DISABLE_LOCAL_AUTH', False)) + +OIDC_RP_CLIENT_ID = os.environ.get('OIDC_RP_CLIENT_ID', None) if OIDC_RP_CLIENT_ID: -- GitLab