Service Portal Modal login

Colleen
Tera Expert

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 ?

7 REPLIES 7

Gaurav Sharma11
Kilo Expert

Hi,

Could you please try calling widget with below code instead of calling it through template:

 

	/* please add spModal to client controller function parameters */
	$scope.openLogin = function() {
		spModal.open({
			title : "Login",
			widget : "uob-widget-login",
			widgetInput : {} // any input object
		}).then(function(){			
			
		});
	};

 

Thanks,

Gaurav

Hi Guarav

Using spModal with the widget made no difference.  server.get is still not being invoked.

Colleen

SatheeshKumar
Kilo Sage

have you verified the http post method is returning proper response? if not, check that first! 

Thanks Satheesh

I did check the http post response.  That's what is actually being passed to the handleLoginSuccess function, rather than the server.get response.