Custom Logout event


#1

Hi to all,

I would like to customize the logout function for the task list.
After logout, I’d like to go to the SSO page.

I need to change redirect URL to URL my SSO.

For the moment, I’m using a custom camunda-webapp package.

To solve the problem, I tried to use the custom script (https://docs.camunda.org/manual/7.8/webapps/tasklist/configuration/#custom-cripts)
but failed.

I ask for help in solving this task.

Thanks,
Petr


JS only plugin in springboot webapp
#2

I managed to connect a custom script.
When i use the custom button, the script runs successfully.
But unfortunately it is not called when logout when I use the default button (from component camunda-commons-ui)

'use strict';
define('custom-ng-module', [
    'angular'
], function (angular) {
    var customModule = angular.module('my.custom.module', []);

    customModule.controller('camHeaderViewsCtrl', ['scope', function ($scope) {
        $rootScope.logout = function (){
            console.log('Test');
        };
    }]);

    return customModule;
});

Could you help me to override the default script for my custom script?


#3

Hi @petrovtsev, you can achieve that by doing the following:

  customModule.controller('camHeaderViewsCtrl', ['$window', '$scope', function($window, $scope) {
    // isLoggedIn: flag set to true initially, since user is logged in
    var isLoggedIn = true;
    
    // register listener to 'authentication.changed' event
    var listener = $scope.$root.$on('authentication.changed', function(ev, auth) {
      if(!auth && isLoggedIn) {
        console.log('logout');
        isLoggedIn = false;
      }
    });

    // remove listener to 'authentication.changed' event
    $scope.$on('$destroy', function() {
      listener();
    });

  }]);

  return customModule;
});

Does this help you? Please let me know if you have any questions regarding this.


#4

Hi @petrovtsev ,

Were you able to write the scripts for Custom logout ?

If yes,Could you please provide a Sample.


#5

Hi @siffogh,

is that script supposed to run without any custom buttons (i.e. using the default logout button in the web app)? I tried adding it and registering it as in the doc and it doesn’t seem to be called at all

Thanks,
Luca


#6

Hi there,
I’ve got the same problem. Is there anyone with a solution? I know nothing about Angular… It feel that it can’t be that hard to change such a simple behaviour. But I just don’t know how…


#7

Got it. A bit hacky but it works.

'use strict';
define('custom-logout', ['angular'], function (angular) {
    var customLogoutModule = angular.module('custom-logout', []).run(
        ['$rootScope', function ($rootScope) {

            $rootScope.$on('$viewContentLoaded', function (event) {
                // Get the HTML element of the header widget.
                var div = document.querySelector("[cam-widget-header]");

                // Get the only property on it, its key is jQuery<many numbers> and its value
                // contains the controller ($camWidgetHeaderController) and the isolated
                // Scope ($isolateScope). The logout function is defined in this scope.
                var jQueryKey = Object.getOwnPropertyNames(div)[0];
                var $isolateScope = div[jQueryKey]['$isolateScope'];
                $isolateScope.logout = function () {
                    // Do whatever you want to do on logout.
                    window.location.href = "/logout"
                }

            })
        }]);
});