mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-06 00:07:44 +01:00
cbd4773cf6
* fix: add onClose to archive toggle dialoge * fix: add link to ConfirmUserLink component * fix: remove icons from admin menu * fix: move button on user list to top right * refactor: move add new api key to header * refactor: button order * fix: lowercase dropdown buttons on feature toggle list * refactor: reorganize reporting dashboard * refactor: consistent buttons * feat: enhance gradual rollout strategy creation * feat: ui tweaks on project access * fix: adjust divider * fix: remove unused imports * fix: update snapshots * fix: add auth options to new user page * fix: add divider * fix: uncontrolled input * fix: add data-loading to sorted by * fix: update snapshots * fix: navigate to project view on create and edit * fix: rename project * fix: add placeholder for feature toggle list component * fix: conditonally render link
148 lines
5.1 KiB
JavaScript
148 lines
5.1 KiB
JavaScript
import React, { useState } from 'react';
|
|
import classnames from 'classnames';
|
|
import PropTypes from 'prop-types';
|
|
import { Button, Grid, TextField, Typography } from '@material-ui/core';
|
|
import { useHistory } from 'react-router';
|
|
import { useCommonStyles } from '../../../common.styles';
|
|
import { useStyles } from './HostedAuth.styles';
|
|
import { Link } from 'react-router-dom';
|
|
import useQueryParams from '../../../hooks/useQueryParams';
|
|
import AuthOptions from '../common/AuthOptions/AuthOptions';
|
|
|
|
const PasswordAuth = ({ authDetails, passwordLogin }) => {
|
|
const commonStyles = useCommonStyles();
|
|
const styles = useStyles();
|
|
const history = useHistory();
|
|
const params = useQueryParams();
|
|
const [username, setUsername] = useState(params.get('email') || '');
|
|
const [password, setPassword] = useState('');
|
|
const [errors, setErrors] = useState({
|
|
usernameError: '',
|
|
passwordError: '',
|
|
});
|
|
|
|
const handleSubmit = async evt => {
|
|
evt.preventDefault();
|
|
|
|
if (!username) {
|
|
setErrors(prev => ({
|
|
...prev,
|
|
usernameError: 'This is a required field',
|
|
}));
|
|
}
|
|
if (!password) {
|
|
setErrors(prev => ({
|
|
...prev,
|
|
passwordError: 'This is a required field',
|
|
}));
|
|
}
|
|
|
|
if (!password || !username) {
|
|
return;
|
|
}
|
|
|
|
const user = { username, password };
|
|
const path = evt.target.action;
|
|
|
|
try {
|
|
await passwordLogin(path, user);
|
|
history.push(`/`);
|
|
} catch (error) {
|
|
if (error.statusCode === 404 || error.statusCode === 400) {
|
|
setErrors(prev => ({
|
|
...prev,
|
|
apiError: 'Invalid login details',
|
|
}));
|
|
setPassword('');
|
|
setUsername('');
|
|
} else {
|
|
setErrors({
|
|
apiError: 'Unknown error while trying to authenticate.',
|
|
});
|
|
}
|
|
}
|
|
};
|
|
|
|
const { usernameError, passwordError, apiError } = errors;
|
|
const { options = [] } = authDetails;
|
|
|
|
return (
|
|
<div>
|
|
<br />
|
|
<div>
|
|
<AuthOptions options={options} />
|
|
</div>
|
|
<p className={styles.fancyLine}>or</p>
|
|
<form onSubmit={handleSubmit} action={authDetails.path}>
|
|
<Typography variant="subtitle2" className={styles.apiError}>
|
|
{apiError}
|
|
</Typography>
|
|
<div
|
|
className={classnames(
|
|
styles.contentContainer,
|
|
commonStyles.contentSpacingY
|
|
)}
|
|
>
|
|
<TextField
|
|
label="Username or email"
|
|
name="username"
|
|
type="string"
|
|
onChange={evt => setUsername(evt.target.value)}
|
|
value={username}
|
|
error={!!usernameError}
|
|
helperText={usernameError}
|
|
variant="outlined"
|
|
size="small"
|
|
/>
|
|
<TextField
|
|
label="Password"
|
|
onChange={evt => setPassword(evt.target.value)}
|
|
name="password"
|
|
type="password"
|
|
value={password}
|
|
error={!!passwordError}
|
|
helperText={passwordError}
|
|
variant="outlined"
|
|
size="small"
|
|
/>
|
|
<Grid container spacing={3}>
|
|
<Grid item xs={6}>
|
|
<Button
|
|
variant="contained"
|
|
color="primary"
|
|
type="submit"
|
|
style={{ maxWidth: '150px' }}
|
|
>
|
|
Sign in
|
|
</Button>
|
|
</Grid>
|
|
<Grid item xs={6}>
|
|
<Link to="/forgotten-password">
|
|
<Typography variant="body2" align="right">
|
|
Forgot your password?
|
|
</Typography>
|
|
</Link>
|
|
</Grid>
|
|
</Grid>
|
|
<br />
|
|
<br />
|
|
<Typography variant="body2" align="center">
|
|
Don't have an account? <br />{' '}
|
|
<a href="https://www.unleash-hosted.com/pricing">
|
|
Sign up
|
|
</a>
|
|
</Typography>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
PasswordAuth.propTypes = {
|
|
authDetails: PropTypes.object.isRequired,
|
|
passwordLogin: PropTypes.func.isRequired,
|
|
history: PropTypes.object.isRequired,
|
|
};
|
|
|
|
export default PasswordAuth;
|