remove .map files from production build
show error message if wrong password was entered.
This commit is contained in:
@ -2,13 +2,17 @@ import React from 'react';
|
||||
import {Button} from '../../elements/GPElements/Button';
|
||||
import style from './AuthenticationPage.module.css';
|
||||
import {addKeyHandler, removeKeyHandler} from '../../utils/ShortkeyHandler';
|
||||
import {refreshAPIToken} from '../../utils/Api';
|
||||
import {faTimes} from '@fortawesome/free-solid-svg-icons';
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
|
||||
|
||||
interface state {
|
||||
pwdText: string;
|
||||
wrongPWDInfo: boolean;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
submit: (password: string) => void;
|
||||
onSuccessLogin: () => void;
|
||||
}
|
||||
|
||||
class AuthenticationPage extends React.Component<Props, state> {
|
||||
@ -16,10 +20,12 @@ class AuthenticationPage extends React.Component<Props, state> {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
pwdText: ''
|
||||
pwdText: '',
|
||||
wrongPWDInfo: false
|
||||
};
|
||||
|
||||
this.keypress = this.keypress.bind(this);
|
||||
this.authenticate = this.authenticate.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount(): void {
|
||||
@ -44,20 +50,50 @@ class AuthenticationPage extends React.Component<Props, state> {
|
||||
onChange={(ch): void => this.setState({pwdText: ch.target.value})}
|
||||
value={this.state.pwdText}
|
||||
/>
|
||||
{this.state.wrongPWDInfo ? (
|
||||
<div>
|
||||
<FontAwesomeIcon
|
||||
style={{
|
||||
color: 'red',
|
||||
marginRight: '7px'
|
||||
}}
|
||||
icon={faTimes}
|
||||
size='1x'
|
||||
/>
|
||||
wrong password!
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div>
|
||||
<Button
|
||||
title='Submit'
|
||||
onClick={(): void => {
|
||||
this.props.submit(this.state.pwdText);
|
||||
}}
|
||||
/>
|
||||
<div className={style.submitbtn}>
|
||||
<Button title='Submit' onClick={this.authenticate} />
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* request a new token and check if pwd was valid
|
||||
*/
|
||||
authenticate(): void {
|
||||
refreshAPIToken(
|
||||
(error) => {
|
||||
if (error !== '') {
|
||||
this.setState({wrongPWDInfo: true});
|
||||
|
||||
// set timeout to make the info auto-disappearing
|
||||
setTimeout(() => {
|
||||
this.setState({wrongPWDInfo: false});
|
||||
}, 2000);
|
||||
} else {
|
||||
this.props.onSuccessLogin();
|
||||
}
|
||||
},
|
||||
true,
|
||||
this.state.pwdText
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* key event handling
|
||||
* @param event keyevent
|
||||
@ -65,10 +101,8 @@ class AuthenticationPage extends React.Component<Props, state> {
|
||||
keypress(event: KeyboardEvent): void {
|
||||
// hide if escape is pressed
|
||||
if (event.key === 'Enter') {
|
||||
// call a parentsubmit if defined
|
||||
if (this.props.submit) {
|
||||
this.props.submit(this.state.pwdText);
|
||||
}
|
||||
// call submit
|
||||
this.authenticate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user