1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { connect, DispatchProp } from 'react-redux';
7 import { Grid, Typography, Button, Select } from '@material-ui/core';
8 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
9 import { login, authActions } from '~/store/auth/auth-action';
10 import { ArvadosTheme } from '~/common/custom-theme';
11 import { RootState } from '~/store/store';
12 import { LoginForm } from '~/views-components/login-form/login-form';
13 import Axios from 'axios';
15 type CssRules = 'root' | 'container' | 'title' | 'content' | 'content__bolder' | 'button';
17 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
20 backgroundColor: theme.palette.grey["200"],
36 marginBottom: theme.spacing.unit * 6,
37 color: theme.palette.grey["800"]
40 marginBottom: theme.spacing.unit * 3,
42 color: theme.palette.grey["800"]
52 const doPAMLogin = (url: string) => (username: string, password: string) => {
53 const formData = new FormData();
54 formData.append("username", username);
55 formData.append("password", password);
56 return Axios.post(`${url}/login`, formData, {
57 headers: { 'X-Http-Method-Override': 'GET' },
61 type LoginPanelProps = DispatchProp<any> & WithStyles<CssRules> & {
62 remoteHosts: { [key: string]: string },
70 export const LoginPanel = withStyles(styles)(
71 connect((state: RootState) => ({
72 remoteHosts: state.auth.remoteHosts,
73 homeCluster: state.auth.homeCluster,
74 uuidPrefix: state.auth.localCluster,
75 loginCluster: state.auth.loginCluster,
76 welcomePage: state.auth.config.clusterConfig.Workbench.WelcomePageHTML,
77 pamLogin: state.auth.config.clusterConfig.Login.PAM,
78 }))(({ classes, dispatch, remoteHosts, homeCluster, uuidPrefix, loginCluster, welcomePage, pamLogin }: LoginPanelProps) =>
79 <Grid container justify="center" alignItems="center"
80 className={classes.root}
81 style={{ marginTop: 56, overflowY: "auto", height: "100%" }}>
82 <Grid item className={classes.container}>
83 <Typography component="div">
84 <div dangerouslySetInnerHTML={{ __html: welcomePage }} style={{ margin: "1em" }} />
86 {Object.keys(remoteHosts).length > 1 && loginCluster === "" &&
88 <Typography component="div" align="right">
89 <label>Please select the cluster that hosts your user account:</label>
90 <Select native value={homeCluster} style={{ margin: "1em" }}
91 onChange={(event) => dispatch(authActions.SET_HOME_CLUSTER(event.target.value))}>
92 {Object.keys(remoteHosts).map((k) => <option key={k} value={k}>{k}</option>)}
97 ? <Typography component="div">
98 <LoginForm dispatch={dispatch} handleSubmit={
99 doPAMLogin(`https://${remoteHosts[homeCluster]}`)}/>
101 : <Typography component="div" align="right">
102 <Button variant="contained" color="primary" style={{ margin: "1em" }}
103 className={classes.button}
104 onClick={() => dispatch(login(uuidPrefix, homeCluster, loginCluster, remoteHosts))}>
105 Log in {uuidPrefix !== homeCluster && loginCluster !== homeCluster &&
106 <span> to {uuidPrefix} with user from {homeCluster}</span>}