Skip to content

Commit

Permalink
Merge pull request #7627 from umbraco/v8/bugfix/AB4828-resetpassword-…
Browse files Browse the repository at this point in the history
…mail

AB4828 - Reset Password Email

(cherry picked from commit f00680b)
  • Loading branch information
Warren Buckley committed Feb 12, 2020
1 parent 9c428b7 commit 6a6978d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,16 @@ protected override void PersistUpdatedItem(IUser entity)
}
}

// If userlogin or the email has changed then need to reset security stamp
if (changedCols.Contains("userLogin") || changedCols.Contains("userEmail"))
{
userDto.EmailConfirmedDate = null;
userDto.SecurityStampToken = entity.SecurityStamp = Guid.NewGuid().ToString();

changedCols.Add("emailConfirmedDate");
changedCols.Add("securityStampToken");
}

//only update the changed cols
if (changedCols.Count > 0)
{
Expand Down
29 changes: 29 additions & 0 deletions src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,35 @@ public void Can_Get_Paged_Results_With_Filter_And_Groups()
}
}

[Test]
public void Can_Invalidate_SecurityStamp_On_Username_Change()
{
// Arrange
var provider = TestObjects.GetScopeProvider(Logger);
using (var scope = provider.CreateScope())
{
var repository = CreateRepository(provider);
var userGroupRepository = CreateUserGroupRepository(provider);

var user = CreateAndCommitUserWithGroup(repository, userGroupRepository);
var originalSecurityStamp = user.SecurityStamp;

// Ensure when user generated a security stamp is present
Assert.That(user.SecurityStamp, Is.Not.Null);
Assert.That(user.SecurityStamp, Is.Not.Empty);

// Update username
user.Username = user.Username + "UPDATED";
repository.Save(user);

// Get the user
var updatedUser = repository.Get(user.Id);

// Ensure the Security Stamp is invalidated & no longer the same
Assert.AreNotEqual(originalSecurityStamp, updatedUser.SecurityStamp);
}
}

private void AssertPropertyValues(IUser updatedItem, IUser originalUser)
{
Assert.That(updatedItem.Id, Is.EqualTo(originalUser.Id));
Expand Down

0 comments on commit 6a6978d

Please sign in to comment.