summary refs log tree commit diff
path: root/webclient/login
diff options
context:
space:
mode:
authormatrix.org <matrix@matrix.org>2014-08-12 15:10:52 +0100
committermatrix.org <matrix@matrix.org>2014-08-12 15:10:52 +0100
commit4f475c7697722e946e39e42f38f3dd03a95d8765 (patch)
tree076d96d3809fb836c7245fd9f7960e7b75888a77 /webclient/login
downloadsynapse-4f475c7697722e946e39e42f38f3dd03a95d8765.tar.xz
Reference Matrix Home Server
Diffstat (limited to 'webclient/login')
-rw-r--r--webclient/login/login-controller.js81
-rw-r--r--webclient/login/login.html51
2 files changed, 132 insertions, 0 deletions
diff --git a/webclient/login/login-controller.js b/webclient/login/login-controller.js
new file mode 100644
index 0000000000..26590da686
--- /dev/null
+++ b/webclient/login/login-controller.js
@@ -0,0 +1,81 @@
+angular.module('LoginController', ['matrixService'])
+.controller('LoginController', ['$scope', '$location', 'matrixService',
+                                    function($scope, $location, matrixService) {
+    'use strict';
+    
+    $scope.account = {
+        homeserver: "http://localhost:8080",
+        desired_user_name: "",
+        user_id: "",
+        password: "",
+        identityServer: "http://localhost:8090",
+        pwd1: "",
+        pwd2: ""
+    };
+
+    $scope.register = function() {
+
+        // Set the urls
+        matrixService.setConfig({
+            homeserver: $scope.account.homeserver,
+            identityServer: $scope.account.identityServer
+        });
+        
+        if ($scope.account.pwd1 !== $scope.account.pwd2) {
+            $scope.feedback = "Passwords don't match.";
+            return;
+        }
+        else if ($scope.account.pwd1.length < 6) {
+            $scope.feedback = "Password must be at least 6 characters.";
+            return;
+        }
+
+        matrixService.register($scope.account.desired_user_name, $scope.account.pwd1).then(
+            function(data) {
+                $scope.feedback = "Success";
+
+                // Update the current config 
+                var config = matrixService.config();
+                angular.extend(config, {
+                    access_token: data.access_token,
+                    user_id: data.user_id
+                });
+                matrixService.setConfig(config);
+
+                // And permanently save it
+                matrixService.saveConfig();
+
+                 // Go to the user's rooms list page
+                $location.path("rooms");
+            },
+            function(reason) {
+                $scope.feedback = "Failure: " + reason;
+            });
+    };
+
+    $scope.login = function() {
+        matrixService.setConfig({
+            homeserver: $scope.account.homeserver,
+            user_id: $scope.account.user_id
+        });
+        // try to login
+        matrixService.login($scope.account.user_id, $scope.account.password).then(
+            function(response) {
+                if ("access_token" in response) {
+                    $scope.feedback = "Login successful.";
+                    matrixService.setConfig({
+                        homeserver: $scope.account.homeserver,
+                        user_id: $scope.account.user_id,
+                        access_token: response.access_token
+                    });
+                    matrixService.saveConfig();
+                    $location.path("rooms");
+                }
+                else {
+                    $scope.feedback = "Failed to login: " + JSON.stringify(response);
+                }
+            }
+        );
+    };
+}]);
+
diff --git a/webclient/login/login.html b/webclient/login/login.html
new file mode 100644
index 0000000000..0d3e8c57fd
--- /dev/null
+++ b/webclient/login/login.html
@@ -0,0 +1,51 @@
+<div ng-controller="LoginController" class="login">
+    <div class="page">
+
+    {{ feedback }}
+        
+    <h3>Register for an account:</h3>
+    <form novalidate>
+        <input id="desired_user_name" size="70" type="text" auto-focus ng-model="account.desired_user_name" placeholder="User name (ex:bob)"/>
+        <br/>
+        <input id="pwd1" size="70" type="password" auto-focus ng-model="account.pwd1" placeholder="Type a password"/>
+        <br/>
+        <input id="pwd2" size="70" type="password" auto-focus ng-model="account.pwd2" placeholder="Re-type your password"/>
+        <br/>
+        <!-- New user registration -->
+        <div>
+            <br/>
+            <button ng-click="register()" ng-disabled="!account.desired_user_name || !account.homeserver || !account.identityServer || !account.pwd1 || !account.pwd2">Register</button>
+        </div>
+    </form>
+
+    <h3>Got an account?</h3>
+    <form novalidate>
+        <!-- Login with an registered user -->
+        <div>
+            <input id="user_id" size="70" type="text" auto-focus ng-model="account.user_id" placeholder="User ID (ex:@bob:localhost)"/>
+            <br />
+            <input id="password" size="70" type="password" ng-model="account.password" placeholder="Password"/><br />
+            <br/>
+            <button ng-click="login()" ng-disabled="!account.user_id || !account.password || !account.homeserver || !account.identityServer">Login</button>
+        </div>
+       
+    </form>
+
+    <h3>Servers</h3>
+    <form novalidate>
+        <div>
+        Home Server: 
+        <input id="homeserver" size="57" type="text" ng-model="account.homeserver" placeholder="Home server URL (ex: http://localhost:8080)"/>
+        </div>
+        <br />
+        <div>
+        Identity Server: 
+        <input id="identityServer" size="56" type="text" ng-model="account.identityServer" placeholder="Identity server URL (ex: http://localhost:8090)"/>
+        </div>
+        <br />
+    </form>
+    <br/>
+    
+
+    </div>
+</div>