X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/80aedc2f5a81de82d946e8fe9622ff194bb63cdb..099468843d687fdc8c6fbb0f0e3dc54f59d0de15:/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 293026c3..f834b3b6 100644 --- a/src/views/login-panel/login-panel.tsx +++ b/src/views/login-panel/login-panel.tsx @@ -2,13 +2,17 @@ // // 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, Select } from '@material-ui/core'; import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles'; -import { login, authActions } from '~/store/auth/auth-action'; -import { ArvadosTheme } from '~/common/custom-theme'; -import { RootState } from '~/store/store'; +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'; +import { sanitizeHTML } from 'common/html-sanitize'; type CssRules = 'root' | 'container' | 'title' | 'content' | 'content__bolder' | 'button'; @@ -47,28 +51,55 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ } }); +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' + }, + }); +}; + type LoginPanelProps = DispatchProp & WithStyles & { remoteHosts: { [key: string]: string }, homeCluster: string, - uuidPrefix: string, + localCluster: string, loginCluster: string, - welcomePage: 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, - uuidPrefix: state.auth.localCluster, + localCluster: state.auth.localCluster, loginCluster: state.auth.loginCluster, - welcomePage: state.config.clusterConfig.Workbench.WelcomePageHTML - }))(({ classes, dispatch, remoteHosts, homeCluster, uuidPrefix, loginCluster, welcomePage }: LoginPanelProps) => - { + const loginBtnLabel = `Log in${(localCluster !== homeCluster && loginCluster !== homeCluster) ? " to "+localCluster+" with user from "+homeCluster : ''}`; + + return ( - -
+ +
{Object.keys(remoteHosts).length > 1 && loginCluster === "" && @@ -80,14 +111,19 @@ export const LoginPanel = withStyles(styles)( } - - + {passwordLogin + ? + + : + + } - + );} ));