Skip to content
Snippets Groups Projects

Issue #3417218 by Grimreaper: Enable Gitlab CI + Update README + Coding standards

7 files
+ 140
72
Compare changes
  • Side-by-side
  • Inline
Files
7
+ 27
26
@@ -5,12 +5,9 @@
* If so, it logs in user on current website and reload page.
*/
(function (Drupal, drupalSettings, once) {
'use strict';
((Drupal, drupalSettings, once) => {
Drupal.behaviors.i18n_sso = Drupal.behaviors.i18n_sso || {};
Drupal.behaviors.i18n_sso.attach = function (context) {
Drupal.behaviors.i18n_sso.attach = (context) => {
Drupal.behaviors.i18n_sso.initLogin(context);
};
@@ -23,31 +20,33 @@
* @param {HTMLDocument|HTMLElement} context
* An element to use as context for querySelectorAll.
*/
Drupal.behaviors.i18n_sso.initLogin = function (context) {
once('i18n_sso', drupalSettings.i18n_sso.wrapperSelector, context).forEach(function (element) {
var div = document.createElement('div');
div.setAttribute('id', 'sso-waiting');
div.innerHTML = drupalSettings.i18n_sso.waiting;
element.insertBefore(div, element.firstChild);
Drupal.behaviors.i18n_sso.getToken();
});
Drupal.behaviors.i18n_sso.initLogin = (context) => {
once('i18n_sso', drupalSettings.i18n_sso.wrapperSelector, context).forEach(
(element) => {
const div = document.createElement('div');
div.setAttribute('id', 'sso-waiting');
div.innerHTML = drupalSettings.i18n_sso.waiting;
element.insertBefore(div, element.firstChild);
Drupal.behaviors.i18n_sso.getToken();
},
);
};
/**
* Retrieves token on configured url and calls the useToken function.
*/
Drupal.behaviors.i18n_sso.getToken = function () {
var xhr = new XMLHttpRequest();
Drupal.behaviors.i18n_sso.getToken = () => {
const xhr = new XMLHttpRequest();
xhr.open('POST', drupalSettings.i18n_sso.ssoUrl);
xhr.withCredentials = true;
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function () {
xhr.onload = () => {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
const data = JSON.parse(xhr.responseText);
Drupal.behaviors.i18n_sso.useToken(data);
}
};
xhr.send('origin=' + encodeURIComponent(window.location.origin));
xhr.send(`origin=${encodeURIComponent(window.location.origin)}`);
};
/**
@@ -58,26 +57,28 @@
* @param {object} data
* The data retrieved from the SSO URL endpoint.
*/
Drupal.behaviors.i18n_sso.useToken = function (data) {
var waitingElement = document.getElementById('sso-waiting');
Drupal.behaviors.i18n_sso.useToken = (data) => {
const waitingElement = document.getElementById('sso-waiting');
if (waitingElement) {
waitingElement.innerHTML = data.message;
if (data.token !== false) {
var xhr = new XMLHttpRequest();
const xhr = new XMLHttpRequest();
xhr.open('POST', drupalSettings.i18n_sso.ssoLogin);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function () {
xhr.setRequestHeader(
'Content-Type',
'application/x-www-form-urlencoded',
);
xhr.onload = () => {
if (xhr.status === 200) {
var loginData = JSON.parse(xhr.responseText);
const loginData = JSON.parse(xhr.responseText);
waitingElement.innerHTML = loginData.message;
if (loginData.success === true) {
window.location.reload();
}
}
};
xhr.send('token=' + encodeURIComponent(data.token));
xhr.send(`token=${encodeURIComponent(data.token)}`);
}
}
};
})(Drupal, drupalSettings, once);
Loading