IdentityUser conforms to the existing IdentityUser from EntityFramework in order to ease migration.
This commit is contained in:
@@ -7,24 +7,89 @@ using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace RavenDB.Identity
|
||||
{
|
||||
/// <summary>
|
||||
/// Base user class for RavenDB Identity. Inherit from this class to add your own properties.
|
||||
/// </summary>
|
||||
public class IdentityUser
|
||||
{
|
||||
/// <summary>
|
||||
/// The ID of the user.
|
||||
/// </summary>
|
||||
public virtual string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The user name. Usually the same as the email.
|
||||
/// </summary>
|
||||
public virtual string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The password hash.
|
||||
/// </summary>
|
||||
public virtual string PasswordHash { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The security stamp.
|
||||
/// </summary>
|
||||
public virtual string SecurityStamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The email of the user.
|
||||
/// </summary>
|
||||
public virtual string Email { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The phone number.
|
||||
/// </summary>
|
||||
public virtual string PhoneNumber { get; set; }
|
||||
public virtual bool IsEmailConfirmed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the user has confirmed their email address.
|
||||
/// </summary>
|
||||
public virtual bool EmailConfirmed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the user has confirmed their phone.
|
||||
/// </summary>
|
||||
public virtual bool IsPhoneNumberConfirmed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of times sign in failed.
|
||||
/// </summary>
|
||||
public virtual int AccessFailedCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the user is locked out.
|
||||
/// </summary>
|
||||
public virtual bool LockoutEnabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When the user lock out is over.
|
||||
/// </summary>
|
||||
public virtual DateTimeOffset? LockoutEndDate { get; set; }
|
||||
public virtual bool TwoFactorAuthEnabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether 2-factor authentication is enabled.
|
||||
/// </summary>
|
||||
public virtual bool TwoFactorEnabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The roles of the user. To modify the user's roles, use <see cref="UserManager{TUser}.AddToRoleAsync(TUser, string)"/> nad <see cref="UserManager{TUser}.RemoveFromRolesAsync(TUser, IEnumerable{string})"/>.
|
||||
/// </summary>
|
||||
public virtual IReadOnlyList<string> Roles { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The user's claims, for use in claims-based authentication.
|
||||
/// </summary>
|
||||
public virtual List<IdentityUserClaim> Claims { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The logins of the user.
|
||||
/// </summary>
|
||||
public virtual List<UserLoginInfo> Logins { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new IdentityUser.
|
||||
/// </summary>
|
||||
public IdentityUser()
|
||||
{
|
||||
this.Claims = new List<IdentityUserClaim>();
|
||||
@@ -32,13 +97,6 @@ namespace RavenDB.Identity
|
||||
this.Logins = new List<UserLoginInfo>();
|
||||
}
|
||||
|
||||
public IdentityUser(string userId, string userName)
|
||||
: this()
|
||||
{
|
||||
this.Id = userId;
|
||||
this.UserName = userName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mutable roles list. This shouldn't be modified by user code; roles should be changed via UserManager instead.
|
||||
/// </summary>
|
||||
|
||||
@@ -439,14 +439,14 @@ namespace RavenDB.Identity
|
||||
{
|
||||
ThrowIfNullDisposedCancelled(user, cancellationToken);
|
||||
|
||||
return Task.FromResult(user.IsEmailConfirmed);
|
||||
return Task.FromResult(user.EmailConfirmed);
|
||||
}
|
||||
|
||||
public Task SetEmailConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken)
|
||||
{
|
||||
ThrowIfNullDisposedCancelled(user, cancellationToken);
|
||||
|
||||
user.IsEmailConfirmed = confirmed;
|
||||
user.EmailConfirmed = confirmed;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -542,7 +542,7 @@ namespace RavenDB.Identity
|
||||
{
|
||||
ThrowIfNullDisposedCancelled(user, cancellationToken);
|
||||
|
||||
user.TwoFactorAuthEnabled = enabled;
|
||||
user.TwoFactorEnabled = enabled;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -550,7 +550,7 @@ namespace RavenDB.Identity
|
||||
{
|
||||
ThrowIfNullDisposedCancelled(user, cancellationToken);
|
||||
|
||||
return Task.FromResult(user.TwoFactorAuthEnabled);
|
||||
return Task.FromResult(user.TwoFactorEnabled);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Sample.Controllers
|
||||
Username = user.UserName,
|
||||
Email = user.Email,
|
||||
PhoneNumber = user.PhoneNumber,
|
||||
IsEmailConfirmed = user.IsEmailConfirmed,
|
||||
IsEmailConfirmed = user.EmailConfirmed,
|
||||
StatusMessage = StatusMessage
|
||||
};
|
||||
|
||||
@@ -318,7 +318,7 @@ namespace Sample.Controllers
|
||||
var model = new TwoFactorAuthenticationViewModel
|
||||
{
|
||||
HasAuthenticator = await _userManager.GetAuthenticatorKeyAsync(user) != null,
|
||||
Is2faEnabled = user.TwoFactorAuthEnabled,
|
||||
Is2faEnabled = user.TwoFactorEnabled,
|
||||
RecoveryCodesLeft = await _userManager.CountRecoveryCodesAsync(user),
|
||||
};
|
||||
|
||||
@@ -334,7 +334,7 @@ namespace Sample.Controllers
|
||||
throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||
}
|
||||
|
||||
if (!user.TwoFactorAuthEnabled)
|
||||
if (!user.TwoFactorEnabled)
|
||||
{
|
||||
throw new ApplicationException($"Unexpected error occured disabling 2FA for user with ID '{user.Id}'.");
|
||||
}
|
||||
@@ -451,7 +451,7 @@ namespace Sample.Controllers
|
||||
throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||
}
|
||||
|
||||
if (!user.TwoFactorAuthEnabled)
|
||||
if (!user.TwoFactorEnabled)
|
||||
{
|
||||
throw new ApplicationException($"Cannot generate recovery codes for user with ID '{user.Id}' as they do not have 2FA enabled.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user