From 96c416144bc9cdebfd51349f9075ab12014a9c6b Mon Sep 17 00:00:00 2001 From: VahidN Date: Fri, 7 Jul 2023 14:16:04 +0330 Subject: [PATCH] Upgrade to SDK-7.0.305 --- .config/dotnet-tools.json | 2 +- .editorconfig | 1 + .github/FUNDING.yml | 12 ------ .github/workflows/build.yml | 2 +- Directory.Packages.props | 40 +++++++++---------- README.md | 2 +- global.json | 2 +- .../WebToolkit/ServerInfo.cs | 5 ++- .../_01-add_migrations.cmd | 2 +- .../_02-update_db.cmd | 2 +- .../_01-add_migrations.cmd | 2 +- .../_02-update_db.cmd | 2 +- .../Identity/SiteStatService.cs | 36 ++++++++--------- .../Identity/UsedPasswordsService.cs | 30 +++++++------- src/ASPNETCoreIdentitySample/Program.cs | 6 +-- 15 files changed, 68 insertions(+), 78 deletions(-) delete mode 100644 .github/FUNDING.yml diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index b03108e..40d5b55 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "dotnet-ef": { - "version": "7.0.3", + "version": "7.0.8", "commands": [ "dotnet-ef" ] diff --git a/.editorconfig b/.editorconfig index 3124ec3..c6d9cb6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -18,6 +18,7 @@ dotnet_diagnostic.CA5395.severity = suggestion dotnet_diagnostic.CA1510.severity = suggestion dotnet_diagnostic.S4487.severity = suggestion dotnet_diagnostic.S1144.severity = suggestion +dotnet_diagnostic.S6605.severity = suggestion # CA1852: Type can be sealed because it has no subtypes in its containing assembly and is not externally visible dotnet_diagnostic.CA1852.severity = suggestion diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index f95b530..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,12 +0,0 @@ -# These are supported funding model platforms - -github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] -patreon: # Replace with a single Patreon username -open_collective: # Replace with a single Open Collective username -ko_fi: # Replace with a single Ko-fi username -tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: # Replace with a single Liberapay username -issuehunt: # Replace with a single IssueHunt username -otechie: # Replace with a single Otechie username -custom: ['https://coffeebede.ir/%D9%88%D8%AD%D9%8A%D8%AF%D9%86%D8%B5%D9%8A%D8%B1%D9%8A', 'https://www.buymeacoffee.com/vahidn'] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d050a33..db6e891 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,6 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 7.0.203 + dotnet-version: 7.0.305 - name: Build DNTIdentity run: dotnet build ./src/ASPNETCoreIdentitySample/ASPNETCoreIdentitySample.csproj --configuration Release \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props index c662835..de6b34f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,39 +1,39 @@ - - + + - + - - - + + + - + - - - - - + + + + + - + - - - + + + - - - - + + + + diff --git a/README.md b/README.md index 38e3dd2..908e846 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ 
-# سفارشی سازی ASP.NET Core Identity SDK-7.0.200 +# سفارشی سازی ASP.NET Core Identity SDK-7.0.305

diff --git a/global.json b/global.json index a27d375..d70f609 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "7.0.203", + "version": "7.0.305", "rollForward": "latestMajor", "allowPrerelease": false } diff --git a/src/ASPNETCoreIdentitySample.Common/WebToolkit/ServerInfo.cs b/src/ASPNETCoreIdentitySample.Common/WebToolkit/ServerInfo.cs index c4020d3..cad2608 100644 --- a/src/ASPNETCoreIdentitySample.Common/WebToolkit/ServerInfo.cs +++ b/src/ASPNETCoreIdentitySample.Common/WebToolkit/ServerInfo.cs @@ -9,13 +9,14 @@ public static string GetAppDataFolderPath() { Directory.CreateDirectory(appDataFolderPath); } + return appDataFolderPath; } public static string GetWwwRootPath() { return Path.Combine( - AppContext.BaseDirectory.Split(new[] { "bin" }, StringSplitOptions.RemoveEmptyEntries).First(), - "wwwroot"); + AppContext.BaseDirectory.Split(new[] { "bin" }, StringSplitOptions.RemoveEmptyEntries)[0], + "wwwroot"); } } \ No newline at end of file diff --git a/src/ASPNETCoreIdentitySample.DataLayer.MSSQL/_01-add_migrations.cmd b/src/ASPNETCoreIdentitySample.DataLayer.MSSQL/_01-add_migrations.cmd index 8560db5..4f97d48 100644 --- a/src/ASPNETCoreIdentitySample.DataLayer.MSSQL/_01-add_migrations.cmd +++ b/src/ASPNETCoreIdentitySample.DataLayer.MSSQL/_01-add_migrations.cmd @@ -1,6 +1,6 @@ For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c_%%a_%%b) For /f "tokens=1-2 delims=/:" %%a in ("%TIME: =0%") do (set mytime=%%a%%b) -dotnet tool update --global dotnet-ef --version 7.0.3 +dotnet tool update --global dotnet-ef --version 7.0.8 dotnet tool restore dotnet build dotnet ef migrations --startup-project ../ASPNETCoreIdentitySample/ add V%mydate%_%mytime% --context MsSqlDbContext diff --git a/src/ASPNETCoreIdentitySample.DataLayer.MSSQL/_02-update_db.cmd b/src/ASPNETCoreIdentitySample.DataLayer.MSSQL/_02-update_db.cmd index db83b33..d824a2c 100644 --- a/src/ASPNETCoreIdentitySample.DataLayer.MSSQL/_02-update_db.cmd +++ b/src/ASPNETCoreIdentitySample.DataLayer.MSSQL/_02-update_db.cmd @@ -1,4 +1,4 @@ -dotnet tool update --global dotnet-ef --version 7.0.3 +dotnet tool update --global dotnet-ef --version 7.0.8 dotnet tool restore dotnet build dotnet ef --startup-project ../ASPNETCoreIdentitySample/ database update --context MsSqlDbContext diff --git a/src/ASPNETCoreIdentitySample.DataLayer.SQLite/_01-add_migrations.cmd b/src/ASPNETCoreIdentitySample.DataLayer.SQLite/_01-add_migrations.cmd index 394fa80..ee123b7 100644 --- a/src/ASPNETCoreIdentitySample.DataLayer.SQLite/_01-add_migrations.cmd +++ b/src/ASPNETCoreIdentitySample.DataLayer.SQLite/_01-add_migrations.cmd @@ -1,6 +1,6 @@ For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c_%%a_%%b) For /f "tokens=1-2 delims=/:" %%a in ("%TIME: =0%") do (set mytime=%%a%%b) -dotnet tool update --global dotnet-ef --version 7.0.3 +dotnet tool update --global dotnet-ef --version 7.0.8 dotnet tool restore dotnet build dotnet ef migrations --startup-project ../ASPNETCoreIdentitySample/ add V%mydate%_%mytime% --context SQLiteDbContext diff --git a/src/ASPNETCoreIdentitySample.DataLayer.SQLite/_02-update_db.cmd b/src/ASPNETCoreIdentitySample.DataLayer.SQLite/_02-update_db.cmd index ed60c18..53b29af 100644 --- a/src/ASPNETCoreIdentitySample.DataLayer.SQLite/_02-update_db.cmd +++ b/src/ASPNETCoreIdentitySample.DataLayer.SQLite/_02-update_db.cmd @@ -1,4 +1,4 @@ -dotnet tool update --global dotnet-ef --version 7.0.3 +dotnet tool update --global dotnet-ef --version 7.0.8 dotnet tool restore dotnet build dotnet ef --startup-project ../ASPNETCoreIdentitySample/ database update --context SQLiteDbContext diff --git a/src/ASPNETCoreIdentitySample.Services/Identity/SiteStatService.cs b/src/ASPNETCoreIdentitySample.Services/Identity/SiteStatService.cs index a8f7da8..81309aa 100644 --- a/src/ASPNETCoreIdentitySample.Services/Identity/SiteStatService.cs +++ b/src/ASPNETCoreIdentitySample.Services/Identity/SiteStatService.cs @@ -28,11 +28,11 @@ public Task> GetOnlineUsersListAsync(int numbersToTake, int minutesTo var now = DateTime.UtcNow; var minutes = now.AddMinutes(-minutesToTake); return _users.AsNoTracking() - .Where(user => user.LastVisitDateTime != null && user.LastVisitDateTime.Value <= now - && user.LastVisitDateTime.Value >= minutes) - .OrderByDescending(user => user.LastVisitDateTime) - .Take(numbersToTake) - .ToListAsync(); + .Where(user => user.LastVisitDateTime != null && user.LastVisitDateTime.Value <= now + && user.LastVisitDateTime.Value >= minutes) + .OrderByDescending(user => user.LastVisitDateTime) + .Take(numbersToTake) + .ToListAsync(); } public Task> GetTodayBirthdayListAsync() @@ -41,18 +41,18 @@ public Task> GetTodayBirthdayListAsync() var day = now.Day; var month = now.Month; return _users.AsNoTracking() - .Where(user => user.BirthDate != null && user.IsActive - && user.BirthDate.Value.Day == day - && user.BirthDate.Value.Month == month) - .ToListAsync(); + .Where(user => user.BirthDate != null && user.IsActive + && user.BirthDate.Value.Day == day + && user.BirthDate.Value.Month == month) + .ToListAsync(); } public async Task GetUsersAverageAge() { var users = await _users.AsNoTracking() - .Where(x => x.BirthDate != null && x.IsActive) - .OrderBy(x => x.BirthDate) - .ToListAsync(); + .Where(x => x.BirthDate != null && x.IsActive) + .OrderBy(x => x.BirthDate) + .ToListAsync(); var count = users.Count; if (count == 0) @@ -63,12 +63,12 @@ public async Task GetUsersAverageAge() var sum = users.Where(user => user.BirthDate != null).Sum(user => (int?)user.BirthDate.Value.GetAge()) ?? 0; return new AgeStatViewModel - { - AverageAge = sum / count, - MaxAgeUser = users.First(), - MinAgeUser = users.Last(), - UsersCount = count - }; + { + AverageAge = sum / count, + MaxAgeUser = users[0], + MinAgeUser = users[^1], + UsersCount = count, + }; } public async Task UpdateUserLastVisitDateTimeAsync(ClaimsPrincipal claimsPrincipal) diff --git a/src/ASPNETCoreIdentitySample.Services/Identity/UsedPasswordsService.cs b/src/ASPNETCoreIdentitySample.Services/Identity/UsedPasswordsService.cs index 27845d1..847b74e 100644 --- a/src/ASPNETCoreIdentitySample.Services/Identity/UsedPasswordsService.cs +++ b/src/ASPNETCoreIdentitySample.Services/Identity/UsedPasswordsService.cs @@ -49,10 +49,10 @@ public async Task AddToUsedPasswordsListAsync(User user) } await _userUsedPasswords.AddAsync(new UserUsedPassword - { - UserId = user.Id, - HashedPassword = user.PasswordHash - }); + { + UserId = user.Id, + HashedPassword = user.PasswordHash, + }); await _uow.SaveChangesAsync(); } @@ -60,8 +60,8 @@ await _userUsedPasswords.AddAsync(new UserUsedPassword { var lastPasswordHistory = await _userUsedPasswords //.AsNoTracking() --> removes shadow properties - .OrderByDescending(userUsedPassword => userUsedPassword.Id) - .FirstOrDefaultAsync(userUsedPassword => userUsedPassword.UserId == userId); + .OrderByDescending(userUsedPassword => userUsedPassword.Id) + .FirstOrDefaultAsync(userUsedPassword => userUsedPassword.UserId == userId); if (lastPasswordHistory == null) { return null; @@ -97,14 +97,14 @@ public async Task IsPreviouslyUsedPasswordAsync(User user, string newPassw var userId = user.Id; var usedPasswords = await _userUsedPasswords - .AsNoTracking() - .Where(userUsedPassword => userUsedPassword.UserId == userId) - .OrderByDescending(userUsedPassword => userUsedPassword.Id) - .Select(userUsedPassword => userUsedPassword.HashedPassword) - .Take(_notAllowedPreviouslyUsedPasswords) - .ToListAsync(); - return usedPasswords.Any(hashedPassword => - _passwordHasher.VerifyHashedPassword(user, hashedPassword, newPassword) != - PasswordVerificationResult.Failed); + .AsNoTracking() + .Where(userUsedPassword => userUsedPassword.UserId == userId) + .OrderByDescending(userUsedPassword => userUsedPassword.Id) + .Select(userUsedPassword => userUsedPassword.HashedPassword) + .Take(_notAllowedPreviouslyUsedPasswords) + .ToListAsync(); + return usedPasswords.Exists(hashedPassword => + _passwordHasher.VerifyHashedPassword(user, hashedPassword, newPassword) != + PasswordVerificationResult.Failed); } } \ No newline at end of file diff --git a/src/ASPNETCoreIdentitySample/Program.cs b/src/ASPNETCoreIdentitySample/Program.cs index 2ee9622..938f2dc 100644 --- a/src/ASPNETCoreIdentitySample/Program.cs +++ b/src/ASPNETCoreIdentitySample/Program.cs @@ -6,14 +6,14 @@ var builder = WebApplication.CreateBuilder(args); ConfigureLogging(builder.Logging, builder.Environment, builder.Configuration); -ConfigureServices(builder.Services, builder.Configuration); +ConfigureServices(builder.Services, builder.Configuration, builder.Environment); var webApp = builder.Build(); ConfigureMiddlewares(webApp, webApp.Environment); ConfigureEndpoints(webApp); ConfigureDatabase(webApp); webApp.Run(); -void ConfigureServices(IServiceCollection services, IConfiguration configuration) +void ConfigureServices(IServiceCollection services, IConfiguration configuration, IWebHostEnvironment env) { services.Configure(options => configuration.Bind(options)); services.Configure(options => @@ -30,8 +30,8 @@ void ConfigureServices(IServiceCollection services, IConfiguration configuration { options.UseCookieStorageProvider() .AbsoluteExpiration(7) + .ShowExceptionsInResponse(env.IsDevelopment()) .ShowThousandsSeparators(false) - .WithNoise(25, 3) .WithEncryptionKey("This is my secure key!"); }); services.AddCloudscribePagination();