import React from 'react'; import {Button} from '../../elements/GPElements/Button'; import style from './AuthenticationPage.module.css'; import {addKeyHandler, removeKeyHandler} from '../../utils/ShortkeyHandler'; import {faTimes} from '@fortawesome/free-solid-svg-icons'; import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import {LoginContext, LoginState} from '../../utils/context/LoginContext'; import {APINode, callApiUnsafe} from '../../utils/Api'; import {cookie, Token} from '../../utils/context/Cookie'; interface state { pwdText: string; wrongPWDInfo: boolean; } interface Props {} class AuthenticationPage extends React.Component { constructor(props: Props) { super(props); this.state = { pwdText: '', wrongPWDInfo: false }; this.keypress = this.keypress.bind(this); this.authenticate = this.authenticate.bind(this); } componentDidMount(): void { addKeyHandler(this.keypress); } componentWillUnmount(): void { removeKeyHandler(this.keypress); } static contextType = LoginContext; render(): JSX.Element { return ( <>
OpenMediaCenter
Login
this.setState({pwdText: ch.target.value})} value={this.state.pwdText} /> {this.state.wrongPWDInfo ? (
wrong password!
) : null}
); } /** * request a new token and check if pwd was valid */ authenticate(): void { callApiUnsafe( APINode.Login, {action: 'login', Password: this.state.pwdText}, (r: Token) => { cookie.Store(r); this.context.setLoginState(LoginState.LoggedIn); }, (e) => { console.log(e); } ); } /** * key event handling * @param event keyevent */ keypress(event: KeyboardEvent): void { // hide if escape is pressed if (event.key === 'Enter') { // call submit this.authenticate(); } } } export default AuthenticationPage;