* Fixed a case where when setting up initial rates for scrobbling, Kavita would log a user without a token set had no rate. * Migrated the whole app to use just the directive instead of whole transloco module. * Migrated the whole app to use just the directive instead of whole transloco module. Fixed prod mode breaking localization & fixed broken minification for language files. * Time Ago pipe will now show Never if there is a null date. Changed the wording of Last Added To -> Last Item Added for volume/series info screen. * Fixed Tachiyomi DTOs and bumped sonar to use Java 17 * One more GA thing * GA junk * Bump versions by dotnet-bump-version. * Weblate Changes (#2189) * Added translation using Weblate (Turkish) * Translated using Weblate (Thai) Currently translated at 100.0% (158 of 158 strings) Translation: Kavita/backend Translate-URL: https://hosted.weblate.org/projects/kavita/backend/th/ * Translated using Weblate (Thai) Currently translated at 15.2% (218 of 1426 strings) Translation: Kavita/ui Translate-URL: https://hosted.weblate.org/projects/kavita/ui/th/ * Translated using Weblate (Turkish) Currently translated at 7.7% (110 of 1426 strings) Translation: Kavita/ui Translate-URL: https://hosted.weblate.org/projects/kavita/ui/tr/ * Translated using Weblate (Portuguese) Currently translated at 17.5% (250 of 1426 strings) Translation: Kavita/ui Translate-URL: https://hosted.weblate.org/projects/kavita/ui/pt/ * Translated using Weblate (Russian) Currently translated at 1.2% (2 of 158 strings) Translation: Kavita/backend Translate-URL: https://hosted.weblate.org/projects/kavita/backend/ru/ * Translated using Weblate (Russian) Currently translated at 4.9% (71 of 1426 strings) Translation: Kavita/ui Translate-URL: https://hosted.weblate.org/projects/kavita/ui/ru/ * Translated using Weblate (Italian) Currently translated at 6.7% (96 of 1426 strings) Translation: Kavita/ui Translate-URL: https://hosted.weblate.org/projects/kavita/ui/it/ * Translated using Weblate (Turkish) Currently translated at 8.8% (14 of 158 strings) Translation: Kavita/backend Translate-URL: https://hosted.weblate.org/projects/kavita/backend/tr/ --------- Co-authored-by: akoray420 <akoray420@gmail.com> Co-authored-by: AlienHack <the4got10@windowslive.com> Co-authored-by: Duarte Silva <smallflake@protonmail.com> Co-authored-by: Blezz Rot <markus.jenya04@yandex.ru> Co-authored-by: Tomas Battistini <tomas.battistini@gmail.com> --------- Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: akoray420 <akoray420@gmail.com> Co-authored-by: AlienHack <the4got10@windowslive.com> Co-authored-by: Duarte Silva <smallflake@protonmail.com> Co-authored-by: Blezz Rot <markus.jenya04@yandex.ru> Co-authored-by: Tomas Battistini <tomas.battistini@gmail.com>
98 lines
3.7 KiB
TypeScript
98 lines
3.7 KiB
TypeScript
import {
|
|
ChangeDetectionStrategy,
|
|
ChangeDetectorRef,
|
|
Component,
|
|
DestroyRef,
|
|
inject,
|
|
OnDestroy,
|
|
OnInit
|
|
} from '@angular/core';
|
|
import { FormControl, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
|
|
import { ToastrService } from 'ngx-toastr';
|
|
import { map, Observable, of, shareReplay, take } from 'rxjs';
|
|
import { User } from 'src/app/_models/user';
|
|
import { AccountService } from 'src/app/_services/account.service';
|
|
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
|
|
import { NgbCollapse } from '@ng-bootstrap/ng-bootstrap';
|
|
import { NgIf, NgFor, AsyncPipe } from '@angular/common';
|
|
import {translate, TranslocoDirective} from "@ngneat/transloco";
|
|
|
|
@Component({
|
|
selector: 'app-change-password',
|
|
templateUrl: './change-password.component.html',
|
|
styleUrls: ['./change-password.component.scss'],
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
standalone: true,
|
|
imports: [NgIf, NgbCollapse, NgFor, ReactiveFormsModule, AsyncPipe, TranslocoDirective]
|
|
})
|
|
export class ChangePasswordComponent implements OnInit, OnDestroy {
|
|
|
|
passwordChangeForm: FormGroup = new FormGroup({});
|
|
user: User | undefined = undefined;
|
|
hasChangePasswordAbility: Observable<boolean> = of(false);
|
|
observableHandles: Array<any> = [];
|
|
passwordsMatch = false;
|
|
resetPasswordErrors: string[] = [];
|
|
isViewMode: boolean = true;
|
|
private readonly destroyRef = inject(DestroyRef);
|
|
|
|
public get password() { return this.passwordChangeForm.get('password'); }
|
|
public get confirmPassword() { return this.passwordChangeForm.get('confirmPassword'); }
|
|
|
|
|
|
constructor(private accountService: AccountService, private toastr: ToastrService, private readonly cdRef: ChangeDetectorRef) { }
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.accountService.currentUser$.pipe(takeUntilDestroyed(this.destroyRef), shareReplay(), take(1)).subscribe(user => {
|
|
this.user = user;
|
|
this.cdRef.markForCheck();
|
|
});
|
|
|
|
this.hasChangePasswordAbility = this.accountService.currentUser$.pipe(takeUntilDestroyed(this.destroyRef), shareReplay(), map(user => {
|
|
return user !== undefined && (this.accountService.hasAdminRole(user) || this.accountService.hasChangePasswordRole(user));
|
|
}));
|
|
this.cdRef.markForCheck();
|
|
|
|
this.passwordChangeForm.addControl('password', new FormControl('', [Validators.required]));
|
|
this.passwordChangeForm.addControl('confirmPassword', new FormControl('', [Validators.required]));
|
|
this.passwordChangeForm.addControl('oldPassword', new FormControl('', [Validators.required]));
|
|
|
|
this.observableHandles.push(this.passwordChangeForm.valueChanges.subscribe(() => {
|
|
const values = this.passwordChangeForm.value;
|
|
this.passwordsMatch = values.password === values.confirmPassword;
|
|
this.cdRef.markForCheck();
|
|
}));
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
this.observableHandles.forEach(o => o.unsubscribe());
|
|
}
|
|
|
|
resetPasswordForm() {
|
|
this.passwordChangeForm.get('password')?.setValue('');
|
|
this.passwordChangeForm.get('confirmPassword')?.setValue('');
|
|
this.passwordChangeForm.get('oldPassword')?.setValue('');
|
|
this.resetPasswordErrors = [];
|
|
this.cdRef.markForCheck();
|
|
}
|
|
|
|
savePasswordForm() {
|
|
if (this.user === undefined) { return; }
|
|
|
|
const model = this.passwordChangeForm.value;
|
|
this.resetPasswordErrors = [];
|
|
this.observableHandles.push(this.accountService.resetPassword(this.user?.username, model.confirmPassword, model.oldPassword).subscribe(() => {
|
|
this.toastr.success(translate('toasts.password-updated'));
|
|
this.resetPasswordForm();
|
|
this.isViewMode = true;
|
|
}, err => {
|
|
this.resetPasswordErrors = err;
|
|
}));
|
|
}
|
|
|
|
toggleViewMode() {
|
|
this.isViewMode = !this.isViewMode;
|
|
this.resetPasswordForm();
|
|
}
|
|
}
|