Base solution for your next web application
Open Closed

Issue extending UserStore #1348


User avatar
0
joe704la created

I extended the User entity by adding the following properties...

public virtual bool LockoutEnabled { get; set; }

        public virtual int AccessFailedCount { get; set; }

        public virtual DateTime? LockoutEndDateUtc { get; set; }

I then went to extend the UserStore by implementing the IUserLockStore<User, long> interface. This works all fine. But when I try to update the user by using the User repository in the UserStore like this _userRepository.UpdateAsync(user) it doesn't actually update the user in the database.

When I debug I can see it go through without any errors being thrown, but it just doesn't update the user. Would you have any ideas why this could be happening?


5 Answer(s)
  • User Avatar
    0
    joe704la created

    Does anyone have any thoughts on this? I am completely stuck. I also tried using the UpdateAsync method that is in the AbpUserStore. That also didn't work. It just doesn't ever update the database. Here is an example that isn't working in the UserStore.

    /// <summary>
            /// Increment failed access count
            /// </summary>
            /// <param name="user"></param>
            /// <returns></returns>
            public Task<int> IncrementAccessFailedCountAsync(User user)
            {
                user.AccessFailedCount++;
    
              //Example of an update not working. 
                UpdateAsync(user);
    
             //Also tried this
              //_userRepository.UpdateAsync(user);
    
                return Task.FromResult(user.AccessFailedCount);
            }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Where do you use IncrementAccessFailedCountAsync method of your UserStore ?

  • User Avatar
    0
    joe704la created

    I use it in the AccountController in the Login method. I am creating a user lockout functionality on 3 failed login attempts.

    I actually think I figured something out reading the ASPNET Boilerplate documentation on Unit of Work. I didn't realize that if an exception is thrown that it rolls back the database transaction.

    In the Login method when a user failed to provide the correct password I returned a UserFriendlyException with the message of how many login attempts they have left. I haven't tested this theory yet but I am guessing if I change how I am returning the error message it will work. I just need to figure out a better way to return the error.

    I am first going to try the [UnitOfWork] attribute but the way the documentation sounded I am not going to be able to do that in the UserStore. I just liked how easy it was to return an error message to the popup error modal using a UserFriendlyException.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can inject IUnitOfWorkManager in UserStore, then use UnitOfWorkManager.Begin method: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#iunitofworkmanager">http://www.aspnetboilerplate.com/Pages/ ... orkmanager</a> _unitOfWorkManager.Begin() accepts TransactionScope and you can set it to Suppress.

    So, inside the using statement, you will use a new non-transactional uow.

  • User Avatar
    0
    joe704la created

    I was looking at that, which did seem like a great way to do it. I just ended up doing it a little differently. In the Login method instead of throwing an exception I just returned a MVCAjaxResponse with Success = false. That way I was able to return an error pretty easily and then catch it in the Ajax call back and display the error message that way.