digipolisantwerp / dataaccess_aspnetcore_deprecated

Generic repository/unit of work framework for ASP.NET Core with Entity Framework.
Other
140 stars 45 forks source link

Login Fails after Changing password success #27

Closed anhlee24 closed 7 years ago

anhlee24 commented 7 years ago

I have an issue: I have used Identity, i have updated password success, but i can not login until i restart the application.

I think there is an issue with the DbContext DI, this is my code:

in Startup.cs

services.AddDbContext<TCMSContext>(options => options.UseSqlServer(_config["ConnectionStrings:TCMSContextConnection"]));
            services.AddDataAccess<TCMSContext>();

In Controller:

public async Task<IdentityResult> UpdateUser(UserUpdateModel userModel) 
        {
            var user = await _userManager.FindByNameAsync(userModel.UserName);

            var result = await _userManager.ChangePasswordAsync(user, userModel.CurrentPassword, userModel.Password);

            if (result.Succeeded)
            {
                user = await _userManager.FindByNameAsync(userModel.UserName);
                user.Address = userModel.Address;
                user.Avatar = userModel.Avatar;
                user.FullName = userModel.FullName;
                user.Email = userModel.Email;
                user.PhoneNumber = userModel.PhoneNumber;
                result = await _userManager.UpdateAsync(user);
            }

            return result;
        }

Do you have any suggest? Thank you.

StevenVandenBroeck commented 7 years ago

The user manager is part of the Identity Framework of ASP.NET and does not use our framework in that flow. You will have to check there : https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity.