X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/7f2b1bb658a39caff2aea1378c7d192499e950fc..d861bd54089e9279cd03b2e4561869ee877b9559:/src/views/login-panel/login-panel.tsx diff --git a/src/views/login-panel/login-panel.tsx b/src/views/login-panel/login-panel.tsx index 6a9210ac..110097be 100644 --- a/src/views/login-panel/login-panel.tsx +++ b/src/views/login-panel/login-panel.tsx @@ -2,13 +2,16 @@ // // SPDX-License-Identifier: AGPL-3.0 -import * as React from 'react'; +import React from 'react'; import { connect, DispatchProp } from 'react-redux'; -import { Grid, Typography, Button } from '@material-ui/core'; +import { Grid, Typography, Button, Select } from '@material-ui/core'; import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles'; -import { login } from '~/store/auth/auth-action'; -import { ArvadosTheme } from '~/common/custom-theme'; -import * as classNames from 'classnames'; +import { login, authActions } from 'store/auth/auth-action'; +import { ArvadosTheme } from 'common/custom-theme'; +import { RootState } from 'store/store'; +import { LoginForm } from 'views-components/login-form/login-form'; +import Axios from 'axios'; +import { Config } from 'common/config'; type CssRules = 'root' | 'container' | 'title' | 'content' | 'content__bolder' | 'button'; @@ -23,7 +26,6 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ left: 0, bottom: 0, right: 0, - background: 'url("arvados-logo-big.png") no-repeat center center', opacity: 0.2, } }, @@ -48,33 +50,79 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ } }); -type LoginPanelProps = DispatchProp & WithStyles; +const doPasswordLogin = (url: string) => (username: string, password: string) => { + const formData: string[] = []; + formData.push('username='+encodeURIComponent(username)); + formData.push('password='+encodeURIComponent(password)); + return Axios.post(`${url}/arvados/v1/users/authenticate`, formData.join('&'), { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + }); +}; -export const LoginPanel = withStyles(styles)(connect()( - ({ classes, dispatch }: LoginPanelProps) => - - - - Welcome to the Arvados Workbench - - - The "Log in" button below will show you a Google sign-in page. - After you assure Google that you want to log in here with your Google account, you will be redirected back here to Arvados Workbench. - - - If you have never used Arvados Workbench before, logging in for the first time will automatically create a new account. - - - IMPORTANT: Please keep in mind to store exploratory data only but not any information used for clinical decision making. - - - Arvados Workbench uses your name and email address only for identification, and does not retrieve any other personal information from Google. - - - - - - -)); +type LoginPanelProps = DispatchProp & WithStyles & { + remoteHosts: { [key: string]: string }, + homeCluster: string, + localCluster: string, + loginCluster: string, + welcomePage: string, + passwordLogin: boolean, +}; + +const loginOptions = ['LDAP', 'PAM', 'Test']; + +export const requirePasswordLogin = (config: Config): boolean => { + if (config && config.clusterConfig && config.clusterConfig.Login) { + return loginOptions + .filter(loginOption => !!config.clusterConfig.Login[loginOption]) + .map(loginOption => config.clusterConfig.Login[loginOption].Enable) + .find(enabled => enabled === true) || false; + } + return false; +}; + +export const LoginPanel = withStyles(styles)( + connect((state: RootState) => ({ + remoteHosts: state.auth.remoteHosts, + homeCluster: state.auth.homeCluster, + localCluster: state.auth.localCluster, + loginCluster: state.auth.loginCluster, + welcomePage: state.auth.config.clusterConfig.Workbench.WelcomePageHTML, + passwordLogin: requirePasswordLogin(state.auth.remoteHostsConfig[state.auth.loginCluster || state.auth.homeCluster]), + }))(({ classes, dispatch, remoteHosts, homeCluster, localCluster, loginCluster, welcomePage, passwordLogin }: LoginPanelProps) => { + const loginBtnLabel = `Log in${(localCluster !== homeCluster && loginCluster !== homeCluster) ? " to "+localCluster+" with user from "+homeCluster : ''}`; + + return ( + + +
+ + {Object.keys(remoteHosts).length > 1 && loginCluster === "" && + + + + + } + + {passwordLogin + ? + + + : + + } + + );} + ));