diff --git a/src/js/login.js b/src/js/login.js index 52300f0d2..f674a0b84 100644 --- a/src/js/login.js +++ b/src/js/login.js @@ -10,15 +10,26 @@ 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.mode = search.passwordReset ? 'passwordReset' : 'login'; + $scope.mode = ''; $scope.busy = false; $scope.error = false; $scope.username = ''; $scope.password = ''; $scope.totpToken = ''; $scope.passwordResetIdentifier = ''; + $scope.newPassword = ''; + $scope.newPasswordRepeat = ''; var API_ORIGIN = '<%= oauth.apiOrigin %>' || window.location.origin; + if (search.passwordReset) { + $scope.mode = 'passwordReset'; + } else if (search.resetToken) { + $scope.mode = 'newPassword'; + setTimeout(function () { $('#inputNewPassword').focus(); }, 200); + } else { + $scope.mode = 'login'; + } + $scope.onLogin = function () { $scope.busy = true; $scope.error = false; @@ -58,7 +69,36 @@ app.controller('LoginController', ['$scope', '$http', function ($scope, $http) { $scope.mode = 'passwordResetDone'; } - $http.post(API_ORIGIN + '/api/v1/cloudron/password_reset', data).success(done).error(done); + $http.post(API_ORIGIN + '/api/v1/cloudron/password_reset_request', data).success(done).error(done); + }; + + $scope.onNewPassword = function () { + $scope.busy = true; + + var data = { + resetToken: search.resetToken, + password: $scope.newPassword + }; + + function error(status) { + console.log('error', status) + $scope.busy = false; + + if (status === 401) $scope.error = 'Invalid reset token'; + else if (status === 409) $scope.error = 'Ask your admin for an invite link first'; + else $scope.error = 'Unknown error'; + } + + $http.post(API_ORIGIN + '/api/v1/cloudron/password_reset', data).success(function (data, status) { + if (status !== 202) return error(status); + + // set token to autologin + localStorage.token = data.accessToken; + + $scope.mode = 'newPasswordDone'; + }).error(function (data, status) { + error(status); + }); }; $scope.showPasswordReset = function () { diff --git a/src/login.html b/src/login.html index 72bb543e8..2eec5148c 100644 --- a/src/login.html +++ b/src/login.html @@ -96,7 +96,7 @@
- + Back to login @@ -118,6 +118,63 @@ +
+
+
+
+ +
+

Set new Password

+
+
+
+
+
+

{{ error }}

+
+
+
+
+
+
+ +
+ +
+ Password must be atleast 8 characters +
+ +
+
+ +
+ Passwords don't match +
+ +
+
+ +
+ Back to login +
+
+
+
+ +
+
+
+
+ +
+

New Password set

+
+ Open Dashboard +
+
+
+
+