Copied to clipboard

Flag this post as spam?

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


  • Alejandro 23 posts 45 karma points
    Jan 08, 2016 @ 16:41
    Alejandro
    1

    Extending Login functionality.

    Hi everyone,

    I'm using the standard Umbraco Login functionality (UmbLoginController), but now I got a request to include notifications when a member is locked out (send emails, display messages, etc).

    Is there a way to hook into the login functionality or subscribe to an event of some sort so that I can include my logic?

    I could of course implement my own Login controller, but I was hoping to avoid that.

    Thanks!.

  • Jordan 24 posts 182 karma points
    Jun 01, 2016 @ 11:32
    Jordan
    0

    Hey Everyone,

    I am actually trying to achieve the same thing. Does anyone have any recommendations on the best way to do this?

    Been looking at creating a custom provider, however I can't seem to get that to work. Wasn't sure if there was a simpler way to hook into a login request.

    Post I have been looking at can be found at this link https://our.umbraco.org/forum/developers/api-questions/30522-How-to-subscribe-to-backend-login-event-if-existing-else-alternative-solution?p=0#comment113339

    Thanks for any help!

  • Paul Seal 524 posts 2889 karma points MVP 7x c-trib
    Jun 01, 2016 @ 11:50
    Paul Seal
    1

    Hi Alejandro This is an interesting problem, I never thought of doing it before. I think my article which shows you how to intercept member saving events will help you achieve what you need to here as the member must get saved when they are locked out for the property to be updated.

    http://www.codeshare.co.uk/blog/intercepting-content-and-member-save-events-in-umbraco/

  • Jordan 24 posts 182 karma points
    Jun 01, 2016 @ 12:50
    Jordan
    1

    Hi Paul,

    Thank you for your reply, That was a brilliant suggestion. I updated the code you had to access the UserService instead of the MemberService and it has done the trick.

    For anyone else wanting to do the same thing, here is the code below:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Umbraco.Core;
    using Umbraco.Core.Events;
    using Umbraco.Core.Models;
    using Umbraco.Core.Models.Membership;
    using Umbraco.Core.Services;
    using Umbraco.Web.Security.Providers;
    
    namespace User.EventHandler
    {
        public class UserEventHandler : ApplicationEventHandler
        {
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                UserService.SavingUser += UserService_Saving;
            }
    
            private void UserService_Saving(IUserService sender, SaveEventArgs<IUser> e)
            {
                foreach (IUser user in e.SavedEntities)
                {
                    //check to see if user is locked out
                    if (user.IsLockedOut)
                    {
                        //send email here
                    }
                }
            }
        }
    }
    
  • Paul Seal 524 posts 2889 karma points MVP 7x c-trib
    Jun 01, 2016 @ 13:01
    Paul Seal
    0

    You're welcome Alejandro. I'm glad you got it working and my code was of use to you.

Please Sign in or register to post replies

Write your reply to:

Draft