summary refs log tree commit diff
path: root/webclient/login/login-controller.js
diff options
context:
space:
mode:
authorDavid Baker <dbkr@matrix.org>2014-09-03 18:23:56 +0100
committerDavid Baker <dbkr@matrix.org>2014-09-03 18:23:56 +0100
commita25d1530ef9f48e5853ee735674d8e2251a8cbb0 (patch)
tree6260c381c4d9d69b678db2e5f7d151e5a606ae5f /webclient/login/login-controller.js
parentAdd support for registering with a threepid to the HS (get credentials from t... (diff)
downloadsynapse-a25d1530ef9f48e5853ee735674d8e2251a8cbb0.tar.xz
Make registering and logging in with a threepid work in the webclient.
Diffstat (limited to 'webclient/login/login-controller.js')
-rw-r--r--webclient/login/login-controller.js33
1 files changed, 30 insertions, 3 deletions
diff --git a/webclient/login/login-controller.js b/webclient/login/login-controller.js
index 7369a28ef0..e367b2f0c5 100644
--- a/webclient/login/login-controller.js
+++ b/webclient/login/login-controller.js
@@ -15,8 +15,8 @@
  */
  
 angular.module('LoginController', ['matrixService'])
-.controller('LoginController', ['$scope', '$location', 'matrixService', 'eventStreamService',
-                                    function($scope, $location, matrixService, eventStreamService) {
+.controller('LoginController', ['$scope', '$rootScope', '$location', 'matrixService', 'eventStreamService',
+                                    function($scope, $rootScope, $location, matrixService, eventStreamService) {
     'use strict';
     
     
@@ -51,10 +51,36 @@ angular.module('LoginController', ['matrixService'])
         matrixService.setConfig({
             homeserver: $scope.account.homeserver,
             identityServer: $scope.account.identityServer,
+        });
+        switch ($scope.login_type) {
+            case 'mxid':
+                $scope.login_with_mxid($scope.account.user_id, $scope.account.password);
+                break;
+            case 'email':
+                matrixService.lookup3pid('email', $scope.account.user_id).then(
+                    function(response) {
+                        if (response.data['address'] == undefined) {
+                            $scope.login_error_msg = "Invalid email address / password";
+                        } else {
+                            console.log("Got address "+response.data['mxid']+" for email "+$scope.account.user_id);
+                            $scope.login_with_mxid(response.data['mxid'], $scope.account.password);
+                        }
+                    },
+                    function() {
+                        $scope.login_error_msg = "Couldn't look up email address. Is your identity server set correctly?";
+                    }
+                );
+        }
+    };
+
+    $scope.login_with_mxid = function(mxid, password) {
+        matrixService.setConfig({
+            homeserver: $scope.account.homeserver,
+            identityServer: $scope.account.identityServer,
             user_id: $scope.account.user_id
         });
         // try to login
-        matrixService.login($scope.account.user_id, $scope.account.password).then(
+        matrixService.login(mxid, password).then(
             function(response) {
                 if ("access_token" in response.data) {
                     $scope.feedback = "Login successful.";
@@ -65,6 +91,7 @@ angular.module('LoginController', ['matrixService'])
                         access_token: response.data.access_token
                     });
                     matrixService.saveConfig();
+                    $rootScope.updateHeader();
                     eventStreamService.resume();
                     $location.url("home");
                 }