Give better login error feedback

This commit is contained in:
Johannes Zellner
2023-04-28 13:10:38 +02:00
parent d7c5e36627
commit 19247f38c5
4 changed files with 72 additions and 15 deletions
+17 -5
View File
@@ -84,17 +84,29 @@ app.controller('LoginController', ['$scope', '$translate', '$http', function ($s
totpToken: $scope.totpToken
};
function error() {
function error(data, status) {
$scope.busy = false;
$scope.error = true;
$scope.error = {};
if (!data || status !== 401) return $scope.error.internal = true;
if (data.message === 'Username and password does not match') {
$scope.error.password = true;
$scope.password = '';
setTimeout(function () { $('#inputPassword').focus(); }, 200);
} else if (data.message.indexOf('totpToken') !== -1) {
$scope.error.totpToken = true;
$scope.totpToken = '';
setTimeout(function () { $('#inputTotpToken').focus(); }, 200);
} else {
$scope.error.generic = true;
}
$scope.password = '';
$scope.loginForm.$setPristine();
setTimeout(function () { $('#inputPassword').focus(); }, 200);
}
$http.post(API_ORIGIN + '/api/v1/cloudron/login', data).success(function (data, status) {
if (status !== 200) return error();
if (status !== 200) return error(data, status);
localStorage.token = data.accessToken;