Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.
C# annotationscbzcomicinfocomicscomics-readercross-platformcsharpepubepub-readerfreelinuxmangamedia-servermetadataopdsopds-feedpdfself-hostedubooquitywindows
Stat hotfix (#1748)
Joe Milazzo3e1d0f39f0e3
diff --git a/API/Controllers/AccountController.cs b/API/Controllers/AccountController.csindex 1592a13d7..2eef78157 100644--- a/API/Controllers/AccountController.cs+++ b/API/Controllers/AccountController.cs@@ -289,7 +289,15 @@ public class AccountController : BaseApiControllervar user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());if (user == null) return Unauthorized("You do not have permission");- if (dto == null || string.IsNullOrEmpty(dto.Email)) return BadRequest("Invalid payload");+ if (dto == null || string.IsNullOrEmpty(dto.Email) || string.IsNullOrEmpty(dto.Password)) return BadRequest("Invalid payload");+++ // Validate this user's password+ if (! await _userManager.CheckPasswordAsync(user, dto.Password))+ {+ _logger.LogCritical("A user tried to change {UserName}'s email, but password didn't validate", user.UserName);+ return BadRequest("You do not have permission");+ }// Validate no other users exist with this emailif (user.Email.Equals(dto.Email)) return Ok("Nothing to do");diff --git a/API/DTOs/Account/UpdateEmailDto.cs b/API/DTOs/Account/UpdateEmailDto.csindex 9b92095d8..2363790f6 100644--- a/API/DTOs/Account/UpdateEmailDto.cs+++ b/API/DTOs/Account/UpdateEmailDto.cs@@ -3,4 +3,5 @@public class UpdateEmailDto{public string Email { get; set; }+ public string Password { get; set; }}diff --git a/API/Services/Tasks/StatsService.cs b/API/Services/Tasks/StatsService.csindex ba27508e9..a4cb355c5 100644--- a/API/Services/Tasks/StatsService.cs+++ b/API/Services/Tasks/StatsService.cs@@ -207,24 +207,28 @@ public class StatsService : IStatsServiceprivate async Task<float> GetPercentageOfLibrariesWithFolderWatchingEnabled(){var libraries = (await _unitOfWork.LibraryRepository.GetLibrariesAsync()).ToList();+ if (libraries.Count == 0) return 0.0f;return libraries.Count(l => l.FolderWatching) / (1.0f * libraries.Count);}private async Task<float> GetPercentageOfLibrariesIncludedInRecommended(){var libraries = (await _unitOfWork.LibraryRepository.GetLibrariesAsync()).ToList();+ if (libraries.Count == 0) return 0.0f;return libraries.Count(l => l.IncludeInRecommended) / (1.0f * libraries.Count);}private async Task<float> GetPercentageOfLibrariesIncludedInDashboard(){var libraries = (await _unitOfWork.LibraryRepository.GetLibrariesAsync()).ToList();+ if (libraries.Count == 0) return 0.0f;return libraries.Count(l => l.IncludeInDashboard) / (1.0f * libraries.Count);}private async Task<float> GetPercentageOfLibrariesIncludedInSearch(){var libraries = (await _unitOfWork.LibraryRepository.GetLibrariesAsync()).ToList();+ if (libraries.Count == 0) return 0.0f;return libraries.Count(l => l.IncludeInSearch) / (1.0f * libraries.Count);}diff --git a/UI/Web/src/app/_services/account.service.ts b/UI/Web/src/app/_services/account.service.tsindex 299925020..ee1dd2461 100644--- a/UI/Web/src/app/_services/account.service.ts+++ b/UI/Web/src/app/_services/account.service.ts@@ -204,8 +204,8 @@ export class AccountService implements OnDestroy {return this.httpClient.post(this.baseUrl + 'account/update', model);}- updateEmail(email: string) {- return this.httpClient.post<UpdateEmailResponse>(this.baseUrl + 'account/update/email', {email});+ updateEmail(email: string, password: string) {+ return this.httpClient.post<UpdateEmailResponse>(this.baseUrl + 'account/update/email', {email, password});}updateAgeRestriction(ageRating: AgeRating, includeUnknowns: boolean) {diff --git a/UI/Web/src/app/user-settings/change-email/change-email.component.html b/UI/Web/src/app/user-settings/change-email/change-email.component.htmlindex 7632cec00..ec859cfbb 100644--- a/UI/Web/src/app/user-settings/change-email/change-email.component.html+++ b/UI/Web/src/app/user-settings/change-email/change-email.component.html@@ -39,6 +39,17 @@</div></div>+ <div class="mb-3">+ <label for="password" class="form-label">Current Password</label>+ <input class="form-control custom-input" type="password" id="password" formControlName="password"+ [class.is-invalid]="form.get('password')?.invalid && form.get('password')?.touched">+ <div id="password-validations" class="invalid-feedback" *ngIf="form.dirty || form.touched">+ <div *ngIf="form.get('password')?.errors?.required">+ This field is required+ </div>+ </div>+ </div>+<div class="col-auto d-flex d-md-block justify-content-sm-center text-md-end mb-3"><button type="button" class="flex-fill btn btn-secondary me-2" aria-describedby="email-card" (click)="resetForm()">Reset</button><button type="submit" class="flex-fill btn btn-primary" aria-describedby="email-card" (click)="saveForm()" [disabled]="!form.valid || !(form.dirty || form.touched)">Save</button>diff --git a/UI/Web/src/app/user-settings/change-email/change-email.component.ts b/UI/Web/src/app/user-settings/change-email/change-email.component.tsindex 6455fd9b8..2864baf43 100644--- a/UI/Web/src/app/user-settings/change-email/change-email.component.ts+++ b/UI/Web/src/app/user-settings/change-email/change-email.component.ts@@ -34,6 +34,7 @@ export class ChangeEmailComponent implements OnInit, OnDestroy {this.accountService.currentUser$.pipe(takeUntil(this.onDestroy), shareReplay(), take(1)).subscribe(user => {this.user = user;this.form.addControl('email', new FormControl(user?.email, [Validators.required, Validators.email]));+ this.form.addControl('password', new FormControl('', [Validators.required]));this.cdRef.markForCheck();this.accountService.isEmailConfirmed().subscribe((confirmed) => {this.emailConfirmed = confirmed;@@ -60,7 +61,7 @@ export class ChangeEmailComponent implements OnInit, OnDestroy {const model = this.form.value;this.errors = [];- this.accountService.updateEmail(model.email).subscribe((updateEmailResponse: UpdateEmailResponse) => {+ this.accountService.updateEmail(model.email, model.password).subscribe((updateEmailResponse: UpdateEmailResponse) => {if (updateEmailResponse.emailSent) {if (updateEmailResponse.hadNoExistingEmail) {this.toastr.success('An email has been sent to ' + model.email + ' for confirmation.');diff --git a/openapi.json b/openapi.jsonindex 6327af78c..807e7fad2 100644--- a/openapi.json+++ b/openapi.json@@ -7,7 +7,7 @@"name": "GPL-3.0","url": "https://github.com/Kareadita/Kavita/blob/develop/LICENSE"},- "version": "0.6.1.27"+ "version": "0.6.1.28"},"servers": [{@@ -13690,6 +13690,10 @@"email": {"type": "string","nullable": true+ },+ "password": {+ "type": "string",+ "nullable": true}},"additionalProperties": false