/* 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 LoginController = require('matrix-react-sdk/lib/controllers/templates/Login') var config = require('../../../../../config.json'); module.exports = React.createClass({ displayName: 'Login', mixins: [LoginController], getInitialState: function() { return { serverConfigVisible: false }; }, componentWillMount: function() { this.onHSChosen(); this.customHsUrl = config.default_hs_url; this.customIsUrl = config.default_is_url; }, getHsUrl: function() { if (this.state.serverConfigVisible) { return this.customHsUrl; } else { return config.default_hs_url; } }, getIsUrl: function() { if (this.state.serverConfigVisible) { return this.customIsUrl; } else { return config.default_is_url; } }, onServerConfigVisibleChange: function(ev) { this.setState({ serverConfigVisible: ev.target.checked }, this.onHsUrlChanged); }, /** * Gets the form field values for the current login stage */ getFormVals: function() { return { 'username': this.refs.user.value.trim(), 'password': this.refs.pass.value.trim() }; }, onHsUrlChanged: function() { var newHsUrl = this.refs.serverConfig.getHsUrl().trim(); var newIsUrl = this.refs.serverConfig.getIsUrl().trim(); if (newHsUrl == this.customHsUrl && newIsUrl == this.customIsUrl) { return; } else { this.customHsUrl = newHsUrl; this.customIsUrl = newIsUrl; } MatrixClientPeg.replaceUsingUrls( this.getHsUrl(), this.getIsUrl() ); this.setState({ hs_url: this.getHsUrl(), is_url: this.getIsUrl() }); // XXX: HSes do not have to offer password auth, so we // need to update and maybe show a different component // when a new HS is entered. if (this.updateHsTimeout) { clearTimeout(this.updateHsTimeout); } var self = this; this.updateHsTimeout = setTimeout(function() { self.onHSChosen(); }, 1000); }, componentForStep: function(step) { switch (step) { case 'choose_hs': case 'fetch_stages': var serverConfigStyle = {}; serverConfigStyle.display = this.state.serverConfigVisible ? 'block' : 'none'; var ServerConfig = sdk.getComponent("molecules.ServerConfig"); return (
); // XXX: clearly these should be separate organisms case 'stage_m.login.password': return (


{ this.componentForStep('choose_hs') }
); case 'stage_m.login.cas': var CasLogin = sdk.getComponent('organisms.CasLogin'); return ( ); } }, onUsernameChanged: function(ev) { this.setState({username: ev.target.value}); }, onPasswordChanged: function(ev) { this.setState({password: ev.target.value}); }, loginContent: function() { var Loader = sdk.getComponent("atoms.Spinner"); var loader = this.state.busy ?
: null; return (

Sign in

{this.componentForStep(this.state.step)}
{ loader } {this.state.errorText}
Create a new account
blog  ·   twitter  ·   github  ·   powered by Matrix
); }, render: function() { return (
vector
{this.loginContent()}
); } });