/* Copyright 2015 OpenMarket Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ 'use strict'; var React = require('react'); var sdk = require('matrix-react-sdk') var MatrixClientPeg = require('matrix-react-sdk/lib/MatrixClientPeg') var RegisterController = require('../../../../controllers/templates/Register') var ServerConfig = require("../../../../components/login/ServerConfig"); var config = require('../../../../../config.json'); module.exports = React.createClass({ displayName: 'Register', mixins: [RegisterController], getInitialState: function() { // TODO: factor out all localstorage stuff into its own home. // This is common to Login, Register and MatrixClientPeg var localStorage = window.localStorage; var hs_url, is_url; if (localStorage) { hs_url = localStorage.getItem("mx_hs_url"); is_url = localStorage.getItem("mx_is_url"); } // make sure we have our MatrixClient set up whatever // Useful for debugging only. // MatrixClientPeg.replaceUsingUrls( // hs_url || config.default_hs_url, // is_url || config.default_is_url // ); return { customHsUrl: hs_url || config.default_hs_url, customIsUrl: is_url || config.default_is_url, serverConfigVisible: (hs_url && hs_url !== config.default_hs_url || is_url && is_url !== config.default_is_url) } }, getRegFormVals: function() { return { email: this.refs.email.value.trim(), username: this.refs.username.value.trim(), password: this.refs.password.value.trim(), confirmPassword: this.refs.confirmPassword.value.trim() }; }, getHsUrl: function() { if (this.state.serverConfigVisible) { return this.state.customHsUrl; } else { return config.default_hs_url; } }, getIsUrl: function() { if (this.state.serverConfigVisible) { return this.state.customIsUrl; } else { return config.default_is_url; } }, onServerConfigVisibleChange: function(ev) { this.setState({ serverConfigVisible: ev.target.checked }); }, onServerUrlChanged: function(newUrl) { this.setState({ customHsUrl: this.refs.serverConfig.getHsUrl(), customIsUrl: this.refs.serverConfig.getIsUrl(), }); this.forceUpdate(); }, onProfileContinueClicked: function() { this.onAccountReady(); }, componentForStep: function(step) { switch (step) { case 'initial': var serverConfigStyle = {}; serverConfigStyle.display = this.state.serverConfigVisible ? 'block' : 'none'; return (