Skip to content

Commit a1978bd

Browse files
authored
Merge pull request #3069 from guardicore/2157-display-login-errors
2157 display login errors
2 parents 6176975 + 0a7ebe4 commit a1978bd

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

monkey/monkey_island/cc/ui/src/components/pages/LoginPage.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import {Button, Col, Container, Form, Row} from 'react-bootstrap';
33

4-
import AuthService from '../../services/AuthService';
4+
import AuthService, {getErrors} from '../../services/AuthService';
55
import monkeyGeneral from '../../images/militant-monkey.svg';
66
import ParticleBackground from '../ui-components/ParticleBackground';
77

@@ -12,7 +12,7 @@ class LoginPageComponent extends React.Component {
1212
if (res['result']) {
1313
this.redirectToHome();
1414
} else {
15-
this.setState({failed: true});
15+
this.setState({failed: true, errors: res['errors']});
1616
}
1717
});
1818
};
@@ -73,7 +73,7 @@ class LoginPageComponent extends React.Component {
7373
</Button>
7474
{
7575
this.state.failed ?
76-
<div className="alert alert-danger" role="alert">Login failed. Bad credentials.</div>
76+
<div className="alert alert-danger" role="alert">{getErrors(this.state.errors)}</div>
7777
:
7878
''
7979
}

monkey/monkey_island/cc/ui/src/components/pages/RegisterPage.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import {Row, Col, Container, Form, Button} from 'react-bootstrap';
33

4-
import AuthService from '../../services/AuthService';
4+
import AuthService, {getErrors} from '../../services/AuthService';
55
import monkeyDetective from '../../images/detective-monkey.svg';
66
import ParticleBackground from '../ui-components/ParticleBackground';
77
import LoadingIcon from '../ui-components/LoadingIcon';
@@ -37,16 +37,6 @@ class RegisterPageComponent extends React.Component {
3737
window.location.href = '/landing-page';
3838
};
3939

40-
getErrors = (errors) => {
41-
const errorArray = [];
42-
43-
for (let i=0; i<errors.length; i++) {
44-
const key = 'registration-error-' + i
45-
errorArray.push(<li key={key}>{errors[i]}</li>);
46-
}
47-
return <ul>{errorArray}</ul>;
48-
};
49-
5040
constructor(props) {
5141
super(props);
5242
this.username = '';
@@ -92,7 +82,7 @@ class RegisterPageComponent extends React.Component {
9282
<Col>
9383
{
9484
this.state.failed ?
95-
<div className='alert alert-danger' role='alert'>{this.getErrors(this.state.errors)}</div>
85+
<div className='alert alert-danger' role='alert'>{getErrors(this.state.errors)}</div>
9686
:
9787
''
9888
}

monkey/monkey_island/cc/ui/src/services/AuthService.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
import _ from 'lodash';
2+
import React from 'react';
3+
4+
export function getErrors(errors) {
5+
const errorArray = [];
6+
7+
for (let i=0; i<errors.length; i++) {
8+
const key = 'registration-error-' + i
9+
errorArray.push(<li key={key}>{errors[i]}</li>);
10+
}
11+
return <ul>{errorArray}</ul>;
12+
}
213

314
export default class AuthService {
415
LOGIN_ENDPOINT = '/api/login?include_auth_token';
@@ -43,7 +54,7 @@ export default class AuthService {
4354
return {result: true};
4455
} else {
4556
this._removeToken();
46-
return {result: false};
57+
return {result: false, errors: res['response']['errors']};
4758
}
4859
})
4960
};

0 commit comments

Comments
 (0)