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 - +