import React from 'react'; import { Input, Button, Container, Icon } from '../../components/'; import { Config, Admin } from '../../model/'; import { notify, FormObjToJSON, alert, prompt } from '../../helpers'; import { bcrypt_password } from '../../helpers/bcrypt'; import ReactCSSTransitionGroup from 'react-addons-css-transition-group'; import "./setup.scss"; export class SetupPage extends React.Component { constructor(props){ super(props); this.state = { stage: 0, password: "", enable_telemetry: false, creating_password: false }; } createPassword(e){ this.setState({creating_password: true}); e.preventDefault(); Config.all().then((config) => { this.setState({enable_telemetry: config.log.telemetry.value}, () => { if(this.state.enable_telemetry === true) return; this.unlisten = this.props.history.listen((location, action) => { this.unlisten(); alert.now((

Help making this software better by sending crash reports and anonymous usage statistics

)); }); }); bcrypt_password(this.state.password) .then((hash) => { config.auth.admin.value = hash; config = FormObjToJSON(config); config.connections = window.CONFIG.connections; Config.save(config, false) .then(() => Admin.login(this.state.password)) .then(() => this.setState({stage: 1, creating_password: false})) .catch((err) => { notify.send(err && err.message, "error"); this.setState({creating_password: false}); }); }) .catch((err) => { notify.send("Hash error: " + JSON.stringify(err), "error"); this.setState({creating_password: false}); }); }); } enableLog(value){ Config.all().then((config) => { config.log.telemetry.value = value; config = FormObjToJSON(config); config.connections = window.CONFIG.connections; Config.save(config, false); }); } start(e){ e.preventDefault(); this.props.history.push("/"); } renderStage(stage){ if(stage === 0){ return (

You made it chief! { this.state.creating_password === true ? : null}

Let's start by protecting the admin area with a password:

this.setState({password: e.target.value})} autoComplete="new-password"/>