From c5ec4098df18aa24bd20d15008d81d6755f437d9 Mon Sep 17 00:00:00 2001 From: irismarie Date: Fri, 11 Dec 2020 14:20:20 +0100 Subject: [PATCH 01/33] select login option --- src/router.js | 4 ++- src/styles/app.css | 20 +++++++++++ src/user/login-select.js | 72 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/user/login-select.js diff --git a/src/router.js b/src/router.js index 05cf900..84aa6f7 100644 --- a/src/router.js +++ b/src/router.js @@ -20,6 +20,7 @@ import { BrowserRouter, Route, Switch } from 'react-router-dom'; import App from './app'; import Login from './user/login'; +import LoginSelect from './user/login-select'; import Logout from './user/logout'; import Home from './common/home'; import Scenarios from './scenario/scenarios'; @@ -34,7 +35,8 @@ class Root extends React.Component { return ( - + + diff --git a/src/styles/app.css b/src/styles/app.css index a2d887d..5ca9250 100644 --- a/src/styles/app.css +++ b/src/styles/app.css @@ -219,6 +219,26 @@ body { background-color: white; } +/** + * Login select + */ + .login-select { + position: sticky; + width: 300px; + height: 200px; + top: 50%; + left: 50%; + margin-top: 50px; + margin-bottom: 100px; + transform: translate(-50%); + + + padding: 20px 20px; + + background-color: #a8c7cf; + box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), + 0 9px 18px 0 rgba(0, 0, 0, 0.1); +} /** * Login form diff --git a/src/user/login-select.js b/src/user/login-select.js new file mode 100644 index 0000000..d8f6178 --- /dev/null +++ b/src/user/login-select.js @@ -0,0 +1,72 @@ +/** + * This file is part of VILLASweb. + * + * VILLASweb is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VILLASweb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VILLASweb. If not, see . + ******************************************************************************/ + +import React, { Component } from 'react'; +import { Form, Button, FormGroup, FormControl, FormLabel, Col } from 'react-bootstrap'; +//import RecoverPassword from './recover-password' +//import AppDispatcher from '../common/app-dispatcher'; +import Header from '../common/header'; +import Footer from '../common/footer'; +import { withRouter } from 'react-router-dom'; + + + +class LoginSelect extends Component { + constructor(props) { + super(props); + + + + this.state = { + standardlogin: true, + keycloaklogin: true, + jupyterlogin: false + } + } + + villaswebLogin = e => { + this.props.history.replace('/login-villas'); + } + + jupyterLogin() { + + } + + + render() { + + return ( +
+
+
+
+ +
+ +
+ +
+
+ +
+ +
+ ); + } +} + +export default withRouter(LoginSelect); From e1dedc66a2e577e40b198103bf49ca4be81c57b0 Mon Sep 17 00:00:00 2001 From: irismarie Date: Thu, 28 Jan 2021 18:53:04 +0100 Subject: [PATCH 02/33] login page based on VillasWeb config --- src/config.js | 5 ++++- src/router.js | 11 +++++++++-- src/styles/app.css | 2 +- src/user/login-select.js | 23 ++--------------------- src/user/logout.js | 13 ++++++++++--- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/config.js b/src/config.js index 874e58f..75fe3a0 100644 --- a/src/config.js +++ b/src/config.js @@ -22,7 +22,10 @@ const config = { admin: { name: 'Institute for Automation of Complex Power Systems (ACS), RWTH Aachen University, Germany', mail: 'stvogel@eonerc.rwth-aachen.de' - } + }, + externalAuth: true, + loginURL: 'http://localhost:4180/oauth2/start', + provider: 'KeyCloak' }; export default config diff --git a/src/router.js b/src/router.js index 84aa6f7..b0c8dd4 100644 --- a/src/router.js +++ b/src/router.js @@ -29,14 +29,21 @@ import Dashboard from './dashboard/dashboard' import InfrastructureComponents from './ic/ics'; import Users from './user/users'; import User from "./user/user"; +import Config from './config.js'; + class Root extends React.Component { render() { return ( - - + ( + + )} + /> + diff --git a/src/styles/app.css b/src/styles/app.css index 5ca9250..3937b0b 100644 --- a/src/styles/app.css +++ b/src/styles/app.css @@ -225,7 +225,7 @@ body { .login-select { position: sticky; width: 300px; - height: 200px; + height: 150px; top: 50%; left: 50%; margin-top: 50px; diff --git a/src/user/login-select.js b/src/user/login-select.js index d8f6178..e6b8d58 100644 --- a/src/user/login-select.js +++ b/src/user/login-select.js @@ -17,8 +17,6 @@ import React, { Component } from 'react'; import { Form, Button, FormGroup, FormControl, FormLabel, Col } from 'react-bootstrap'; -//import RecoverPassword from './recover-password' -//import AppDispatcher from '../common/app-dispatcher'; import Header from '../common/header'; import Footer from '../common/footer'; import { withRouter } from 'react-router-dom'; @@ -26,27 +24,12 @@ import { withRouter } from 'react-router-dom'; class LoginSelect extends Component { - constructor(props) { - super(props); - - - this.state = { - standardlogin: true, - keycloaklogin: true, - jupyterlogin: false - } - } villaswebLogin = e => { - this.props.history.replace('/login-villas'); + this.props.history.replace('/villaslogin'); } - jupyterLogin() { - - } - - render() { return ( @@ -56,9 +39,7 @@ class LoginSelect extends Component {

- -
- +
diff --git a/src/user/logout.js b/src/user/logout.js index 3179a45..a1e4a4c 100644 --- a/src/user/logout.js +++ b/src/user/logout.js @@ -19,6 +19,7 @@ import React from 'react'; import { Redirect } from 'react-router-dom'; import AppDispatcher from '../common/app-dispatcher'; +import Config from '../config.js'; class Logout extends React.Component { componentDidMount() { @@ -34,9 +35,15 @@ class Logout extends React.Component { } render() { - return ( - - ); + if (Config.externalAuth) { + return ( + + ); + } else { + return ( + + ); + } } } From 48a7386736907e1ad66762fe82493eec78a32a3a Mon Sep 17 00:00:00 2001 From: irismarie Date: Wed, 3 Feb 2021 18:05:03 +0100 Subject: [PATCH 03/33] after successful oauth, make backend request, #39 --- src/config.js | 5 ++- src/router.js | 6 ++- src/user/login-complete.js | 70 ++++++++++++++++++++++++++++++++++ src/user/login-select.js | 2 +- src/user/login-store.js | 4 ++ src/user/users-data-manager.js | 35 ++++++++++++----- 6 files changed, 107 insertions(+), 15 deletions(-) create mode 100644 src/user/login-complete.js diff --git a/src/config.js b/src/config.js index 75fe3a0..c911724 100644 --- a/src/config.js +++ b/src/config.js @@ -24,8 +24,9 @@ const config = { mail: 'stvogel@eonerc.rwth-aachen.de' }, externalAuth: true, - loginURL: 'http://localhost:4180/oauth2/start', - provider: 'KeyCloak' + loginURL: 'http://localhost:4180/oauth2/start?rd=http://localhost:3000/login/complete', + provider: 'KeyCloak', + disableVillasLogin: false, }; export default config diff --git a/src/router.js b/src/router.js index b0c8dd4..1ae24e6 100644 --- a/src/router.js +++ b/src/router.js @@ -29,7 +29,8 @@ import Dashboard from './dashboard/dashboard' import InfrastructureComponents from './ic/ics'; import Users from './user/users'; import User from "./user/user"; -import Config from './config.js'; +import Config from './config'; +import LoginComplete from './user/login-complete' class Root extends React.Component { @@ -37,10 +38,11 @@ class Root extends React.Component { return ( + ( - + )} /> diff --git a/src/user/login-complete.js b/src/user/login-complete.js new file mode 100644 index 0000000..e8b2bc6 --- /dev/null +++ b/src/user/login-complete.js @@ -0,0 +1,70 @@ +/** + * This file is part of VILLASweb. + * + * VILLASweb is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VILLASweb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VILLASweb. If not, see . + ******************************************************************************/ + +import React from 'react'; +import { Redirect } from 'react-router-dom'; +import AppDispatcher from '../common/app-dispatcher'; +import LoginStore from './login-store' +import NotificationsDataManager from '../common/data-managers/notifications-data-manager'; + + + +class LoginComplete extends React.Component { + constructor(props) { + super(props); + + AppDispatcher.dispatch({ + type: 'users/extlogin', + }); + + this.state = { + loginMessage: '', + token: '', + currentUser: '', + } + } + + static getStores(){ + return [LoginStore] + } + + static calculateState(prevState, props) { + // We need to work with the login store here to trigger the re-render upon state change after login + // Upon successful login, the token and currentUser are stored in the local storage as strings + return { + loginMessage: LoginStore.getState().loginMessage, + token: LoginStore.getState().token, + currentUser: LoginStore.getState().currentUser, + } + } + + componentDidMount() { + NotificationsDataManager.setSystem(this.refs.notificationSystem); + } + + render() { + const { user } = this.state.currentUser; + if (this.state.currentUser !== null && this.state.currentUser !== "") { + return (); + } + else { + return (

Authenticating..

); + } + } +} + +export default LoginComplete; diff --git a/src/user/login-select.js b/src/user/login-select.js index e6b8d58..1602fbf 100644 --- a/src/user/login-select.js +++ b/src/user/login-select.js @@ -37,7 +37,7 @@ class LoginSelect extends Component {
- +
diff --git a/src/user/login-store.js b/src/user/login-store.js index aa69290..077d30a 100644 --- a/src/user/login-store.js +++ b/src/user/login-store.js @@ -40,6 +40,10 @@ class LoginStore extends ReduceStore { UsersDataManager.login(action.username, action.password); return Object.assign({}, state, { loginMessage: null }); + case 'users/extlogin': + UsersDataManager.login(); + return Object.assign({}, state, { loginMessage: null }); + case 'users/logout': // disconnect from all infrastructure components ICDataDataManager.closeAll(); diff --git a/src/user/users-data-manager.js b/src/user/users-data-manager.js index b5694a7..6fd725b 100644 --- a/src/user/users-data-manager.js +++ b/src/user/users-data-manager.js @@ -25,18 +25,33 @@ class UsersDataManager extends RestDataManager { } login(username, password) { - RestAPI.post(this.makeURL('/authenticate'), { username: username, password: password }).then(response => { - AppDispatcher.dispatch({ - type: 'users/logged-in', - token: response.token, - currentUser: response.user, + if (username && password) { + RestAPI.post(this.makeURL('/authenticate'), { username: username, password: password }).then(response => { + AppDispatcher.dispatch({ + type: 'users/logged-in', + token: response.token, + currentUser: response.user, + }); + }).catch(error => { + AppDispatcher.dispatch({ + type: 'users/login-error', + error: error + }); }); - }).catch(error => { - AppDispatcher.dispatch({ - type: 'users/login-error', - error: error + } else { // external authentication + RestAPI.post(this.makeURL('/authenticate'),).then(response => { + AppDispatcher.dispatch({ + type: 'users/logged-in', + token: response.token, + currentUser: response.user, + }); + }).catch(error => { + AppDispatcher.dispatch({ + type: 'users/login-error', + error: error + }); }); - }); + } } } From ef84f20eb4930e6b34c266c01b872b1d02f0ca9f Mon Sep 17 00:00:00 2001 From: irismarie Date: Wed, 3 Feb 2021 18:07:57 +0100 Subject: [PATCH 04/33] changed config values for integration test, #39 --- src/config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.js b/src/config.js index c911724..f6e470b 100644 --- a/src/config.js +++ b/src/config.js @@ -24,8 +24,8 @@ const config = { mail: 'stvogel@eonerc.rwth-aachen.de' }, externalAuth: true, - loginURL: 'http://localhost:4180/oauth2/start?rd=http://localhost:3000/login/complete', - provider: 'KeyCloak', + loginURL: 'villas.k8s/oauth2/start?rd=villas.k8s/login/complete', + provider: 'Jupyter', disableVillasLogin: false, }; From 36e0741f7e4604262c5edec0adafaa9cad67d489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iris=20Marie=20K=C3=B6ster?= Date: Thu, 4 Feb 2021 14:25:13 +0100 Subject: [PATCH 05/33] use more generic relative paths --- src/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.js b/src/config.js index f6e470b..bdcc841 100644 --- a/src/config.js +++ b/src/config.js @@ -24,7 +24,7 @@ const config = { mail: 'stvogel@eonerc.rwth-aachen.de' }, externalAuth: true, - loginURL: 'villas.k8s/oauth2/start?rd=villas.k8s/login/complete', + loginURL: '/oauth2/start?rd=/login/complete', provider: 'Jupyter', disableVillasLogin: false, }; From a1e95657ce5591959ba746d47484e8a47eede73c Mon Sep 17 00:00:00 2001 From: irismarie Date: Fri, 5 Feb 2021 11:04:10 +0100 Subject: [PATCH 06/33] convert to flux container --- src/user/login-complete.js | 40 +++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/user/login-complete.js b/src/user/login-complete.js index e8b2bc6..41b5bb5 100644 --- a/src/user/login-complete.js +++ b/src/user/login-complete.js @@ -20,6 +20,7 @@ import { Redirect } from 'react-router-dom'; import AppDispatcher from '../common/app-dispatcher'; import LoginStore from './login-store' import NotificationsDataManager from '../common/data-managers/notifications-data-manager'; +import NotificationsFactory from "../common/data-managers/notifications-factory"; @@ -35,9 +36,17 @@ class LoginComplete extends React.Component { loginMessage: '', token: '', currentUser: '', + secondsToWait: 5, } + + this.timer = 0; + this.startTimer = this.startTimer.bind(this); + this.countDown = this.countDown.bind(this); + + this.startTimer(); } + static getStores(){ return [LoginStore] } @@ -52,8 +61,26 @@ class LoginComplete extends React.Component { } } - componentDidMount() { - NotificationsDataManager.setSystem(this.refs.notificationSystem); + componentDidUnmount() { + clearInterval(this.timer); + } + + startTimer() { + if (this.timer == 0 && this.state.secondsToWait > 0) { + // call function 'countDown' every 1000ms + this.timer = setInterval(this.countDown, 1000); + } + } + + countDown() { + console.log("count down"); + let seconds = this.state.secondsToWait - 1; + this.setState({secondsToWait: seconds}); + + // waiting time over, stop counting down + if (seconds == 0) { + clearInterval(this.timer); + } } render() { @@ -61,10 +88,13 @@ class LoginComplete extends React.Component { if (this.state.currentUser !== null && this.state.currentUser !== "") { return (); } - else { - return (

Authenticating..

); + else if (this.state.secondsToWait > 0) { + return (

Authenticating.. {this.state.secondsToWait}

); + } else { // authenticating failed + //NotificationsFactory.LOAD_ERROR('Backend did not return user after external auth'); + return (); } } } -export default LoginComplete; +export default Container.create(fluxContainerConverter.convert(LoginComplete)); \ No newline at end of file From 3eb3c88bbe612e516620ab7bfb7a2ed1df7c5831 Mon Sep 17 00:00:00 2001 From: irismarie Date: Fri, 5 Feb 2021 12:36:15 +0100 Subject: [PATCH 07/33] (fix) added missing requirements --- src/user/login-complete.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/user/login-complete.js b/src/user/login-complete.js index 41b5bb5..3a7769e 100644 --- a/src/user/login-complete.js +++ b/src/user/login-complete.js @@ -19,6 +19,8 @@ import React from 'react'; import { Redirect } from 'react-router-dom'; import AppDispatcher from '../common/app-dispatcher'; import LoginStore from './login-store' +import { Container } from 'flux/utils'; + import NotificationsDataManager from '../common/data-managers/notifications-data-manager'; import NotificationsFactory from "../common/data-managers/notifications-factory"; @@ -97,4 +99,5 @@ class LoginComplete extends React.Component { } } +let fluxContainerConverter = require('../common/FluxContainerConverter'); export default Container.create(fluxContainerConverter.convert(LoginComplete)); \ No newline at end of file From b8b0f3e44a9e1ac0003e2c1a69a672787e7930a3 Mon Sep 17 00:00:00 2001 From: irismarie Date: Fri, 5 Feb 2021 13:06:02 +0100 Subject: [PATCH 08/33] (fix) useless and erroneous code --- src/user/login-complete.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/user/login-complete.js b/src/user/login-complete.js index 3a7769e..92aeb72 100644 --- a/src/user/login-complete.js +++ b/src/user/login-complete.js @@ -86,7 +86,6 @@ class LoginComplete extends React.Component { } render() { - const { user } = this.state.currentUser; if (this.state.currentUser !== null && this.state.currentUser !== "") { return (); } From cf8a1e049ca3f1466f0d2101e24fd6f7ee31b179 Mon Sep 17 00:00:00 2001 From: irismarie Date: Fri, 5 Feb 2021 14:52:21 +0100 Subject: [PATCH 09/33] change authenticate endpoints --- src/user/users-data-manager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/user/users-data-manager.js b/src/user/users-data-manager.js index 6fd725b..0008fa1 100644 --- a/src/user/users-data-manager.js +++ b/src/user/users-data-manager.js @@ -26,7 +26,7 @@ class UsersDataManager extends RestDataManager { login(username, password) { if (username && password) { - RestAPI.post(this.makeURL('/authenticate'), { username: username, password: password }).then(response => { + RestAPI.post(this.makeURL('/authenticate/internal'), { username: username, password: password }).then(response => { AppDispatcher.dispatch({ type: 'users/logged-in', token: response.token, @@ -39,7 +39,7 @@ class UsersDataManager extends RestDataManager { }); }); } else { // external authentication - RestAPI.post(this.makeURL('/authenticate'),).then(response => { + RestAPI.post(this.makeURL('/authenticate/external'),).then(response => { AppDispatcher.dispatch({ type: 'users/logged-in', token: response.token, From f994520f9e6463592f8782c182528688146f30e6 Mon Sep 17 00:00:00 2001 From: irismarie Date: Fri, 5 Feb 2021 14:52:39 +0100 Subject: [PATCH 10/33] console output --- src/user/login-complete.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/user/login-complete.js b/src/user/login-complete.js index 92aeb72..2a8894b 100644 --- a/src/user/login-complete.js +++ b/src/user/login-complete.js @@ -64,7 +64,8 @@ class LoginComplete extends React.Component { } componentDidUnmount() { - clearInterval(this.timer); + console.log("component unmounting"); + //clearInterval(this.timer); } startTimer() { @@ -75,8 +76,9 @@ class LoginComplete extends React.Component { } countDown() { - console.log("count down"); + console.log("count down, seconds:"); let seconds = this.state.secondsToWait - 1; + console.log(seconds); this.setState({secondsToWait: seconds}); // waiting time over, stop counting down @@ -86,6 +88,8 @@ class LoginComplete extends React.Component { } render() { + console.log("render, seconds to wait:"); + console.log(this.state.secondsToWait); if (this.state.currentUser !== null && this.state.currentUser !== "") { return (); } From e7482990aafe18c665a4297cd9b960bd062c5e3e Mon Sep 17 00:00:00 2001 From: irismarie Date: Fri, 5 Feb 2021 15:45:58 +0100 Subject: [PATCH 11/33] debugging info --- src/user/login-complete.js | 4 +++- src/user/login-store.js | 1 + src/user/users-data-manager.js | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/user/login-complete.js b/src/user/login-complete.js index 2a8894b..8397720 100644 --- a/src/user/login-complete.js +++ b/src/user/login-complete.js @@ -90,7 +90,9 @@ class LoginComplete extends React.Component { render() { console.log("render, seconds to wait:"); console.log(this.state.secondsToWait); - if (this.state.currentUser !== null && this.state.currentUser !== "") { + if (this.state.currentUser && this.state.currentUser !== "") { + console.log("user:"); + console.log(this.state.currentUser); return (); } else if (this.state.secondsToWait > 0) { diff --git a/src/user/login-store.js b/src/user/login-store.js index 077d30a..c553e17 100644 --- a/src/user/login-store.js +++ b/src/user/login-store.js @@ -55,6 +55,7 @@ class LoginStore extends ReduceStore { case 'users/logged-in': // save login in local storage + console.log(action); localStorage.setItem('token', action.token); localStorage.setItem('currentUser', JSON.stringify(action.currentUser)); diff --git a/src/user/users-data-manager.js b/src/user/users-data-manager.js index 0008fa1..17c4cd4 100644 --- a/src/user/users-data-manager.js +++ b/src/user/users-data-manager.js @@ -40,6 +40,7 @@ class UsersDataManager extends RestDataManager { }); } else { // external authentication RestAPI.post(this.makeURL('/authenticate/external'),).then(response => { + console.log(response); AppDispatcher.dispatch({ type: 'users/logged-in', token: response.token, From d6992fe7342cbda0539a4937feca0da409cb59cc Mon Sep 17 00:00:00 2001 From: irismarie Date: Fri, 5 Feb 2021 17:37:21 +0100 Subject: [PATCH 12/33] wait before redirecting --- src/user/login-complete.js | 14 ++++++++------ src/user/login-store.js | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/user/login-complete.js b/src/user/login-complete.js index 8397720..3bca1f7 100644 --- a/src/user/login-complete.js +++ b/src/user/login-complete.js @@ -63,9 +63,9 @@ class LoginComplete extends React.Component { } } - componentDidUnmount() { + stopTimer() { console.log("component unmounting"); - //clearInterval(this.timer); + clearInterval(this.timer); } startTimer() { @@ -93,13 +93,15 @@ class LoginComplete extends React.Component { if (this.state.currentUser && this.state.currentUser !== "") { console.log("user:"); console.log(this.state.currentUser); + this.stopTimer(); return (); } - else if (this.state.secondsToWait > 0) { - return (

Authenticating.. {this.state.secondsToWait}

); - } else { // authenticating failed - //NotificationsFactory.LOAD_ERROR('Backend did not return user after external auth'); + else if (this.state.secondsToWait == 0) { + this.stopTimer(); return (); + } else { // authenticating failed + //NotificationsFactory.LOAD_ERROR('Backend did not return user after external auth'); + return (

Authenticating.. {this.state.secondsToWait}

); } } } diff --git a/src/user/login-store.js b/src/user/login-store.js index c553e17..c236639 100644 --- a/src/user/login-store.js +++ b/src/user/login-store.js @@ -58,6 +58,8 @@ class LoginStore extends ReduceStore { console.log(action); localStorage.setItem('token', action.token); localStorage.setItem('currentUser', JSON.stringify(action.currentUser)); + console.log(localStorage.getItem('token')); + console.log(localStorage.getItem("currentUser")); return Object.assign({}, state, { token: action.token, currentUser: action.currentUser}); From a8b753df08fde1be5992195b11b319b772962ab6 Mon Sep 17 00:00:00 2001 From: irismarie Date: Fri, 5 Feb 2021 18:42:37 +0100 Subject: [PATCH 13/33] stop annoying timergit add . --- src/user/login-complete.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/user/login-complete.js b/src/user/login-complete.js index 3bca1f7..cbeca8f 100644 --- a/src/user/login-complete.js +++ b/src/user/login-complete.js @@ -44,6 +44,7 @@ class LoginComplete extends React.Component { this.timer = 0; this.startTimer = this.startTimer.bind(this); this.countDown = this.countDown.bind(this); + this.stopTimer = this.stopTimer.bind(this); this.startTimer(); } @@ -64,7 +65,7 @@ class LoginComplete extends React.Component { } stopTimer() { - console.log("component unmounting"); + console.log("stop timer"); clearInterval(this.timer); } From 830448a9bdf5ff0b7be6423f39487338018938f2 Mon Sep 17 00:00:00 2001 From: irismarie Date: Fri, 5 Feb 2021 19:22:12 +0100 Subject: [PATCH 14/33] stop, timer, please --- src/user/login-complete.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/user/login-complete.js b/src/user/login-complete.js index cbeca8f..d8dd65c 100644 --- a/src/user/login-complete.js +++ b/src/user/login-complete.js @@ -28,6 +28,7 @@ import NotificationsFactory from "../common/data-managers/notifications-factory" class LoginComplete extends React.Component { constructor(props) { + console.log("LoginComplete constructor"); super(props); AppDispatcher.dispatch({ @@ -38,7 +39,7 @@ class LoginComplete extends React.Component { loginMessage: '', token: '', currentUser: '', - secondsToWait: 5, + secondsToWait: 99, } this.timer = 0; @@ -46,7 +47,12 @@ class LoginComplete extends React.Component { this.countDown = this.countDown.bind(this); this.stopTimer = this.stopTimer.bind(this); + + } + + componentDidMount() { this.startTimer(); + this.setState({secondsToWait: 5}); } From 83674086f42a110220daef18026a00d7c3aafc02 Mon Sep 17 00:00:00 2001 From: irismarie Date: Wed, 17 Feb 2021 17:53:26 +0100 Subject: [PATCH 15/33] read config from backend, changed login page --- src/app.js | 5 ++++ src/config-reader.js | 43 ++++++++++++++++++++++++++++++++ src/router.js | 10 +------- src/styles/app.css | 7 ++++++ src/user/login-form.js | 43 +++++++++++++++++++++++--------- src/user/login-select.js | 53 ---------------------------------------- src/user/login-store.js | 16 +++++++++--- src/user/login.js | 3 ++- src/user/logout.js | 6 ----- 9 files changed, 103 insertions(+), 83 deletions(-) create mode 100644 src/config-reader.js delete mode 100644 src/user/login-select.js diff --git a/src/app.js b/src/app.js index bcaced0..ba2ecc0 100644 --- a/src/app.js +++ b/src/app.js @@ -48,6 +48,11 @@ class App extends React.Component { this.state = { showSidebarMenu: false, } + + // load config from backend + AppDispatcher.dispatch({ + type: 'config/load', + }); } componentDidMount() { diff --git a/src/config-reader.js b/src/config-reader.js new file mode 100644 index 0000000..1893910 --- /dev/null +++ b/src/config-reader.js @@ -0,0 +1,43 @@ +/** + * This file is part of VILLASweb. + * + * VILLASweb is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VILLASweb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VILLASweb. If not, see . + ******************************************************************************/ + +import RestDataManager from './common/data-managers/rest-data-manager'; +import RestAPI from './common/api/rest-api'; +import AppDispatcher from './common/app-dispatcher'; + + +class ConfigReader extends RestDataManager { + constructor() { + super('config', '/config'); + } + + loadConfig() { + RestAPI.get(this.makeURL('/config'), null).then(response => { + AppDispatcher.dispatch({ + type: 'config/loaded', + data: response, + }); + }).catch(error => { + AppDispatcher.dispatch({ + type: 'config/load-error', + error: error, + }); + }); + } +}; + +export default new ConfigReader(); \ No newline at end of file diff --git a/src/router.js b/src/router.js index 1ae24e6..b70bf6e 100644 --- a/src/router.js +++ b/src/router.js @@ -20,7 +20,6 @@ import { BrowserRouter, Route, Switch } from 'react-router-dom'; import App from './app'; import Login from './user/login'; -import LoginSelect from './user/login-select'; import Logout from './user/logout'; import Home from './common/home'; import Scenarios from './scenario/scenarios'; @@ -29,7 +28,6 @@ import Dashboard from './dashboard/dashboard' import InfrastructureComponents from './ic/ics'; import Users from './user/users'; import User from "./user/user"; -import Config from './config'; import LoginComplete from './user/login-complete' @@ -39,13 +37,7 @@ class Root extends React.Component { - ( - - )} - /> - + diff --git a/src/styles/app.css b/src/styles/app.css index c50399c..8a9c72e 100644 --- a/src/styles/app.css +++ b/src/styles/app.css @@ -254,6 +254,13 @@ body { 0 9px 18px 0 rgba(0, 0, 0, 0.1); } +hr { + margin-top: 1rem; + margin-bottom: 1rem; + border:0; + border-top: 1px solid rgba(0, 0, 0, 0.1); +} + /** * Tables */ diff --git a/src/user/login-form.js b/src/user/login-form.js index 1c2fc5e..d412831 100644 --- a/src/user/login-form.js +++ b/src/user/login-form.js @@ -19,6 +19,8 @@ import React, { Component } from 'react'; import { Form, Button, FormGroup, FormControl, FormLabel, Col } from 'react-bootstrap'; import RecoverPassword from './recover-password' import AppDispatcher from '../common/app-dispatcher'; +import _ from 'lodash'; + class LoginForm extends Component { constructor(props) { @@ -56,17 +58,17 @@ class LoginForm extends Component { this.setState({ [event.target.id]: event.target.value, disableLogin }); } - openRecoverPassword(){ - this.setState({forgottenPassword: true}); + openRecoverPassword() { + this.setState({ forgottenPassword: true }); } - closeRecoverPassword(){ - this.setState({forgottenPassword: false}); + closeRecoverPassword() { + this.setState({ forgottenPassword: false }); } - render() { + villaslogin() { return ( -
+ Username @@ -89,19 +91,38 @@ class LoginForm extends Component {
} - + - - + + - + this.closeRecoverPassword()} sessionToken={this.props.sessionToken} /> - ); } + + render() { + let villasLogin = this.villaslogin(); + + if (this.props.config) { + let externalLogin = _.get(this.props.config, ['authentication', 'external', 'enabled']) + let provider = _.get(this.props.config, ['authentication', 'external', 'provider_name']) + let url = _.get(this.props.config, ['authentication', 'external', 'authorize_url']) + + if (externalLogin && provider && url) { + return [ + villasLogin, +
, + + ]; + } + } + + return villasLogin; + } } export default LoginForm; diff --git a/src/user/login-select.js b/src/user/login-select.js deleted file mode 100644 index 1602fbf..0000000 --- a/src/user/login-select.js +++ /dev/null @@ -1,53 +0,0 @@ -/** - * This file is part of VILLASweb. - * - * VILLASweb is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * VILLASweb is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with VILLASweb. If not, see . - ******************************************************************************/ - -import React, { Component } from 'react'; -import { Form, Button, FormGroup, FormControl, FormLabel, Col } from 'react-bootstrap'; -import Header from '../common/header'; -import Footer from '../common/footer'; -import { withRouter } from 'react-router-dom'; - - - -class LoginSelect extends Component { - - - villaswebLogin = e => { - this.props.history.replace('/villaslogin'); - } - - render() { - - return ( -
-
-
-
- -
- -
-
- -
- -
- ); - } -} - -export default withRouter(LoginSelect); diff --git a/src/user/login-store.js b/src/user/login-store.js index c236639..7eb4b2b 100644 --- a/src/user/login-store.js +++ b/src/user/login-store.js @@ -20,6 +20,7 @@ import { ReduceStore } from 'flux/utils'; import AppDispatcher from '../common/app-dispatcher'; import UsersDataManager from './users-data-manager'; import ICDataDataManager from '../ic/ic-data-data-manager'; +import ConfigReader from '../config-reader'; class LoginStore extends ReduceStore { constructor() { @@ -31,11 +32,23 @@ class LoginStore extends ReduceStore { currentUser: null, token: null, loginMessage: null, + config: null, }; } reduce(state, action) { switch (action.type) { + case 'config/load': + ConfigReader.loadConfig(); + return state; + + case 'config/loaded': + return Object.assign({}, state, { config: action.data }); + + case 'config/load-error': + console.log("config load error"); + return Object.assign({}, state, { config: null }); + case 'users/login': UsersDataManager.login(action.username, action.password); return Object.assign({}, state, { loginMessage: null }); @@ -55,11 +68,8 @@ class LoginStore extends ReduceStore { case 'users/logged-in': // save login in local storage - console.log(action); localStorage.setItem('token', action.token); localStorage.setItem('currentUser', JSON.stringify(action.currentUser)); - console.log(localStorage.getItem('token')); - console.log(localStorage.getItem("currentUser")); return Object.assign({}, state, { token: action.token, currentUser: action.currentUser}); diff --git a/src/user/login.js b/src/user/login.js index 0a6fac8..0ab4b28 100644 --- a/src/user/login.js +++ b/src/user/login.js @@ -40,6 +40,7 @@ class Login extends Component { loginMessage: LoginStore.getState().loginMessage, token: LoginStore.getState().token, currentUser: LoginStore.getState().currentUser, + config: LoginStore.getState().config, } } @@ -62,7 +63,7 @@ class Login extends Component {
Login - +