Skip to content

Commit

Permalink
#386 Local Login Issue (#396)
Browse files Browse the repository at this point in the history
* #386 Add setLoginToken to mmgisAPI

* #386 Fix variable path

* #386 SKIP_CLIENT_INITIAL_LOGIN env + mmgisAPI.initialLogin
  • Loading branch information
tariqksoliman committed Jul 13, 2023
1 parent eb10fc4 commit d8c8ea7
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 60 deletions.
2 changes: 2 additions & 0 deletions configuration/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
86 changes: 49 additions & 37 deletions docs/pages/APIs/JavaScript/Main/Main.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions docs/pages/Setup/ENVs/ENVs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
4 changes: 3 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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%;
Expand Down
6 changes: 5 additions & 1 deletion sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -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=
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=
1 change: 1 addition & 0 deletions scripts/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
40 changes: 22 additions & 18 deletions src/essence/Ancillary/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 0 additions & 3 deletions src/essence/Tools/Info/InfoTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
5 changes: 5 additions & 0 deletions src/essence/mmgisAPI/mmgisAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d8c8ea7

Please sign in to comment.