diff --git a/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSignInManager.cs b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSignInManager.cs index 00d46b0c04..61387f6536 100644 --- a/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSignInManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSignInManager.cs @@ -17,8 +17,6 @@ public class AbpSignInManager : SignInManager protected ISettingProvider SettingProvider { get; } - protected IClock Clock { get; } - private readonly IdentityUserManager _identityUserManager; public AbpSignInManager( @@ -30,8 +28,7 @@ public class AbpSignInManager : SignInManager IAuthenticationSchemeProvider schemes, IUserConfirmation confirmation, IOptions options, - ISettingProvider settingProvider, - IClock clock) : base( + ISettingProvider settingProvider) : base( userManager, contextAccessor, claimsFactory, @@ -41,7 +38,6 @@ public class AbpSignInManager : SignInManager confirmation) { SettingProvider = settingProvider; - Clock = clock; AbpOptions = options.Value; _identityUserManager = userManager; } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs index 914a8c7c06..ec5db2fe90 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs @@ -125,7 +125,7 @@ public class IdentityUser : FullAuditedAggregateRoot, IUser, IHasEntityVer /// /// Gets or sets the last password change time for the user. /// - public virtual DateTime? LastPasswordChangeTime { get; protected set; } + public virtual DateTimeOffset? LastPasswordChangeTime { get; protected set; } //TODO: Can we make collections readonly collection, which will provide encapsulation. But... can work for all ORMs? @@ -383,7 +383,7 @@ public class IdentityUser : FullAuditedAggregateRoot, IUser, IHasEntityVer ShouldChangePasswordOnNextLogin = shouldChangePasswordOnNextLogin; } - public virtual void SetLastPasswordChangeTime(DateTime? lastPasswordChangeTime) + public virtual void SetLastPasswordChangeTime(DateTimeOffset? lastPasswordChangeTime) { LastPasswordChangeTime = lastPasswordChangeTime; } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs index 785239c661..355378b8d0 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs @@ -26,8 +26,6 @@ public class IdentityUserManager : UserManager, IDomainService protected ISettingProvider SettingProvider { get; } protected ICancellationTokenProvider CancellationTokenProvider { get; } - protected IClock Clock { get; } - protected override CancellationToken CancellationToken => CancellationTokenProvider.Token; public IdentityUserManager( @@ -44,8 +42,7 @@ public class IdentityUserManager : UserManager, IDomainService ILogger logger, ICancellationTokenProvider cancellationTokenProvider, IOrganizationUnitRepository organizationUnitRepository, - ISettingProvider settingProvider, - IClock clock) + ISettingProvider settingProvider) : base( store, optionsAccessor, @@ -59,7 +56,6 @@ public class IdentityUserManager : UserManager, IDomainService { OrganizationUnitRepository = organizationUnitRepository; SettingProvider = settingProvider; - Clock = clock; RoleRepository = roleRepository; UserRepository = userRepository; CancellationTokenProvider = cancellationTokenProvider; @@ -274,9 +270,9 @@ public class IdentityUserManager : UserManager, IDomainService return false; } - var lastPasswordChangeTime = user.LastPasswordChangeTime ?? user.CreationTime; + var lastPasswordChangeTime = user.LastPasswordChangeTime ?? DateTime.SpecifyKind(user.CreationTime, DateTimeKind.Utc); var passwordChangePeriodDays = await SettingProvider.GetAsync(IdentitySettingNames.Password.PasswordChangePeriodDays); - return passwordChangePeriodDays > 0 && lastPasswordChangeTime.AddDays(passwordChangePeriodDays) < Clock.Now; + return passwordChangePeriodDays > 0 && lastPasswordChangeTime.AddDays(passwordChangePeriodDays) < DateTime.UtcNow; } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs index 6385cd4297..6239af36e0 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs @@ -56,7 +56,6 @@ public class IdentityUserStore : protected ILogger Logger { get; } protected ILookupNormalizer LookupNormalizer { get; } protected IIdentityUserRepository UserRepository { get; } - protected IClock Clock { get; } public IdentityUserStore( IIdentityUserRepository userRepository, @@ -64,7 +63,6 @@ public class IdentityUserStore : IGuidGenerator guidGenerator, ILogger logger, ILookupNormalizer lookupNormalizer, - IClock clock, IdentityErrorDescriber describer = null) { UserRepository = userRepository; @@ -72,7 +70,6 @@ public class IdentityUserStore : GuidGenerator = guidGenerator; Logger = logger; LookupNormalizer = lookupNormalizer; - Clock = clock; ErrorDescriber = describer ?? new IdentityErrorDescriber(); } @@ -274,7 +271,7 @@ public class IdentityUserStore : if (await FindByIdAsync(user.Id.ToString(), cancellationToken) != null) { - user.SetLastPasswordChangeTime(Clock.Now); + user.SetLastPasswordChangeTime(DateTime.UtcNow); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs index 92484d72ec..b2c7ebecb6 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs @@ -41,8 +41,6 @@ public class AbpResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator protected ISettingProvider SettingProvider { get; } - protected IClock Clock { get; } - public AbpResourceOwnerPasswordValidator( IdentityUserManager userManager, SignInManager signInManager, @@ -52,8 +50,7 @@ public class AbpResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator IOptions abpIdentityOptions, IServiceScopeFactory serviceScopeFactory, IOptions identityOptions, - ISettingProvider settingProvider, - IClock clock) + ISettingProvider settingProvider) { UserManager = userManager; SignInManager = signInManager; @@ -64,7 +61,6 @@ public class AbpResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator AbpIdentityOptions = abpIdentityOptions.Value; IdentityOptions = identityOptions; SettingProvider = settingProvider; - Clock = clock; } /// diff --git a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server/Migrations/20230314024329_Initial.cs b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server/Migrations/20230314024329_Initial.cs index 322f065b34..f2525f617b 100644 --- a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server/Migrations/20230314024329_Initial.cs +++ b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server/Migrations/20230314024329_Initial.cs @@ -317,7 +317,7 @@ namespace MyCompanyName.MyProjectName.Blazor.Server.Migrations AccessFailedCount = table.Column(type: "int", nullable: false, defaultValue: 0), ShouldChangePasswordOnNextLogin = table.Column(type: "bit", nullable: false), EntityVersion = table.Column(type: "int", nullable: false), - LastPasswordChangeTime = table.Column(type: "datetime2", nullable: true), + LastPasswordChangeTime = table.Column(type: "datetimeoffset", nullable: true), ExtraProperties = table.Column(type: "nvarchar(max)", nullable: true), ConcurrencyStamp = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: true), CreationTime = table.Column(type: "datetime2", nullable: false), diff --git a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server/Migrations/20230314024404_Initial.cs b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server/Migrations/20230314024404_Initial.cs index 68b1b7c744..e4e66c791a 100644 --- a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server/Migrations/20230314024404_Initial.cs +++ b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server/Migrations/20230314024404_Initial.cs @@ -317,7 +317,7 @@ namespace MyCompanyName.MyProjectName.Migrations AccessFailedCount = table.Column(type: "int", nullable: false, defaultValue: 0), ShouldChangePasswordOnNextLogin = table.Column(type: "bit", nullable: false), EntityVersion = table.Column(type: "int", nullable: false), - LastPasswordChangeTime = table.Column(type: "datetime2", nullable: true), + LastPasswordChangeTime = table.Column(type: "datetimeoffset", nullable: true), ExtraProperties = table.Column(type: "nvarchar(max)", nullable: true), ConcurrencyStamp = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: true), CreationTime = table.Column(type: "datetime2", nullable: false), diff --git a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host/Migrations/20230314024402_Initial.cs b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host/Migrations/20230314024402_Initial.cs index ec22adf26e..8355eaab06 100644 --- a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host/Migrations/20230314024402_Initial.cs +++ b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host/Migrations/20230314024402_Initial.cs @@ -317,7 +317,7 @@ namespace MyCompanyName.MyProjectName.Host.Migrations AccessFailedCount = table.Column(type: "int", nullable: false, defaultValue: 0), ShouldChangePasswordOnNextLogin = table.Column(type: "bit", nullable: false), EntityVersion = table.Column(type: "int", nullable: false), - LastPasswordChangeTime = table.Column(type: "datetime2", nullable: true), + LastPasswordChangeTime = table.Column(type: "datetimeoffset", nullable: true), ExtraProperties = table.Column(type: "nvarchar(max)", nullable: true), ConcurrencyStamp = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: true), CreationTime = table.Column(type: "datetime2", nullable: false), diff --git a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/Migrations/20230314024433_Initial.cs b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/Migrations/20230314024433_Initial.cs index a506607a81..64f21c71e9 100644 --- a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/Migrations/20230314024433_Initial.cs +++ b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/Migrations/20230314024433_Initial.cs @@ -317,7 +317,7 @@ namespace MyCompanyName.MyProjectName.Mvc.Migrations AccessFailedCount = table.Column(type: "int", nullable: false, defaultValue: 0), ShouldChangePasswordOnNextLogin = table.Column(type: "bit", nullable: false), EntityVersion = table.Column(type: "int", nullable: false), - LastPasswordChangeTime = table.Column(type: "datetime2", nullable: true), + LastPasswordChangeTime = table.Column(type: "datetimeoffset", nullable: true), ExtraProperties = table.Column(type: "nvarchar(max)", nullable: true), ConcurrencyStamp = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: true), CreationTime = table.Column(type: "datetime2", nullable: false), diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20230314023936_Initial.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20230314023936_Initial.cs index acd4e34b62..f594ae7458 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20230314023936_Initial.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20230314023936_Initial.cs @@ -338,7 +338,7 @@ namespace MyCompanyName.MyProjectName.Migrations AccessFailedCount = table.Column(type: "int", nullable: false, defaultValue: 0), ShouldChangePasswordOnNextLogin = table.Column(type: "bit", nullable: false), EntityVersion = table.Column(type: "int", nullable: false), - LastPasswordChangeTime = table.Column(type: "datetime2", nullable: true), + LastPasswordChangeTime = table.Column(type: "datetimeoffset", nullable: true), ExtraProperties = table.Column(type: "nvarchar(max)", nullable: true), ConcurrencyStamp = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: true), CreationTime = table.Column(type: "datetime2", nullable: false), diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.AuthServer/Migrations/20230314024642_Initial.cs b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.AuthServer/Migrations/20230314024642_Initial.cs index 68b1b7c744..e4e66c791a 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.AuthServer/Migrations/20230314024642_Initial.cs +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.AuthServer/Migrations/20230314024642_Initial.cs @@ -317,7 +317,7 @@ namespace MyCompanyName.MyProjectName.Migrations AccessFailedCount = table.Column(type: "int", nullable: false, defaultValue: 0), ShouldChangePasswordOnNextLogin = table.Column(type: "bit", nullable: false), EntityVersion = table.Column(type: "int", nullable: false), - LastPasswordChangeTime = table.Column(type: "datetime2", nullable: true), + LastPasswordChangeTime = table.Column(type: "datetimeoffset", nullable: true), ExtraProperties = table.Column(type: "nvarchar(max)", nullable: true), ConcurrencyStamp = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: true), CreationTime = table.Column(type: "datetime2", nullable: false), diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Server.Host/Migrations/20230314024129_Initial.cs b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Server.Host/Migrations/20230314024129_Initial.cs index 112599b999..efc30c3e7a 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Server.Host/Migrations/20230314024129_Initial.cs +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Server.Host/Migrations/20230314024129_Initial.cs @@ -317,7 +317,7 @@ namespace MyCompanyName.MyProjectName.Blazor.Server.Host.Migrations AccessFailedCount = table.Column(type: "int", nullable: false, defaultValue: 0), ShouldChangePasswordOnNextLogin = table.Column(type: "bit", nullable: false), EntityVersion = table.Column(type: "int", nullable: false), - LastPasswordChangeTime = table.Column(type: "datetime2", nullable: true), + LastPasswordChangeTime = table.Column(type: "datetimeoffset", nullable: true), ExtraProperties = table.Column(type: "nvarchar(max)", nullable: true), ConcurrencyStamp = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: true), CreationTime = table.Column(type: "datetime2", nullable: false), diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20230314024104_Initial.cs b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20230314024104_Initial.cs index 690c55586b..172f52146e 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20230314024104_Initial.cs +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20230314024104_Initial.cs @@ -317,7 +317,7 @@ namespace MyCompanyName.MyProjectName.Migrations AccessFailedCount = table.Column(type: "int", nullable: false, defaultValue: 0), ShouldChangePasswordOnNextLogin = table.Column(type: "bit", nullable: false), EntityVersion = table.Column(type: "int", nullable: false), - LastPasswordChangeTime = table.Column(type: "datetime2", nullable: true), + LastPasswordChangeTime = table.Column(type: "datetimeoffset", nullable: true), ExtraProperties = table.Column(type: "nvarchar(max)", nullable: true), ConcurrencyStamp = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: true), CreationTime = table.Column(type: "datetime2", nullable: false),