Give better login error feedback
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user