diff --git a/src/js/login.js b/src/js/login.js index bb7ea9ef4..52300f0d2 100644 --- a/src/js/login.js +++ b/src/js/login.js @@ -10,24 +10,24 @@ app.controller('LoginController', ['$scope', '$http', function ($scope, $http) { var search = decodeURIComponent(window.location.search).slice(1).split('&').map(function (item) { return item.indexOf('=') === -1 ? [item, true] : [item.slice(0, item.indexOf('=')), item.slice(item.indexOf('=')+1)]; }).reduce(function (o, k) { o[k[0]] = k[1]; return o; }, {}); $scope.initialized = false; - $scope.passwordReset = !!search.passwordReset; + $scope.mode = search.passwordReset ? 'passwordReset' : 'login'; $scope.busy = false; - $scope.error = null; + $scope.error = false; $scope.username = ''; $scope.password = ''; $scope.totpToken = ''; $scope.passwordResetIdentifier = ''; + var API_ORIGIN = '<%= oauth.apiOrigin %>' || window.location.origin; $scope.onLogin = function () { $scope.busy = true; - $scope.error = null; + $scope.error = false; var data = { username: $scope.username, password: $scope.password, totpToken: $scope.totpToken }; - var apiOrigin = '<%= oauth.apiOrigin %>' || window.location.origin; function error() { $scope.busy = false; @@ -38,7 +38,7 @@ app.controller('LoginController', ['$scope', '$http', function ($scope, $http) { setTimeout(function () { $('#inputPassword').focus(); }, 200); } - $http.post(apiOrigin + '/api/v1/cloudron/login', data).success(function (data, status) { + $http.post(API_ORIGIN + '/api/v1/cloudron/login', data).success(function (data, status) { if (status !== 200) return error(); localStorage.token = data.accessToken; @@ -47,16 +47,31 @@ app.controller('LoginController', ['$scope', '$http', function ($scope, $http) { }; $scope.onPasswordReset = function () { + $scope.busy = true; + var data = { + identifier: $scope.passwordResetIdentifier + }; + + function done() { + $scope.busy = false; + $scope.mode = 'passwordResetDone'; + } + + $http.post(API_ORIGIN + '/api/v1/cloudron/password_reset', data).success(done).error(done); }; $scope.showPasswordReset = function () { - $scope.passwordReset = true; + window.document.title = 'Password Reset'; + $scope.mode = 'passwordReset'; + $scope.passwordResetIdentifier = ''; setTimeout(function () { $('#inputPasswordResetIdentifier').focus(); }, 200); }; $scope.showLogin = function () { - $scope.passwordReset = false; + window.document.title = 'Cloudron Login'; + $scope.mode = 'login'; + $scope.error = false; setTimeout(function () { $('#inputUsername').focus(); }, 200); }; }]); diff --git a/src/login.html b/src/login.html index c94ac5570..72bb543e8 100644 --- a/src/login.html +++ b/src/login.html @@ -5,7 +5,7 @@ -