--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { useState, useEffect } from 'react';
+import { withStyles, WithStyles, StyleRulesCallback } from '@material-ui/core/styles';
+import CircularProgress from '@material-ui/core/CircularProgress';
+import { Button, Card, CardContent, TextField, CardActions } from '@material-ui/core';
+import { green } from '@material-ui/core/colors';
+import { AxiosPromise } from 'axios';
+
+type CssRules = 'root' | 'loginBtn' | 'card' | 'wrapper' | 'progress';
+
+const styles: StyleRulesCallback<CssRules> = theme => ({
+ root: {
+ display: 'flex',
+ flexWrap: 'wrap',
+ width: '100%',
+ margin: `${theme.spacing.unit} auto`
+ },
+ loginBtn: {
+ marginTop: theme.spacing.unit,
+ flexGrow: 1
+ },
+ card: {
+ marginTop: theme.spacing.unit,
+ width: '100%'
+ },
+ wrapper: {
+ margin: theme.spacing.unit,
+ position: 'relative',
+ },
+ progress: {
+ color: green[500],
+ position: 'absolute',
+ top: '50%',
+ left: '50%',
+ marginTop: -12,
+ marginLeft: -12,
+ },
+});
+
+interface LoginFormProps {
+ handleSubmit: (username: string, password: string) => AxiosPromise;
+}
+
+export const LoginForm = withStyles(styles)(
+ ({ handleSubmit, classes }: LoginFormProps & WithStyles<CssRules>) => {
+ const [username, setUsername] = useState('');
+ const [password, setPassword] = useState('');
+ const [isButtonDisabled, setIsButtonDisabled] = useState(true);
+ const [isSubmitting, setSubmitting] = useState(false);
+ const [helperText, setHelperText] = useState('');
+ const [error, setError] = useState(false);
+
+ useEffect(() => {
+ setError(false);
+ setHelperText('');
+ if (username.trim() && password.trim()) {
+ setIsButtonDisabled(false);
+ } else {
+ setIsButtonDisabled(true);
+ }
+ }, [username, password]);
+
+ const handleLogin = () => {
+ setSubmitting(true);
+ handleSubmit(username, password)
+ .then((response) => {
+ setError(false);
+ console.log("LOGIN SUCESSFUL: ", response);
+ setSubmitting(false);
+ })
+ .catch((err) => {
+ setError(true);
+ console.log("ERROR: ", err.response);
+ setHelperText(`${err.response && err.response.data && err.response.data.errors[0] || 'Error logging in: '+err}`);
+ setSubmitting(false);
+ });
+ };
+
+ const handleKeyPress = (e: any) => {
+ if (e.keyCode === 13 || e.which === 13) {
+ if (!isButtonDisabled) {
+ handleLogin();
+ }
+ }
+ };
+
+ return (
+ <React.Fragment>
+ <form className={classes.root} noValidate autoComplete="off">
+ <Card className={classes.card}>
+ <div className={classes.wrapper}>
+ <CardContent>
+ <div>
+ <TextField
+ disabled={isSubmitting}
+ error={error} fullWidth id="username" type="email"
+ label="Username" margin="normal"
+ onChange={(e) => setUsername(e.target.value)}
+ onKeyPress={(e) => handleKeyPress(e)}
+ />
+ <TextField
+ disabled={isSubmitting}
+ error={error} fullWidth id="password" type="password"
+ label="Password" margin="normal"
+ helperText={helperText}
+ onChange={(e) => setPassword(e.target.value)}
+ onKeyPress={(e) => handleKeyPress(e)}
+ />
+ </div>
+ </CardContent>
+ <CardActions>
+ <Button variant="contained" size="large" color="primary"
+ className={classes.loginBtn} onClick={() => handleLogin()}
+ disabled={isSubmitting || isButtonDisabled}>
+ Log in
+ </Button>
+ </CardActions>
+ { isSubmitting && <CircularProgress color='secondary' className={classes.progress} />}
+ </div>
+ </Card>
+ </form>
+ </React.Fragment>
+ );
+ });
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';
type CssRules = 'root' | 'container' | 'title' | 'content' | 'content__bolder' | 'button';
}
});
+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,
- welcomePage: string
+ welcomePage: string,
+ pamLogin: boolean,
};
export const LoginPanel = withStyles(styles)(
homeCluster: state.auth.homeCluster,
uuidPrefix: state.auth.localCluster,
loginCluster: state.auth.loginCluster,
- welcomePage: state.auth.config.clusterConfig.Workbench.WelcomePageHTML
- }))(({ classes, dispatch, remoteHosts, homeCluster, uuidPrefix, loginCluster, welcomePage }: LoginPanelProps) =>
+ 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%" }}>
</Select>
</Typography>}
- <Typography component="div" align="right">
- <Button variant="contained" color="primary" style={{ margin: "1em" }} className={classes.button}
+ {pamLogin
+ ? <Typography component="div">
+ <LoginForm 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
- {uuidPrefix !== homeCluster && loginCluster !== homeCluster &&
+ Log in {uuidPrefix !== homeCluster && loginCluster !== homeCluster &&
<span> to {uuidPrefix} with user from {homeCluster}</span>}
</Button>
- </Typography>
+ </Typography>}
</Grid>
</Grid >
));