16212: Sets api token on login success, re-focus on login error.
[arvados.git] / src / views / login-panel / login-panel.tsx
index a67228bcca47c6c6c9fd7f117eb17f2a87f640c3..203a2f192fbe9e86d00b18df7cf90b1264b1f961 100644 (file)
@@ -9,7 +9,8 @@ import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/st
 import { login, authActions } from '~/store/auth/auth-action';
 import { ArvadosTheme } from '~/common/custom-theme';
 import { RootState } from '~/store/store';
-import * as classNames from 'classnames';
+import { LoginForm } from '~/views-components/login-form/login-form';
+import Axios from 'axios';
 
 type CssRules = 'root' | 'container' | 'title' | 'content' | 'content__bolder' | 'button';
 
@@ -24,7 +25,6 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
             left: 0,
             bottom: 0,
             right: 0,
-            background: 'url("arvados-logo-big.png") no-repeat center center',
             opacity: 0.2,
         }
     },
@@ -49,11 +49,22 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     }
 });
 
+const doPAMLogin = (url: string) => (username: string, password: string) => {
+    const formData = new FormData();
+    formData.append("username", username);
+    formData.append("password", password);
+    return Axios.post(`${url}/login`, formData, {
+        headers: { 'X-Http-Method-Override': 'GET' },
+    });
+};
+
 type LoginPanelProps = DispatchProp<any> & WithStyles<CssRules> & {
     remoteHosts: { [key: string]: string },
     homeCluster: string,
     uuidPrefix: string,
-    loginCluster: string
+    loginCluster: string,
+    welcomePage: string,
+    pamLogin: boolean,
 };
 
 export const LoginPanel = withStyles(styles)(
@@ -61,30 +72,19 @@ export const LoginPanel = withStyles(styles)(
         remoteHosts: state.auth.remoteHosts,
         homeCluster: state.auth.homeCluster,
         uuidPrefix: state.auth.localCluster,
-        loginCluster: state.auth.loginCluster
-    }))(({ classes, dispatch, remoteHosts, homeCluster, uuidPrefix, loginCluster }: LoginPanelProps) =>
+        loginCluster: state.auth.loginCluster,
+        welcomePage: state.auth.config.clusterConfig.Workbench.WelcomePageHTML,
+        pamLogin: state.auth.config.clusterConfig.Login.PAM,
+    }))(({ classes, dispatch, remoteHosts, homeCluster, uuidPrefix, loginCluster, welcomePage, pamLogin }: LoginPanelProps) =>
         <Grid container justify="center" alignItems="center"
             className={classes.root}
             style={{ marginTop: 56, overflowY: "auto", height: "100%" }}>
             <Grid item className={classes.container}>
-                <Typography variant='h6' align="center" className={classes.title}>
-                    Welcome to the Arvados Workbench
-               </Typography>
-                <Typography className={classes.content}>
-                    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.
-               </Typography>
-                <Typography className={classes.content}>
-                    If you have never used Arvados Workbench before, logging in for the first time will automatically create a new account.
-               </Typography>
-                <Typography variant='body1' className={classNames(classes.content, classes.content__bolder)}>
-                    IMPORTANT: Please keep in mind to store exploratory data only but not any information used for clinical decision making.
-               </Typography>
-                <Typography className={classes.content}>
-                    Arvados Workbench uses your name and email address only for identification, and does not retrieve any other personal information from Google.
-               </Typography>
-
+                <Typography component="div">
+                    <div dangerouslySetInnerHTML={{ __html: welcomePage }} style={{ margin: "1em" }} />
+                </Typography>
                 {Object.keys(remoteHosts).length > 1 && loginCluster === "" &&
+
                     <Typography component="div" align="right">
                         <label>Please select the cluster that hosts your user account:</label>
                         <Select native value={homeCluster} style={{ margin: "1em" }}
@@ -93,14 +93,19 @@ export const LoginPanel = withStyles(styles)(
                         </Select>
                     </Typography>}
 
-                <Typography component="div" align="right">
-                    <Button variant="contained" color="primary" style={{ margin: "1em" }} className={classes.button}
+                {pamLogin
+                ? <Typography component="div">
+                    <LoginForm dispatch={dispatch} handleSubmit={
+                        doPAMLogin(`https://${remoteHosts[homeCluster]}`)}/>
+                </Typography>
+                : <Typography component="div" align="right">
+                    <Button variant="contained" color="primary" style={{ margin: "1em" }}
+                        className={classes.button}
                         onClick={() => dispatch(login(uuidPrefix, homeCluster, loginCluster, remoteHosts))}>
-                        Log in to {uuidPrefix}
-                        {uuidPrefix !== homeCluster && loginCluster !== homeCluster &&
-                            <span>&nbsp;with user from {homeCluster}</span>}
+                        Log in {uuidPrefix !== homeCluster && loginCluster !== homeCluster &&
+                            <span>&nbsp;to {uuidPrefix} with user from {homeCluster}</span>}
                     </Button>
-                </Typography>
+                </Typography>}
             </Grid>
         </Grid >
     ));