SmartIT_Extensions/BMC/smart-it-full-helix/scripts/app/asset/bcm-credential-alert-contro...

64 lines
2.6 KiB
JavaScript

"use strict";
(function () {
'use strict';
angular.module('assetModule')
.controller('BcmCredentialAlertController', ['$scope', '$filter', 'userModel', '$modalInstance',
function ($scope, $filter, userModel, $modalInstance) {
$scope.errorGeneral = "";
var state = {
loginPending: false
}, errorMessageType = '', isUsernameOrPasswordEmpty = function () {
var form = $scope.bcmLoginForm;
if (!form.username) {
errorMessageType = 'usernameRequired';
}
if (!form.password) {
errorMessageType = 'passwordRequired';
}
if (!form.username && !form.password) {
errorMessageType = 'usernameAndPasswordRequired';
}
return errorMessageType;
};
$scope.state = state;
$scope.bcmLoginForm = {
username: '',
password: '',
submitForm: function () {
$scope.errorGeneral = "";
var that = this;
errorMessageType = null;
state.loginPending = true;
//validation
if (isUsernameOrPasswordEmpty()) {
$scope.errorMessageType = errorMessageType;
state.loginPending = false;
return;
}
// All good, do login
userModel.doBCMLogin(that.username, that.password).then(function () {
//login successful
state.loginPending = false;
that.password = '';
$modalInstance.close();
}).catch(function (error) {
if (error.data && error.data.error) {
if (error.data.error === "BCM_Unauthorized") {
$scope.errorGeneral = $filter('i18n')('user.loginError.1006');
}
else {
$scope.errorGeneral = error.data.error;
}
}
else {
//Login error
errorMessageType = error.status;
}
state.loginPending = false;
that.password = '';
});
}
};
}]);
})();