Service Portal Modal login
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 09:36 AM
We have customised the login widget for the Service Portal modal login, so that ITIL users are redirected to the frameset view. The widget seemed to work fine in Madrid, but stopped working after we upgraded to New York. I've debugged the code and it looks like the server.get call after a successful login is not calling the server script. The modal login form is opened from the header widget
Header widget server script extract
data.loginWidget = $sp.getWidget('uob-widget-login');
Header widget client controller extract:
$scope.openLogin = function () {
$scope.modalInstance = $uibModal.open({
templateUrl: 'uobModalLogin',
scope: $scope
});
};
uobModalLogin template:
<div class="login_widget">
<sp-widget widget="data.loginWidget"></sp-widget>
<style>
.modal-content { border: 0px solid transparent; }
</style>
</div>
uob-widget-login client controller extract
function loginCtrl($scope, $http, $window, $location, glideUserSession, glideSystemProperties, spUtil) {
var c = this;
c.remember_me = c.data.forgetMeDefault;
if (!c.data.is_logged_in && c.data.multisso_enabled && c.data.default_idp) {
// ...
}
// c.login is called when Login button is clicked
c.login = function(username, password) {
var url = spUtil.getURL({sysparm_type: 'view_form.login'});
// If the page isn't public, then the ID in the
// URL won't match the rendered page ID
var pageId = $location.search().id || $scope.page.id;
var isLoginPage = $scope.portal.login_page_dv == pageId;
return $http({
method: 'post',
url: url,
data: $.param({
'sysparm_type': 'login',
'ni.nolog.user_password': true,
'remember_me': !!c.remember_me ? true : false,
'user_name': username,
'user_password': password,
'get_redirect_url': true,
'sysparm_goto_url': isLoginPage ? null : $location.url(),
'mfa_redirect_url': c.data.pageURI
}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function(response) {
if (!response.data) {
c.message = $scope.data.errorMsg;
return;
}
if (response.data.status == 'success') {
if (c.data.multiFactorAuthEnabled) {
c.server.get({
action: "multi_factor_auth_setup",
directTo: response.data.redirect_url
}).then(handleLoginSuccess.bind(response));
} else {
var inp = {
action: "login_redirect",
message: response.data.message,
directTo: response.data.redirect_url
};
c.server.get(inp).then(
// THE PROMISE IS RESOLVING BUT THE SERVER SCRIPT IS NOT BEING EXECUTED
handleLoginSuccess.call(response)
);
}
} // ...
}, function errorCallback(response) {
c.message = $scope.data.errorMsg;
});
};
c.externalLogin = function() {
// .....
};
function handleLoginSuccess() {
// this = RESPONSE RETURNED BY $http CALL, SHOULD BE RESPONSE RETURNED BY server.get
c.success = this.data.message;
$window.location = this.data.redirect_url;
}
c.setExternalLogin = function(newVal) {
c.externalLoginMode = newVal;
};
}
uob-widget-login server script extract:
(function() {
options.show_panel = options.show_panel == "true" || options.show_panel == true;
// ....
if (input && input.action == 'login_redirect') {
// THIS IS WHERE THE REDIRECT URL SHOULD BE DEFINED
data.message = input.message;
data.redirect_url = input.directTo;
data.frameset = (gs.getUser().hasRole('itil') || gs.getUser().hasRole('hr_basic') || gs.getUser().hasRole('admin'));
var sp_home = $sp.getValue('homepage');
if (data.frameset && (input.directTo.indexOf('?id=')==-1 || input.directTo.indexOf('?id=')!=-1 && input.directTo.indexOf('?id='+sp_home)==-1)) {
var frameset_home = gs.getProperty("glide.login.home");
data.redirect_url = "nav_to.do?uri="+frameset_home;
}
return;
}
data.errorMsg = gs.getMessage("There was an error processing your request");
// ... more properties
})();
Why is the server.get not invoking the uob-widget-login server script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2020 04:24 AM
Not sure whether this is a related issue. I put a few console.log statements in both the server scripts for the header and login widgets, and nothing is printing to the console. I am using Chrome and have Info logging level checked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2020 06:30 AM
I've placed dummy server.get calls at different places in the uob-widget-login client script, and I've determined that the server.get call fails when it is executed AFTER the $http call. So it looks like the $http call is somehow "disrupting" server.get.
Has anyone encountered a similar issue ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2020 07:34 AM
Also, there was a mistake in the uob-widget-login client controller code that I copied into my post. The correct code should be:
if (response.data.status == 'success') {
if (c.data.multiFactorAuthEnabled) {
c.server.get({
action: "multi_factor_auth_setup",
directTo: response.data.redirect_url
}).then(handleLoginSuccess.bind(response));
} else {
var inp = {
action: "login_redirect",
message: response.data.message,
directTo: response.data.redirect_url
};
c.server.get(inp).then(
function(r) {
// The response from the server.get call should contain the property data.redirect_url
// Instead the response (r) is the same as the original input (inp),
// so data.redirect_url is undefined
handleLoginSuccess.call(r);
}
);
}
}