Skip to content

Commit 4b77de5

Browse files
committed
Add SharedKey property and update related methods for user sharing functionality
1 parent 713b154 commit 4b77de5

File tree

7 files changed

+39
-10
lines changed

7 files changed

+39
-10
lines changed

modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentityUserConsts.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ public static class IdentityUserConsts
3737
/// Default value: 16
3838
/// </summary>
3939
public static int MaxLoginProviderLength { get; set; } = 16;
40+
41+
/// <summary>
42+
/// Default value: 256
43+
/// </summary>
44+
public static int MaxSharedKeyLength { get; set; } = 256;
4045
}

modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Task<IdentityUser> FindByPasskeyIdAsync(
167167
CancellationToken cancellationToken = default);
168168

169169
Task<List<IdentityUser>> GetSharingUsersAsync(
170-
[NotNull] string normalizedEmail,
170+
[NotNull] string sharedKey,
171171
bool includeDetails = false,
172172
CancellationToken cancellationToken = default
173173
);

modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ public class IdentityUser : FullAuditedAggregateRoot<Guid>, IUser, IHasEntityVer
137137
/// </summary>
138138
public virtual bool IsShared { get; protected set; }
139139

140+
/// <summary>
141+
/// Gets or sets the shared key for this user.
142+
/// </summary>
143+
public virtual string SharedKey { get; protected set; }
144+
140145
//TODO: Can we make collections readonly collection, which will provide encapsulation. But... can work for all ORMs?
141146

142147
/// <summary>
@@ -450,6 +455,11 @@ public virtual void SethIsShared(bool isShared)
450455
IsShared = isShared;
451456
}
452457

458+
public virtual void SetSharedKey(string sharedKey)
459+
{
460+
SharedKey = sharedKey;
461+
}
462+
453463
public override string ToString()
454464
{
455465
return $"{base.ToString()}, UserName = {UserName}";

modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected async override Task<IdentityResult> UpdateUserAsync(IdentityUser user)
116116
/// <returns>A <see cref="IdentityResult"/> representing whether validation was successful.</returns>
117117
public virtual async Task<IdentityResult> CallValidateUserAsync(IdentityUser user)
118118
{
119-
return await base.ValidateUserAsync(user);
119+
return await ValidateUserAsync(user);
120120
}
121121

122122
/// <summary>
@@ -129,7 +129,20 @@ public virtual async Task<IdentityResult> CallValidateUserAsync(IdentityUser use
129129
/// <returns>A <see cref="IdentityResult"/> representing whether validation was successful.</returns>
130130
public virtual async Task<IdentityResult> CallValidatePasswordAsync(IdentityUser user, string password)
131131
{
132-
return await base.ValidatePasswordAsync(user, password);
132+
return await ValidatePasswordAsync(user, password);
133+
}
134+
135+
/// <summary>
136+
/// This is to call the protection method UpdatePasswordHash
137+
/// Updates a user's password hash.
138+
/// </summary>
139+
/// <param name="user">The user.</param>
140+
/// <param name="newPassword">The new password.</param>
141+
/// <param name="validatePassword">Whether to validate the password.</param>
142+
/// <returns>Whether the password has was successfully updated.</returns>
143+
public virtual async Task<IdentityResult> CallUpdatePasswordHash(IdentityUser user, string newPassword, bool validatePassword)
144+
{
145+
return await UpdatePasswordHash(user, newPassword, validatePassword);
133146
}
134147

135148
public virtual async Task<IdentityUser> GetByIdAsync(Guid id)

modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,11 @@ public virtual async Task UpdateOrganizationAsync(Guid sourceOrganizationId, Gui
455455
}
456456
}
457457

458-
public virtual async Task<List<IdentityUser>> GetSharingUsersAsync(string normalizedEmail, bool includeDetails = false, CancellationToken cancellationToken = default)
458+
public virtual async Task<List<IdentityUser>> GetSharingUsersAsync(string sharedKey, bool includeDetails = false, CancellationToken cancellationToken = default)
459459
{
460460
return await (await GetDbSetAsync())
461461
.IncludeDetails(includeDetails)
462-
.Where(x => x.IsShared)
463-
.Where(x => x.NormalizedEmail == normalizedEmail)
462+
.Where(x => x.SharedKey == sharedKey)
464463
.ToListAsync(GetCancellationToken(cancellationToken));
465464
}
466465

modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public static void ConfigureIdentity([NotNull] this ModelBuilder builder)
3333
.HasColumnName(nameof(IdentityUser.TwoFactorEnabled));
3434
b.Property(u => u.LockoutEnabled).HasDefaultValue(false)
3535
.HasColumnName(nameof(IdentityUser.LockoutEnabled));
36+
b.Property(u => u.IsShared).HasDefaultValue(false)
37+
.HasColumnName(nameof(IdentityUser.IsShared));
38+
b.Property(u => u.SharedKey).HasMaxLength(IdentityUserConsts.MaxSharedKeyLength)
39+
.HasColumnName(nameof(IdentityUser.SharedKey));
3640

3741
b.Property(u => u.IsExternal).IsRequired().HasDefaultValue(false)
3842
.HasColumnName(nameof(IdentityUser.IsExternal));

modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,10 @@ public virtual async Task<IdentityUser> FindByPasskeyIdAsync(byte[] credentialId
451451
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
452452
}
453453

454-
455-
public virtual async Task<List<IdentityUser>> GetSharingUsersAsync(string normalizedEmail, bool includeDetails = false, CancellationToken cancellationToken = default)
454+
public virtual async Task<List<IdentityUser>> GetSharingUsersAsync(string sharedKey, bool includeDetails = false, CancellationToken cancellationToken = default)
456455
{
457456
return await (await GetQueryableAsync(cancellationToken))
458-
.Where(x => x.IsShared)
459-
.Where(u => u.NormalizedEmail == normalizedEmail)
457+
.Where(u => u.SharedKey == sharedKey)
460458
.ToListAsync(GetCancellationToken(cancellationToken));
461459
}
462460

0 commit comments

Comments
 (0)