15064: Logging into home cluster logs into all federated clusters
[arvados-workbench2.git] / src / views / login-panel / login-panel.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { connect, DispatchProp } from 'react-redux';
7 import { Grid, Typography, Button, Select, FormControl } 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 * as classNames from 'classnames';
13
14 type CssRules = 'root' | 'container' | 'title' | 'content' | 'content__bolder' | 'button';
15
16 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
17     root: {
18         position: 'relative',
19         backgroundColor: theme.palette.grey["200"],
20         '&::after': {
21             content: `''`,
22             position: 'absolute',
23             top: 0,
24             left: 0,
25             bottom: 0,
26             right: 0,
27             background: 'url("arvados-logo-big.png") no-repeat center center',
28             opacity: 0.2,
29         }
30     },
31     container: {
32         width: '560px',
33         zIndex: 10
34     },
35     title: {
36         marginBottom: theme.spacing.unit * 6,
37         color: theme.palette.grey["800"]
38     },
39     content: {
40         marginBottom: theme.spacing.unit * 3,
41         lineHeight: '1.2rem',
42         color: theme.palette.grey["800"]
43     },
44     'content__bolder': {
45         fontWeight: 'bolder'
46     },
47     button: {
48         boxShadow: 'none'
49     }
50 });
51
52 type LoginPanelProps = DispatchProp<any> & WithStyles<CssRules> & {
53     remoteHosts: { [key: string]: string },
54     homeCluster: string,
55     uuidPrefix: string
56 };
57
58 export const LoginPanel = withStyles(styles)(
59     connect((state: RootState) => ({
60         remoteHosts: state.auth.remoteHosts,
61         homeCluster: state.auth.homeCluster,
62         uuidPrefix: state.auth.localCluster
63     }))(({ classes, dispatch, remoteHosts, homeCluster, uuidPrefix }: LoginPanelProps) =>
64         <Grid container justify="center" alignItems="center"
65             className={classes.root}
66             style={{ marginTop: 56, overflowY: "auto", height: "100%" }}>
67             <Grid item className={classes.container}>
68                 <Typography variant='h6' align="center" className={classes.title}>
69                     Welcome to the Arvados Workbench
70                 </Typography>
71                 <Typography className={classes.content}>
72                     The "Log in" button below will show you a Google sign-in page.
73                     After you assure Google that you want to log in here with your Google account, you will be redirected back here to Arvados Workbench.
74                 </Typography>
75                 <Typography className={classes.content}>
76                     If you have never used Arvados Workbench before, logging in for the first time will automatically create a new account.
77                 </Typography>
78                 <Typography variant='body1' className={classNames(classes.content, classes.content__bolder)}>
79                     IMPORTANT: Please keep in mind to store exploratory data only but not any information used for clinical decision making.
80                 </Typography>
81                 <Typography className={classes.content}>
82                     Arvados Workbench uses your name and email address only for identification, and does not retrieve any other personal information from Google.
83                 </Typography>
84
85                 {Object.keys(remoteHosts).length > 1 &&
86                     <Typography component="div" align="right">
87                         <label>Please select the cluster that hosts your user account:</label>
88                         <Select native value={homeCluster} style={{ margin: "1em" }}
89                             onChange={(event) => dispatch(authActions.SET_HOME_CLUSTER(event.target.value))}>
90                             {Object.keys(remoteHosts).map((k) => <option key={k} value={k}>{k}</option>)}
91                         </Select>
92                     </Typography>}
93
94                 <Typography component="div" align="right">
95                     <Button variant="contained" color="primary" style={{ margin: "1em" }} className={classes.button}
96                         onClick={() => dispatch(login(uuidPrefix, homeCluster, remoteHosts))}>
97                         Log in to {uuidPrefix}
98                         {uuidPrefix !== homeCluster &&
99                             <span>&nbsp;with user from {homeCluster}</span>}
100                     </Button>
101                 </Typography>
102             </Grid>
103         </Grid >
104     ));