I have a password reset action in my mvc controller with this code:
var user = AuthService.GetUser(command.IdUser);
if (user == null)
{
return PartialView("_MessageFailed", "The user doesn't exists");
}
if (user.TenantId != command.IdWebsite)
{
return PartialView("_MessageFailed", "You are not allowed to reset this user password");
}
var token = AuthService.GenerateUserPasswordToken(user.Id);
var result = AuthService.ResetPassword(user.Id, token, command.NewPassword);
if (result.Succeeded)
return PartialView("_MessageSuccess", "The password has changed");
return PartialView("_MessageFailed", string.Join("<br>", result.Errors));
The user exists, but I'm having an error in the result object in reset method that says Name [email protected] is already taken.
Why is this happening?
Could be because in the aspnetusers table in the database are two users with the same email and different tenantId? How can I fix this?
Update: AuthService is a protected property like this:
protected AuthenticationLogic AuthService
{
get
{
return authService ?? new AuthenticationLogic(HttpContext.GetOwinContext());
}
private set { authService = value; }
}
Where AuthenticationLogic constructor:
public AuthenticationLogic(IOwinContext owinContext) {
this.owinContext = owinContext;
}
If the issue is a duplicate email address, you can disable the 'RequireUniqueEmail' property of the UserManager:
C# Example
manager.UserValidator = new UserValidator<ApplicationUser>(manager)
{
RequireUniqueEmail = false
};
Visual Basic example
manager.UserValidator = New UserValidator(Of ApplicationUser, Integer)(manager) With {
.RequireUniqueEmail = False
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With