Skip to content

Commit

Permalink
#558: Use js to fetch 4xx logout url
Browse files Browse the repository at this point in the history
  • Loading branch information
jekuaitk committed Jan 23, 2024
1 parent 4757a4b commit 96d50bf
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Nedenfor ses dato for release og beskrivelse af opgaver som er implementeret.

* Opdaterede til [OS2Forms Organisation
2.0.1](https://github.com/itk-dev/os2forms_organisation/releases/tag/2.0.1).
* Opdaterede 4xx page logout link

## [2.7.3] 2024-01-16

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ environment, as its data contains personal data.

If developers need an actual database for local development, the stg-environment
can be made ready for download by ensuring that you delete all submissions and
other informations that can have personal character, before downloading.
other information that can have personal character, before downloading.

## Coding standards

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
window.addEventListener('load', function () {
const elem = document.getElementById('logout_suggestion')
let url = elem.getAttribute('href')
url = replaceUrlParam(url, 'destination', window.location.pathname)
elem.setAttribute('href', url)
}, false)

// @see https://stackoverflow.com/a/20420424
function replaceUrlParam (url, paramName, paramValue) {
if (paramValue == null) {
paramValue = ''
}
const pattern = new RegExp('\\b(' + paramName + '=).*?(&|#|$)')
if (url.search(pattern) >= 0) {
return url.replace(pattern, '$1' + paramValue + '$2')
}
url = url.replace(/[?#]$/, '')
return url + (url.indexOf('?') > 0 ? '&' : '?') + paramName + '=' + paramValue
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ global-styling:
css:
theme:
build/app.css: {}

logout-suggestion:
version: 1.x
js:
assets/logout-suggestion.js: {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
function os2forms_selvbetjening_theme_preprocess_page(&$variables): void {
$variables['site_logo'] = theme_get_setting('logo.url');
$variables['site_name'] = \Drupal::config('system.site')->get('name');
$variables['request_uri'] = \Drupal::service('request_stack')->getCurrentRequest()->getRequestUri();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

{# Content #}
{% block page_content %}
{{ attach_library('os2forms_selvbetjening_theme/logout-suggestion') }}

{{ page.content }}
{% if logged_in %}
<p>
{% set url = path('user.logout', {destination: request_uri}) %}
{{ 'Here is a suggestion to what you can do. Try to log out of <a href=":url">@siteName</a>'|t({':url': url, '@siteName': site_name}) }}
{% set url = path('user.logout') %}
{{ 'Here is a suggestion to what you can do. Try to log out of <a id="logout_suggestion" href=":url">@siteName</a>'|t({':url': url, '@siteName': site_name}) }}
</p>
{% endif %}
{% endblock %}

0 comments on commit 96d50bf

Please sign in to comment.