import React, {Component} from 'react'; import './Config.scss'; import {Button, ButtonGroup, Col, Container, Form, Modal, Row, Table, ToggleButton} from "react-bootstrap"; class Config extends Component { constructor(props) { super(props); this.state = { server_address: "", flag_regex: "", auth_required: false, accounts: {}, showSignup: false, showConfig: true, tmpUser:"", tmpPass:"", tmpConf:"", errors:"" }; this.serverIpChanged = this.serverIpChanged.bind(this); this.flagRegexChanged = this.flagRegexChanged.bind(this); this.authRequiredChanged = this.authRequiredChanged.bind(this); this.userChanged = this.userChanged.bind(this); this.passwdChanged = this.passwdChanged.bind(this); this.confirmChanged = this.confirmChanged.bind(this); } serverIpChanged(event) { this.setState({server_address: event.target.value}); } flagRegexChanged(event) { this.setState({flag_regex: event.target.value}); } authRequiredChanged() { this.setState({auth_required: !this.value}); this.checked = !this.checked; this.value = !this.value; } userChanged(event) { this.setState({tmpUser: event.target.value}); } passwdChanged(event) { this.setState({tmpPass: event.target.value}); } confirmChanged(event) { this.setState({tmpConf: event.target.value}); } setup() { const requestOptions = { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ config: { server_address: this.state.server_address, flag_regex: this.state.flag_regex, auth_required: this.state.auth_required, }, accounts: this.state.accounts }) }; let msg = ""; fetch('/setup', requestOptions) .then(response => { if (response.status === 202 ){ //this.setState({showConfig:false}); this.props.onHide(); this.props.onDone(); } else { response.json().then(data => { this.setState( {errors : data.error.toString()} ); }); } } ); } signup(){ if (this.state.tmpPass === this.state.tmpConf){ const accounts = {...this.state.accounts}; accounts[this.state.tmpUser] = this.state.tmpPass; this.setState({accounts}); console.log(this.state); this.setState({showSignup:false,showConfig:true}) } this.setState({tmpUser : ""}); this.setState({tmpPass : ""}); this.setState({tmpConf : ""}); } render() { let rows = Object.keys(this.state.accounts).map(u => {u} ); return ( <> # passwd
username: password: confirm password:
~/.config
this.authRequiredChanged()} > Authentication {rows}
users
server_address: flag_regex:
{this.state.errors .split('\n').map((item, key) => { return {item}
}) }
); } } export default Config;