mirror of
https://github.com/ansible/awx.git
synced 2026-03-16 08:27:29 -02:30
update login modal to grab error from RootDialog
This commit is contained in:
@@ -356,3 +356,11 @@
|
|||||||
color: var(--pf-global--success-color--200);
|
color: var(--pf-global--success-color--200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// LoginModal overrides
|
||||||
|
//
|
||||||
|
|
||||||
|
.pf-m-error p.pf-c-form__helper-text {
|
||||||
|
color: var(--pf-global--danger-color--100);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { Redirect } from 'react-router-dom';
|
import { Redirect, withRouter } from 'react-router-dom';
|
||||||
import { I18n } from '@lingui/react';
|
import { I18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import {
|
import {
|
||||||
@@ -7,6 +7,9 @@ import {
|
|||||||
LoginPage,
|
LoginPage,
|
||||||
} from '@patternfly/react-core';
|
} from '@patternfly/react-core';
|
||||||
|
|
||||||
|
import { withRootDialog } from '../contexts/RootDialog';
|
||||||
|
import { withNetwork } from '../contexts/Network';
|
||||||
|
|
||||||
import towerLogo from '../../images/tower-logo-header.svg';
|
import towerLogo from '../../images/tower-logo-header.svg';
|
||||||
|
|
||||||
class AWXLogin extends Component {
|
class AWXLogin extends Component {
|
||||||
@@ -17,7 +20,8 @@ class AWXLogin extends Component {
|
|||||||
username: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
isInputValid: true,
|
isInputValid: true,
|
||||||
isLoading: false
|
isLoading: false,
|
||||||
|
isAuthenticated: false
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onChangeUsername = this.onChangeUsername.bind(this);
|
this.onChangeUsername = this.onChangeUsername.bind(this);
|
||||||
@@ -35,7 +39,7 @@ class AWXLogin extends Component {
|
|||||||
|
|
||||||
async onLoginButtonClick (event) {
|
async onLoginButtonClick (event) {
|
||||||
const { username, password, isLoading } = this.state;
|
const { username, password, isLoading } = this.state;
|
||||||
const { api } = this.props;
|
const { api, handleHttpError, clearRootDialogMessage } = this.props;
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
@@ -43,25 +47,23 @@ class AWXLogin extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearRootDialogMessage();
|
||||||
this.setState({ isLoading: true });
|
this.setState({ isLoading: true });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await api.login(username, password);
|
await api.login(username, password);
|
||||||
|
this.setState({ isAuthenticated: true, isLoading: false });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response && error.response.status === 401) {
|
handleHttpError(error) || this.setState({ isInputValid: false, isLoading: false });
|
||||||
this.setState({ isInputValid: false });
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
this.setState({ isLoading: false });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { username, password, isInputValid } = this.state;
|
const { username, password, isInputValid, isAuthenticated } = this.state;
|
||||||
const { api, alt, loginInfo, logo } = this.props;
|
const { alt, loginInfo, logo, bodyText: errorMessage } = this.props;
|
||||||
const logoSrc = logo ? `data:image/jpeg;${logo}` : towerLogo;
|
const logoSrc = logo ? `data:image/jpeg;${logo}` : towerLogo;
|
||||||
|
|
||||||
if (api.isAuthenticated()) {
|
if (isAuthenticated) {
|
||||||
return (<Redirect to="/" />);
|
return (<Redirect to="/" />);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,10 +77,11 @@ class AWXLogin extends Component {
|
|||||||
textContent={loginInfo}
|
textContent={loginInfo}
|
||||||
>
|
>
|
||||||
<LoginForm
|
<LoginForm
|
||||||
|
className={errorMessage && 'pf-m-error'}
|
||||||
usernameLabel={i18n._(t`Username`)}
|
usernameLabel={i18n._(t`Username`)}
|
||||||
passwordLabel={i18n._(t`Password`)}
|
passwordLabel={i18n._(t`Password`)}
|
||||||
showHelperText={!isInputValid}
|
showHelperText={!isInputValid || !!errorMessage}
|
||||||
helperText={i18n._(t`Invalid username or password. Please try again.`)}
|
helperText={errorMessage || i18n._(t`Invalid username or password. Please try again.`)}
|
||||||
usernameValue={username}
|
usernameValue={username}
|
||||||
passwordValue={password}
|
passwordValue={password}
|
||||||
isValidUsername={isInputValid}
|
isValidUsername={isInputValid}
|
||||||
@@ -94,4 +97,4 @@ class AWXLogin extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AWXLogin;
|
export default withNetwork(withRootDialog(withRouter(AWXLogin)));
|
||||||
|
|||||||
Reference in New Issue
Block a user