Copied to clipboard

Flag this post as spam?

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


  • firepol 125 posts 173 karma points
    Apr 04, 2012 @ 15:54
    firepol
    0

    How to subscribe to backend login event (if existing, else alternative solution)

    Hi,

    I checked the Overview of all events and I don't see any event such as AfterLogin or similar.

    I found another thread in this forum where somebody suggests how to proceed, but without giving any code I'm not able to reproduce the given solution.

    Can somebody help?

    As it seems to me that no "AfterLogin" event exists, what I think I'll do is to create a session containing the loggedin username and run a method called "userRedirect". There will be a check to see if the session is existing. If yes, do nothing (as the user already logged in and was already redirected), if not, create the session and call userRedirect as stated above.

    I'd like this to work only in the backend. No idea how to proceed and I would be really happy if somebody can give me precise instructions (where to create the class, a code snippet...).

    Thanks and cheers

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Apr 04, 2012 @ 19:27
    Lee Kelleher
    2

    Hi firepol,

    The other thread mentions about overridding Umbraco's own membership provider with a custom one, then you can hook into various calls from there.

    Quick code snippet would be...

    namespace Our.Umbraco
    {
        public class CustomUsersMembershipProvider : umbraco.providers.UsersMembershipProvider
        {
            public override bool ValidateUser(string username, string password)
            {
                var success = base.ValidateUser(username, password);
    
                if (success)
                {
                    // do any custom code here!
                }
    
                return success;
            }
        }
    }

    You can either drop this in your App_Code, or compile it to your own assembly.

    Then replace the current Umbraco membership provider...

    <add name="UsersMembershipProvider" type="Our.Umbraco.CustomUsersMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" passwordFormat="Hashed" />

    Now whenever someone logs into the back-office, it would call your code.

    Cheers, Lee.

  • firepol 125 posts 173 karma points
    Apr 05, 2012 @ 13:53
    firepol
    0

    Thanks Lee, you rock!

    That's a good and helpful reply. By the way, I would put this answer/information also somewhere in the wiki, maybe related to the events. Can be helpful for other people too (ok they can find it in the forum but still, the wiki is more important on my opinion, and, if well mantained, always a good reference to all developers...)

    Cheers

  • firepol 125 posts 173 karma points
    Apr 05, 2012 @ 15:05
    firepol
    0

    Hei Lee, if you have time, it would be cool if you could have a look also at this question related to this thread.

    Actually I thought it would be easy/peasy but as Murphy is always there, it wasn't ;)

    Thanks and cheers

    --firepol

Please Sign in or register to post replies

Write your reply to:

Draft