diff --git a/configuration/env.js b/configuration/env.js index 3d4a67ec..12089203 100644 --- a/configuration/env.js +++ b/configuration/env.js @@ -104,6 +104,8 @@ function getClientEnvironment(publicUrl) { PORT: process.env.PORT, ENABLE_MMGIS_WEBSOCKETS: process.env.ENABLE_MMGIS_WEBSOCKETS, MAIN_MISSION: process.env.MAIN_MISSION, + THIRD_PARTY_COOKIES: process.env.THIRD_PARTY_COOKIES || "", + SKIP_CLIENT_INITIAL_LOGIN: process.env.SKIP_CLIENT_INITIAL_LOGIN || "", } ); // Stringify all values so we can feed into webpack DefinePlugin diff --git a/docs/pages/APIs/JavaScript/Main/Main.md b/docs/pages/APIs/JavaScript/Main/Main.md index f87be052..a1610a7c 100644 --- a/docs/pages/APIs/JavaScript/Main/Main.md +++ b/docs/pages/APIs/JavaScript/Main/Main.md @@ -54,6 +54,7 @@ The `src/essence/mmgisAPI/mmgisAPI.js` file exposes functions that can be called - [writeCoordinateURL()](#writecoordinateurl) - [onLoaded(onLoadCallback)](#onloadedonloadcallback) - [getActiveTool()](#getactivetool) + - [setLoginToken(username, token)](#setlogintoken) - [project(lnglat)](#projectlnglat) - [unproject(xy)](#unprojectxy) @@ -821,6 +822,16 @@ The following is an example of how to call the `getActiveTool` function: window.mmgisAPI.getActiveTool(); ``` +### initialLogin() + +Performs the initial login call to relogin returning users. Pairable with the ENV `SKIP_CLIENT_INITIAL_LOGIN=`. + +The following is an example of how to call the `initialLogin` function: + +```javascript +window.mmgisAPI.initialLogin(); +``` + ### project(lnglat) This function convert a Longitude, Latitude object into X, Y (i.e. Easting, Northing) coordinates. It uses the map's base projection and the proj4 library to perform the transformation. @@ -851,47 +862,48 @@ This function can be used to overwrite the contents displayed in the LegendTool. #### Function parameters -- `legends` - An array of objects, where each object must contain the following keys: legend, layerUUID, display_name, opacity. The value for the legend key should be in the same format as what is stored in the layers data under the `_legend` key (i.e. `L_.layers.data[layerName]._legend`). layerUUID and display_name should be strings and opacity should be a number between 0 and 1. +- `legends` - An array of objects, where each object must contain the following keys: legend, layerUUID, display*name, opacity. The value for the legend key should be in the same format as what is stored in the layers data under the `_legend` key (i.e. `L*.layers.data[layerName].\_legend`). layerUUID and display_name should be strings and opacity should be a number between 0 and 1. The following is an example of how to call the `overwriteLegends` function: + ```javascript const legends = [ - { - color: '#00e400', - strokecolor: '#000000', - shape: 'continuous', - value: '0 - 54', - }, - { - color: '#ffff00', - strokecolor: '#000000', - shape: 'continuous', - value: '54 - 154', - }, - { - color: '#ff7e00', - strokecolor: '#000000', - shape: 'continuous', - value: '154 - 254', - }, - { - color: '#8f3f97', - strokecolor: '#000000', - shape: 'continuous', - value: '254 - 354', - }, - { - color: '#8f3f97', - strokecolor: '#000000', - shape: 'continuous', - value: '354 - 424', - }, - { - color: '#7e0023', - strokecolor: '#000000', - shape: 'continuous', - value: '> 424', - }, + { + color: "#00e400", + strokecolor: "#000000", + shape: "continuous", + value: "0 - 54", + }, + { + color: "#ffff00", + strokecolor: "#000000", + shape: "continuous", + value: "54 - 154", + }, + { + color: "#ff7e00", + strokecolor: "#000000", + shape: "continuous", + value: "154 - 254", + }, + { + color: "#8f3f97", + strokecolor: "#000000", + shape: "continuous", + value: "254 - 354", + }, + { + color: "#8f3f97", + strokecolor: "#000000", + shape: "continuous", + value: "354 - 424", + }, + { + color: "#7e0023", + strokecolor: "#000000", + shape: "continuous", + value: "> 424", + }, ]; window.mmgisAPI.overwriteLegends(legends); diff --git a/docs/pages/Setup/ENVs/ENVs.md b/docs/pages/Setup/ENVs/ENVs.md index 7aa253f7..a8a90cd8 100644 --- a/docs/pages/Setup/ENVs/ENVs.md +++ b/docs/pages/Setup/ENVs/ENVs.md @@ -131,3 +131,7 @@ For use when `ENABLE_CONFIG_WEBSOCKETS=true` (if `ENABLE_CONFIG_WEBSOCKETS=false #### `MAIN_MISSION=` If the new MAIN_MISSION ENV is set to a valid mission, skip the landing page and go straight to that mission. Other missions will still be accessible by either forcing the landing page (clicking the top-left M logo) or by going to a link directly. | string | default `''` + +#### `SKIP_CLIENT_INITIAL_LOGIN=` + +If true, MMGIS will not auto-login returning users. This can be useful when login is managed someplace else. The initial login process can be manually triggered with `mmgisAPI.initialLogin()` | boolean | default `false` diff --git a/public/index.html b/public/index.html index 6a39d4ed..04d81a1b 100644 --- a/public/index.html +++ b/public/index.html @@ -338,7 +338,8 @@ mmgisglobal.ROOT_PATH = "#{ROOT_PATH}"; mmgisglobal.WEBSOCKET_ROOT_PATH = "#{WEBSOCKET_ROOT_PATH}"; mmgisglobal.ENABLE_MMGIS_WEBSOCKETS = "#{ENABLE_MMGIS_WEBSOCKETS}"; - mmgisglobal.MAIN_MISSION = "#{MAIN_MISSION}" + mmgisglobal.MAIN_MISSION = "#{MAIN_MISSION}"; + mmgisglobal.SKIP_CLIENT_INITIAL_LOGIN = "#{SKIP_CLIENT_INITIAL_LOGIN}"; mmgisglobal.THIRD_PARTY_COOKIES = "#{THIRD_PARTY_COOKIES}"; break; default: @@ -355,6 +356,7 @@ mmgisglobal.WEBSOCKET_ROOT_PATH = "%WEBSOCKET_ROOT_PATH%"; mmgisglobal.ENABLE_MMGIS_WEBSOCKETS = "%ENABLE_MMGIS_WEBSOCKETS%"; mmgisglobal.MAIN_MISSION = "%MAIN_MISSION%"; + mmgisglobal.SKIP_CLIENT_INITIAL_LOGIN = "%SKIP_CLIENT_INITIAL_LOGIN%"; mmgisglobal.THIRD_PARTY_COOKIES = "%THIRD_PARTY_COOKIES%"; // eslint-disable-next-line mmgisglobal.HOSTS = %HOSTS%; diff --git a/sample.env b/sample.env index 3f0b3aa6..4fbaed43 100644 --- a/sample.env +++ b/sample.env @@ -72,4 +72,8 @@ ENABLE_CONFIG_OVERRIDE=false # If the new MAIN_MISSION ENV is set to a valid mission, skip the landing page and go straight to that mission. # Other missions will still be accessible by either forcing the landing page (clicking the top-left M logo) or by going to a link directly. -MAIN_MISSION= \ No newline at end of file +MAIN_MISSION= + +# If true, MMGIS will not auto-login returning users. This can be useful when login is managed someplace else. +# The initial login process can be manually triggered with mmgisAPI.initialLogin() +SKIP_CLIENT_INITIAL_LOGIN= \ No newline at end of file diff --git a/scripts/server.js b/scripts/server.js index 3fd8cd40..05969d24 100644 --- a/scripts/server.js +++ b/scripts/server.js @@ -764,6 +764,7 @@ setups.getBackendSetups(function (setups) { CLEARANCE_NUMBER: process.env.CLEARANCE_NUMBER, ENABLE_MMGIS_WEBSOCKETS: process.env.ENABLE_MMGIS_WEBSOCKETS, MAIN_MISSION: process.env.MAIN_MISSION, + SKIP_CLIENT_INITIAL_LOGIN: process.env.SKIP_CLIENT_INITIAL_LOGIN, THIRD_PARTY_COOKIES: process.env.THIRD_PARTY_COOKIES, PORT: process.env.PORT, ROOT_PATH: ROOT_PATH, diff --git a/src/essence/Ancillary/Login/Login.js b/src/essence/Ancillary/Login/Login.js index 9451aef4..b495f465 100644 --- a/src/essence/Ancillary/Login/Login.js +++ b/src/essence/Ancillary/Login/Login.js @@ -221,29 +221,33 @@ var Login = { : 'mdi mdi-login mdi-18px' ) - //Sign in at page load from cookie if possible + // Sign in at page load from cookie if possible if ( window.mmgisglobal.AUTH !== 'off' && - window.mmgisglobal.AUTH !== 'csso' + window.mmgisglobal.AUTH !== 'csso' && + window.mmgisglobal.SKIP_CLIENT_INITIAL_LOGIN != 'true' ) { - calls.api( - 'login', - { - useToken: true, - }, - function (d) { - Login.username = d.username - window.mmgisglobal.user = Login.username - window.mmgisglobal.groups = d.groups - - loginSuccess(d) - }, - function (d) { - loginSuccess(d, true) - } - ) + Login.initialLogin() } }, + initialLogin() { + calls.api( + 'login', + { + useToken: true, + }, + function (d) { + Login.username = d.username + window.mmgisglobal.user = Login.username + window.mmgisglobal.groups = d.groups + + loginSuccess(d) + }, + function (d) { + loginSuccess(d, true) + } + ) + }, createModal: function () { this.removeModal() diff --git a/src/essence/Tools/Info/InfoTool.js b/src/essence/Tools/Info/InfoTool.js index b2aec2a3..03ed0ace 100644 --- a/src/essence/Tools/Info/InfoTool.js +++ b/src/essence/Tools/Info/InfoTool.js @@ -3,9 +3,6 @@ import * as d3 from 'd3' import F_ from '../../Basics/Formulae_/Formulae_' import L_ from '../../Basics/Layers_/Layers_' import Map_ from '../../Basics/Map_/Map_' -import Globe_ from '../../Basics/Globe_/Globe_' -import Login from '../../Ancillary/Login/Login' -import CursorInfo from '../../Ancillary/CursorInfo' import { Kinds } from '../../../pre/tools' import Dropy from '../../../external/Dropy/dropy' diff --git a/src/essence/mmgisAPI/mmgisAPI.js b/src/essence/mmgisAPI/mmgisAPI.js index 6a171dbc..5691418e 100644 --- a/src/essence/mmgisAPI/mmgisAPI.js +++ b/src/essence/mmgisAPI/mmgisAPI.js @@ -3,6 +3,7 @@ import F_ from '../Basics/Formulae_/Formulae_' import ToolController_ from '../Basics/ToolController_/ToolController_' import QueryURL from '../Ancillary/QueryURL' import TimeControl from '../Ancillary/TimeControl' +import Login from '../Ancillary/Login/Login' import LegendTool from '../Tools/Legend/LegendTool.js' import $ from 'jquery' @@ -674,6 +675,10 @@ var mmgisAPI = { */ onLoaded: mmgisAPI_.onLoaded, + /** initialLogin: performs the initial login call to relogin returning users. Pairable with the ENV `SKIP_CLIENT_INITIAL_LOGIN=`. + */ + initialLogin: Login.initialLogin, + /** project - converts a lnglat into xy coordinates with the current (custom or default web mercator) proj4 definition * @param {object} {lng: 0, lat: 0} - lnglat to convert * @returns {object} {x: 0, y: 0} - converted easting northing xy