Skip to content

Commit

Permalink
Add configuration option for a login hint text
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Jan 15, 2024
1 parent e9c1ccc commit 92500c8
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 6 deletions.
48 changes: 48 additions & 0 deletions schemas/qwc-ldap-auth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/qwc-services/qwc-ldap-auth/master/schemas/qwc-ldap-auth.json",
"title": "QWC LDAP authentication service",
"type": "object",
"properties": {
"$schema": {
"title": "JSON Schema",
"description": "Reference to JSON schema of this config",
"type": "string",
"format": "uri",
"default": "https://raw.githubusercontent.com/qwc-services/qwc-ldap-auth/master/schemas/qwc-ldap-auth.json"
},
"service": {
"title": "Service name",
"type": "string",
"const": "ldap-auth"
},
"config": {
"title": "Config options",
"type": "object",
"properties": {
"login_hint":{
"description": "Login hint text, shown above login form fields. Either a string, or dictionary `{\"<lang>\": \"<text>\"}`. When providing a dictionary, the entry matching the current locale will be searched, with fallback to `en` if no entry for the current locale exists, and fallback to an empty string if no `en` entry exists.",
"type": {
"oneOf":[
{"type": "string"},
{
"type": "object",
"patternProperties": {
"^[a-z]{2}$": {
"type": "string"
}
}
}
]
}
}
},
"required": [
]
}
},
"required": [
"service",
"config"
]
}
23 changes: 17 additions & 6 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import i18n
from qwc_services_core.jwt import jwt_manager
from qwc_services_core.auth import GroupNameMapper
from qwc_services_core.runtime_config import RuntimeConfig
from qwc_services_core.tenant_handler import (
TenantHandler, TenantPrefixMiddleware, TenantSessionInterface)

Expand Down Expand Up @@ -115,12 +116,10 @@
ldap_manager = LDAP3LoginManager(app) # Setup a LDAP3 Login Manager.


if os.environ.get('TENANT_HEADER'):
app.wsgi_app = TenantPrefixMiddleware(
app.wsgi_app, os.environ.get('TENANT_HEADER'))
tenant_handler = TenantHandler(app.logger)

if os.environ.get('TENANT_HEADER') or os.environ.get('TENANT_URL_RE'):
app.session_interface = TenantSessionInterface(os.environ)
app.wsgi_app = TenantPrefixMiddleware(app.wsgi_app)
app.session_interface = TenantSessionInterface(os.environ)


# Create a dictionary to store the users in when they authenticate.
Expand Down Expand Up @@ -209,6 +208,10 @@ def home():

@app.route('/login', methods=['GET', 'POST'])
def login():
config_handler = RuntimeConfig("ldapAuth", app.logger)
tenant = tenant_handler.tenant()
config = config_handler.tenant_config(tenant)

target_url = url_path(request.args.get('url', '/'))
if current_user.is_authenticated:
return redirect(target_url)
Expand Down Expand Up @@ -239,8 +242,16 @@ def login():
errors.remove('Invalid Username/Password.')
errors.append(i18n.t('auth.auth_failed'))

login_hint = config.get('login_hint')
if isinstance(login_hint, dict):
login_hint = login_hint.get(
i18n.get('locale'),
login_hint.get('en', '')
)

return render_template('login.html', form=form, i18n=i18n,
title=i18n.t("auth.login_page_title"))
title=i18n.t("auth.login_page_title"),
login_hint=login_hint)


@app.route('/verify_login', methods=['POST'])
Expand Down
5 changes: 5 additions & 0 deletions src/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ input:focus {
display: block;
margin-top: 12px;
}

.login-hint {
text-align: left;
font-size: 14px;
}
5 changes: 5 additions & 0 deletions src/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ <h1>{{ i18n.t('auth.login_form_title') }}</h1>
</div>

<div class="login-form">
{% if login_hint != "" and login_hint != None %}
<div class="control-group login-hint">
<span>{{ login_hint }}</span>
</div>
{% endif %}
<div class="control-group">
<input type="text" class="login-field" value=""
placeholder="{{ i18n.t('auth.username_placeholder') }}" name="username" autofocus="">
Expand Down

0 comments on commit 92500c8

Please sign in to comment.