Fixup password reset page

This commit is contained in:
Johannes Zellner
2020-02-04 15:53:56 +01:00
parent a50fa9bcf4
commit 0762b337b8
2 changed files with 46 additions and 24 deletions
+22 -7
View File
@@ -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);
};
}]);