Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Claus Jessing 9 posts 100 karma points
    Sep 02, 2019 @ 08:30
    Claus Jessing
    0

    Calling my own function on logout?

    So... edging on in my quest to control login/logout myself I've managed to figure out how to redirect to my own logout URL when clicking the Logout button by editing the umbraco.services.js (approx line 11335) from this:

    logout: function logout() {
        return authResource.performLogout().then(function (data) {
            userAuthExpired();
            //done!
            return null;
        });
    },
    

    to this:

    logout: function logout() {
        authResource.performLogout().then(function (data) {
            userAuthExpired();
        });
        location.href = '/logout';
    },
    

    What I would like to do is to add my own logout2() rather than edit logout(). So I've tried editing the logout button in user.html from:

    <umb-button
        alias="logOut"
        type="button"
        action="logout()"
        shortcut="ctrl+shift+l"
        button-style="danger"
        label="Log out"
        label-key="general_logout">
    </umb-button>
    

    to

    <umb-button
        alias="logOut"
        type="button"
        action="logout2()"
        shortcut="ctrl+shift+l"
        button-style="danger"
        label="Log out"
        label-key="general_logout">
    </umb-button>
    

    but login2() is never called.

    Can anyone shed some light on what I'm missing?

    Thanks in advance

    Edit: I found out that if I edit routes.js, the doLogout function, I can direct that to logout2() and leave the button untouched...

  • Ollie Storey 17 posts 172 karma points
    Sep 02, 2019 @ 11:38
    Ollie Storey
    100

    The following changes worked for me: The following changes worked for me Try changing what you have here

    logout: function logout() {
        authResource.performLogout().then(function (data) {
            userAuthExpired();
        });
        location.href = '/logout';
    },
    

    to this

    logoutNew: function logout() {
        authResource.performLogout().then(function (data) {
            userAuthExpired();
        });
        location.href = '/logout';
    },
    

    And then your button will need to look like this

    <umb-button
        alias="logOut"
        type="button"
        action="logoutNew()"
        shortcut="ctrl+shift+l"
        button-style="danger"
        label="Log out"
        label-key="general_logout">
    </umb-button>
    

    Make sure to change your clientdependency config number too!

    Hope that works!

  • Claus Jessing 9 posts 100 karma points
    Sep 03, 2019 @ 05:11
    Claus Jessing
    0

    Morning Ollie :-)

    Thanks a bunch! It works like a charm.

    Although it works I'm somewhat annoyed with the fact that this is what I have to go to. I'd prefer a more "Umbraco like" way. If there were some standard "beforeLogout" events I could hook into.

    But this will do :-) Thanks again.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies