diff -r 06f609adfbf8 -r 990f2c928b15 client/src/components/Login.js --- a/client/src/components/Login.js Mon Jun 26 15:45:50 2017 +0200 +++ b/client/src/components/Login.js Mon Jun 26 16:43:22 2017 +0200 @@ -1,7 +1,7 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; -import { Grid, Row, Col, Panel, FormGroup, ControlLabel, FormControl, Button, Alert } from 'react-bootstrap'; +import { Grid, Row, Col, Panel, FormGroup, ControlLabel, FormControl, Button, Alert, HelpBlock } from 'react-bootstrap'; import '../App.css'; import Navbar from './Navbar'; import * as authActions from '../actions/authActions'; @@ -20,10 +20,25 @@ this.props.history.push('/register'); } - renderError() { - return ( - Bad credentials - ) + renderErrorMessage(errorMessages, fieldname) { + if (errorMessages && errorMessages.has(fieldname)) { + return errorMessages.get(fieldname).map((message, key) => + { message } + ); + } + } + + renderNonFieldErrors(errorMessages) { + if (errorMessages && errorMessages.has('non_field_errors')) { + const errors = errorMessages.get('non_field_errors'); + return ( + + { errors.map((message, key) => +

{ message }

+ ) } +
+ ) + } } render() { @@ -32,6 +47,8 @@

Login

) + const errorMessages = this.props.login.get('errorMessages'); + return (
@@ -40,15 +57,17 @@
- + Username { this.username = ref; }} /> + { this.renderErrorMessage(errorMessages, 'username') } - + Password { this.password = ref; }} /> + { this.renderErrorMessage(errorMessages, 'password') } - { this.props.login.error && this.renderError() } + { this.renderNonFieldErrors(errorMessages) }
@@ -65,7 +84,6 @@ function mapStateToProps(state, props) { return { - currentUser: state['currentUser'], login: state['login'] }; }