From f4dd88ed642fcae8316e12c75685eeffb0508624 Mon Sep 17 00:00:00 2001
From: Kegan Dougal <kegan@matrix.org>
Date: Thu, 12 Nov 2015 11:54:35 +0000
Subject: [PATCH] Remove ServerConfig; Add Signup logic class

- ServerConfig seems too specific to Vector, but we can always add it back later.
- Signup.js contains all the logic for determining what to show which was
  previously in UI components.
---
 src/Signup.js                             | 49 +++++++++++++++++
 src/controllers/molecules/ServerConfig.js | 67 -----------------------
 2 files changed, 49 insertions(+), 67 deletions(-)
 create mode 100644 src/Signup.js
 delete mode 100644 src/controllers/molecules/ServerConfig.js

diff --git a/src/Signup.js b/src/Signup.js
new file mode 100644
index 0000000000..06b70fb7f5
--- /dev/null
+++ b/src/Signup.js
@@ -0,0 +1,49 @@
+"use strict";
+var MatrixClientPeg = require("./MatrixClientPeg");
+var dis = require("./dispatcher");
+
+class Register {
+
+}
+
+class Login {
+    constructor(hsUrl, isUrl) {
+        this._hsUrl = hsUrl;
+        this._isUrl = isUrl;
+        this._currentFlowIndex = 0;
+        this._flows = [];
+    }
+
+    getFlows() {
+        var self = this;
+        // feels a bit wrong to be clobbering the global client for something we
+        // don't even know if it'll work, but we'll leave this here for now to
+        // not complicate matters further. It would be nicer to isolate this
+        // logic entirely from the rest of the app though.
+        MatrixClientPeg.replaceUsingUrls(
+            this._hsUrl,
+            this._isUrl
+        );
+        return MatrixClientPeg.get().loginFlows().then(function(result) {
+            self._flows = result.flows;
+            self._currentFlowIndex = 0;
+            // technically the UI should display options for all flows for the
+            // user to then choose one, so return all the flows here.
+            return self._flows;
+        });
+    }
+
+    chooseFlow(flowIndex) {
+        this._currentFlowIndex = flowIndex;
+    }
+
+    getCurrentFlowStep() {
+        // technically the flow can have multiple steps, but no one does this
+        // for login so we can ignore it.
+        var flowStep = this._flows[this._currentFlowIndex];
+        return flowStep ? flowStep.type : null;
+    }
+}
+
+module.exports.Register = Register;
+module.exports.Login = Login;
diff --git a/src/controllers/molecules/ServerConfig.js b/src/controllers/molecules/ServerConfig.js
deleted file mode 100644
index 77fcb1d8c5..0000000000
--- a/src/controllers/molecules/ServerConfig.js
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
-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");
-
-module.exports = {
-    propTypes: {
-        onHsUrlChanged: React.PropTypes.func,
-        onIsUrlChanged: React.PropTypes.func,
-        defaultHsUrl: React.PropTypes.string,
-        defaultIsUrl: React.PropTypes.string
-    },
-
-    getDefaultProps: function() {
-        return {
-            onHsUrlChanged: function() {},
-            onIsUrlChanged: function() {},
-            defaultHsUrl: 'https://matrix.org/',
-            defaultIsUrl: 'https://matrix.org/'
-        };
-    },
-
-    getInitialState: function() {
-        return {
-            hs_url: this.props.defaultHsUrl,
-            is_url: this.props.defaultIsUrl,
-            original_hs_url: this.props.defaultHsUrl,
-            original_is_url: this.props.defaultIsUrl,
-        }
-    },
-
-    hsChanged: function(ev) {
-        this.setState({hs_url: ev.target.value}, function() {
-            this.props.onHsUrlChanged(this.state.hs_url);
-        });
-    },
-
-    // XXX: horrible naming due to potential confusion between the word 'is' and the acronym 'IS'
-    isChanged: function(ev) {
-        this.setState({is_url: ev.target.value}, function() {
-            this.props.onIsUrlChanged(this.state.is_url);
-        });
-    },
-
-    getHsUrl: function() {
-        return this.state.hs_url;
-    },
-
-    getIsUrl: function() {
-        return this.state.is_url;
-    },
-};