Fixed registration bugs: empty password gets registered, credentials not being sent

This commit is contained in:
VakarisZ 2020-06-15 11:33:56 +03:00
parent 39231abbab
commit 5996569607
3 changed files with 20 additions and 17 deletions

View File

@ -65,8 +65,8 @@ class RegisterPageComponent extends React.Component {
<h3 className='reg-subtitle'>Let's secure your island!</h3> <h3 className='reg-subtitle'>Let's secure your island!</h3>
<div> <div>
<Form className={'registration-form'}> <Form className={'registration-form'}>
<Form.Control type='text' placeholder='Username'/> <Form.Control onChange={evt => this.updateUsername(evt)} type='text' placeholder='Username'/>
<Form.Control type='password' placeholder='Password'/> <Form.Control onChange={evt => this.updatePassword(evt)} type='password' placeholder='Password'/>
<Button id={'registration-button'} onClick={() => { <Button id={'registration-button'} onClick={() => {
this.register() this.register()
}}> }}>

View File

@ -1,5 +1,5 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
import {Col, Grid, Row} from 'react-bootstrap'; import {Col, Container, Row} from 'react-bootstrap';
import PillarsOverview from './PillarOverview'; import PillarsOverview from './PillarOverview';
import ZeroTrustReportLegend from './ReportLegend'; import ZeroTrustReportLegend from './ReportLegend';
import * as PropTypes from 'prop-types'; import * as PropTypes from 'prop-types';
@ -8,7 +8,7 @@ export default class SummarySection extends Component {
render() { render() {
return <div id="summary-section"> return <div id="summary-section">
<h2>Summary</h2> <h2>Summary</h2>
<Grid fluid={true}> <Container fluid>
<Row> <Row>
<Col xs={12} sm={12} md={12} lg={12}> <Col xs={12} sm={12} md={12} lg={12}>
<p> <p>
@ -28,7 +28,7 @@ export default class SummarySection extends Component {
<ZeroTrustReportLegend/> <ZeroTrustReportLegend/>
</Col> </Col>
</Row> </Row>
</Grid> </Container>
</div> </div>
} }
} }

View File

@ -51,7 +51,11 @@ export default class AuthService {
}; };
register = (username, password) => { register = (username, password) => {
return this._register(username, this.hashSha3(password)); if (password !== '') {
return this._register(username, this.hashSha3(password));
} else {
return this._register(username, password);
}
}; };
_register = (username, password) => { _register = (username, password) => {
@ -62,14 +66,14 @@ export default class AuthService {
'password_hash': password 'password_hash': password
}) })
}).then(res => { }).then(res => {
if (res.status === 200) { if (res.status === 200) {
return this._login(username, password) return this._login(username, password)
} else { } else {
return res.json().then(res_json => { return res.json().then(res_json => {
return {result: false, error: res_json['error']}; return {result: false, error: res_json['error']};
}) })
} }
}) })
}; };
_authFetch = (url, options = {}) => { _authFetch = (url, options = {}) => {
@ -101,7 +105,7 @@ export default class AuthService {
needsRegistration = () => { needsRegistration = () => {
return fetch(this.REGISTRATION_API_ENDPOINT, return fetch(this.REGISTRATION_API_ENDPOINT,
{method: 'GET'}) {method: 'GET'})
.then(response => response.json()) .then(response => response.json())
.then(res => { .then(res => {
return res['needs_registration'] return res['needs_registration']
@ -132,8 +136,7 @@ export default class AuthService {
_isTokenExpired(token) { _isTokenExpired(token) {
try { try {
return decode(token)['exp'] - this.SECONDS_BEFORE_JWT_EXPIRES < Date.now() / 1000; return decode(token)['exp'] - this.SECONDS_BEFORE_JWT_EXPIRES < Date.now() / 1000;
} } catch (err) {
catch (err) {
return false; return false;
} }
} }