Polish Round 1 (#2396)
This commit is contained in:
parent
cf2c43d390
commit
02b002d81a
197 changed files with 1233 additions and 1751 deletions
|
@ -76,6 +76,17 @@
|
|||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.13" />
|
||||
<PackageReference Include="EasyCaching.InMemory" Version="1.9.2" />
|
||||
<PackageReference Include="ExCSS" Version="4.2.4" />
|
||||
<PackageReference Include="Hangfire" Version="1.8.6" />
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.6" />
|
||||
<PackageReference Include="Hangfire.InMemory" Version="0.6.0" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.54" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.13" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="7.0.13" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.13" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.13" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.3.2" />
|
||||
<PackageReference Include="MimeTypeMapOfficial" Version="1.0.17" />
|
||||
|
|
|
@ -603,7 +603,7 @@ public class AccountController : BaseApiController
|
|||
{
|
||||
var invitedUser = await _unitOfWork.UserRepository.GetUserByEmailAsync(dto.Email);
|
||||
if (await _userManager.IsEmailConfirmedAsync(invitedUser!))
|
||||
return BadRequest(await _localizationService.Translate(User.GetUserId(), "user-already-registered", invitedUser!.UserName));
|
||||
return BadRequest(await _localizationService.Translate(User.GetUserId(), "user-already-registered", invitedUser.UserName));
|
||||
return BadRequest(await _localizationService.Translate(User.GetUserId(), "user-already-invited"));
|
||||
}
|
||||
|
||||
|
@ -684,7 +684,6 @@ public class AccountController : BaseApiController
|
|||
{
|
||||
var emailLink = await _accountService.GenerateEmailLink(Request, user.ConfirmationToken, "confirm-email", dto.Email);
|
||||
_logger.LogCritical("[Invite User]: Email Link for {UserName}: {Link}", user.UserName, emailLink);
|
||||
_logger.LogCritical("[Invite User]: Token {UserName}: {Token}", user.UserName, user.ConfirmationToken);
|
||||
|
||||
if (!_emailService.IsValidEmail(dto.Email))
|
||||
{
|
||||
|
@ -706,7 +705,6 @@ public class AccountController : BaseApiController
|
|||
InvitingUser = adminUser.UserName!,
|
||||
ServerConfirmationLink = emailLink
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
return Ok(new InviteUserResponse
|
||||
|
@ -834,13 +832,13 @@ public class AccountController : BaseApiController
|
|||
public async Task<ActionResult<string>> ConfirmForgotPassword(ConfirmPasswordResetDto dto)
|
||||
{
|
||||
var user = await _unitOfWork.UserRepository.GetUserByEmailAsync(dto.Email);
|
||||
if (user == null)
|
||||
{
|
||||
return BadRequest(await _localizationService.Get("en", "bad-credentials"));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
return BadRequest(await _localizationService.Get("en", "bad-credentials"));
|
||||
}
|
||||
|
||||
var result = await _userManager.VerifyUserTokenAsync(user, TokenOptions.DefaultProvider,
|
||||
"ResetPassword", dto.Token);
|
||||
if (!result)
|
||||
|
|
|
@ -18,7 +18,9 @@ public class MemberDto
|
|||
public bool IsPending { get; init; }
|
||||
public AgeRestrictionDto? AgeRestriction { get; init; }
|
||||
public DateTime Created { get; init; }
|
||||
public DateTime CreatedUtc { get; init; }
|
||||
public DateTime LastActive { get; init; }
|
||||
public DateTime LastActiveUtc { get; init; }
|
||||
public IEnumerable<LibraryDto>? Libraries { get; init; }
|
||||
public IEnumerable<string>? Roles { get; init; }
|
||||
}
|
||||
|
|
|
@ -665,7 +665,9 @@ public class UserRepository : IUserRepository
|
|||
Username = u.UserName,
|
||||
Email = u.Email,
|
||||
Created = u.Created,
|
||||
CreatedUtc = u.CreatedUtc,
|
||||
LastActive = u.LastActive,
|
||||
LastActiveUtc = u.LastActiveUtc,
|
||||
Roles = u.UserRoles.Select(r => r.Role.Name).ToList(),
|
||||
IsPending = !u.EmailConfirmed,
|
||||
AgeRestriction = new AgeRestrictionDto()
|
||||
|
|
|
@ -120,6 +120,7 @@ public static class Seed
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
public static async Task SeedRoles(RoleManager<AppRole> roleManager)
|
||||
{
|
||||
var roles = typeof(PolicyConstants)
|
||||
|
|
|
@ -78,10 +78,8 @@ public class StatisticService : IStatisticService
|
|||
.CountAsync();
|
||||
|
||||
var lastActive = await _context.AppUserProgresses
|
||||
.OrderByDescending(p => p.LastModified)
|
||||
.Where(p => p.AppUserId == userId)
|
||||
.Select(p => p.LastModified)
|
||||
.FirstOrDefaultAsync();
|
||||
.MaxAsync(p => p.LastModified);
|
||||
|
||||
|
||||
// First get the total pages per library
|
||||
|
@ -103,15 +101,28 @@ public class StatisticService : IStatisticService
|
|||
})
|
||||
.ToListAsync();
|
||||
|
||||
var averageReadingTimePerWeek = _context.AppUserProgresses
|
||||
|
||||
// New solution. Calculate total hours then divide by number of weeks from time account was created (or min reading event) till now
|
||||
var averageReadingTimePerWeek = await _context.AppUserProgresses
|
||||
.Where(p => p.AppUserId == userId)
|
||||
.Join(_context.Chapter, p => p.ChapterId, c => c.Id,
|
||||
(p, c) => new
|
||||
{
|
||||
AverageReadingHours = Math.Min((float) p.PagesRead / (float) c.Pages, 1.0) * ((float) c.AvgHoursToRead)
|
||||
AverageReadingHours = Math.Min((float) p.PagesRead / (float) c.Pages, 1.0) *
|
||||
((float) c.AvgHoursToRead)
|
||||
})
|
||||
.Select(x => x.AverageReadingHours)
|
||||
.Average() * 7.0;
|
||||
.SumAsync();
|
||||
|
||||
var earliestReadDate = await _context.AppUserProgresses
|
||||
.Where(p => p.AppUserId == userId)
|
||||
.MinAsync(p => p.Created);
|
||||
|
||||
var timeDifference = DateTime.Now - earliestReadDate;
|
||||
var deltaWeeks = (int)Math.Ceiling(timeDifference.TotalDays / 7);
|
||||
|
||||
averageReadingTimePerWeek /= deltaWeeks;
|
||||
|
||||
|
||||
return new UserReadStatistics()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue