diff --git a/API/Controllers/LicenseController.cs b/API/Controllers/LicenseController.cs index 05886e77c..08a7789ad 100644 --- a/API/Controllers/LicenseController.cs +++ b/API/Controllers/LicenseController.cs @@ -8,7 +8,6 @@ using API.Extensions; using API.Services; using API.Services.Plus; -using Kavita.Common; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; @@ -17,22 +16,13 @@ namespace API.Controllers; #nullable enable -public class LicenseController : BaseApiController +public class LicenseController( + IUnitOfWork unitOfWork, + ILogger logger, + ILicenseService licenseService, + ILocalizationService localizationService) + : BaseApiController { - private readonly IUnitOfWork _unitOfWork; - private readonly ILogger _logger; - private readonly ILicenseService _licenseService; - private readonly ILocalizationService _localizationService; - - public LicenseController(IUnitOfWork unitOfWork, ILogger logger, - ILicenseService licenseService, ILocalizationService localizationService) - { - _unitOfWork = unitOfWork; - _logger = logger; - _licenseService = licenseService; - _localizationService = localizationService; - } - /// /// Checks if the user's license is valid or not /// @@ -41,7 +31,7 @@ public LicenseController(IUnitOfWork unitOfWork, ILogger logg [ResponseCache(CacheProfileName = ResponseCacheProfiles.LicenseCache)] public async Task> HasValidLicense(bool forceCheck = false) { - return Ok(await _licenseService.HasActiveLicense(forceCheck)); + return Ok(await licenseService.HasActiveLicense(forceCheck)); } /// @@ -54,7 +44,7 @@ public async Task> HasValidLicense(bool forceCheck = false) public async Task> HasLicense() { return Ok(!string.IsNullOrEmpty( - (await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.LicenseKey)).Value)); + (await unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.LicenseKey)).Value)); } [Authorize("RequireAdminRole")] @@ -62,14 +52,24 @@ public async Task> HasLicense() [ResponseCache(CacheProfileName = ResponseCacheProfiles.LicenseCache)] public async Task RemoveLicense() { - _logger.LogInformation("Removing license on file for Server"); - var setting = await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.LicenseKey); + logger.LogInformation("Removing license on file for Server"); + var setting = await unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.LicenseKey); setting.Value = null; - _unitOfWork.SettingsRepository.Update(setting); - await _unitOfWork.CommitAsync(); + unitOfWork.SettingsRepository.Update(setting); + await unitOfWork.CommitAsync(); return Ok(); } + [Authorize("RequireAdminRole")] + [HttpPost("reset")] + public async Task ResetLicense(UpdateLicenseDto dto) + { + logger.LogInformation("Resetting license on file for Server"); + if (await licenseService.ResetLicense(dto.License, dto.Email)) return Ok(); + + return BadRequest(localizationService.Translate(User.GetUserId(), "unable-to-reset-k+")); + } + /// /// Updates server license /// @@ -81,11 +81,11 @@ public async Task UpdateLicense(UpdateLicenseDto dto) { try { - await _licenseService.AddLicense(dto.License.Trim(), dto.Email.Trim()); + await licenseService.AddLicense(dto.License.Trim(), dto.Email.Trim(), dto.DiscordId); } catch (Exception ex) { - return BadRequest(await _localizationService.Translate(User.GetUserId(), ex.Message)); + return BadRequest(await localizationService.Translate(User.GetUserId(), ex.Message)); } return Ok(); } diff --git a/API/DTOs/License/EncryptLicenseDto.cs b/API/DTOs/License/EncryptLicenseDto.cs index df4426018..97015c470 100644 --- a/API/DTOs/License/EncryptLicenseDto.cs +++ b/API/DTOs/License/EncryptLicenseDto.cs @@ -5,4 +5,5 @@ public class EncryptLicenseDto public required string License { get; set; } public required string InstallId { get; set; } public required string EmailId { get; set; } + public string? DiscordId { get; set; } } diff --git a/API/DTOs/License/ResetLicenseDto.cs b/API/DTOs/License/ResetLicenseDto.cs new file mode 100644 index 000000000..f62d78870 --- /dev/null +++ b/API/DTOs/License/ResetLicenseDto.cs @@ -0,0 +1,8 @@ +namespace API.DTOs.License; + +public class ResetLicenseDto +{ + public required string License { get; set; } + public required string InstallId { get; set; } + public required string EmailId { get; set; } +} diff --git a/API/DTOs/License/UpdateLicenseDto.cs b/API/DTOs/License/UpdateLicenseDto.cs index 1b4270e6b..b2803952c 100644 --- a/API/DTOs/License/UpdateLicenseDto.cs +++ b/API/DTOs/License/UpdateLicenseDto.cs @@ -10,4 +10,8 @@ public class UpdateLicenseDto /// Email registered with Stripe /// public required string Email { get; set; } + /// + /// Optional DiscordId + /// + public string? DiscordId { get; set; } } diff --git a/API/I18N/en.json b/API/I18N/en.json index 4c1c5b8c4..b7ddc1128 100644 --- a/API/I18N/en.json +++ b/API/I18N/en.json @@ -175,6 +175,7 @@ "not-authenticated": "User is not authenticated", "unable-to-register-k+": "Unable to register license due to error. Reach out to Kavita+ Support", + "unable-to-reset-k+": "Unable to reset Kavita+ license due to error. Reach out to Kavita+ Support", "anilist-cred-expired": "AniList Credentials have expired or not set", "scrobble-bad-payload": "Bad payload from Scrobble Provider", "theme-doesnt-exist": "Theme file missing or invalid", diff --git a/API/Services/Plus/LicenseService.cs b/API/Services/Plus/LicenseService.cs index 2307520e4..c00527c2c 100644 --- a/API/Services/Plus/LicenseService.cs +++ b/API/Services/Plus/LicenseService.cs @@ -26,8 +26,9 @@ public interface ILicenseService { Task ValidateLicenseStatus(); Task RemoveLicense(); - Task AddLicense(string license, string email); + Task AddLicense(string license, string email, string? discordId); Task HasActiveLicense(bool forceCheck = false); + Task ResetLicense(string license, string email); } public class LicenseService : ILicenseService @@ -87,7 +88,7 @@ private async Task IsLicenseValid(string license) /// /// /// - private async Task RegisterLicense(string license, string email) + private async Task RegisterLicense(string license, string email, string? discordId) { if (string.IsNullOrWhiteSpace(license) || string.IsNullOrWhiteSpace(email)) return string.Empty; try @@ -104,7 +105,8 @@ private async Task RegisterLicense(string license, string email) { License = license.Trim(), InstallId = HashUtil.ServerToken(), - EmailId = email.Trim() + EmailId = email.Trim(), + DiscordId = discordId?.Trim() }) .ReceiveJson(); @@ -164,10 +166,10 @@ public async Task RemoveLicense() await provider.RemoveAsync(CacheKey); } - public async Task AddLicense(string license, string email) + public async Task AddLicense(string license, string email, string? discordId) { var serverSetting = await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.LicenseKey); - var lic = await RegisterLicense(license, email); + var lic = await RegisterLicense(license, email, discordId); if (string.IsNullOrWhiteSpace(lic)) throw new KavitaException("unable-to-register-k+"); serverSetting.Value = lic; @@ -199,4 +201,43 @@ public async Task HasActiveLicense(bool forceCheck = false) return false; } + + public async Task ResetLicense(string license, string email) + { + try + { + var encryptedLicense = await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.LicenseKey); + var response = await (Configuration.KavitaPlusApiUrl + "/api/license/reset") + .WithHeader("Accept", "application/json") + .WithHeader("User-Agent", "Kavita") + .WithHeader("x-license-key", encryptedLicense.Value) + .WithHeader("x-installId", HashUtil.ServerToken()) + .WithHeader("x-kavita-version", BuildInfo.Version) + .WithHeader("Content-Type", "application/json") + .WithTimeout(TimeSpan.FromSeconds(Configuration.DefaultTimeOutSecs)) + .PostJsonAsync(new ResetLicenseDto() + { + License = license.Trim(), + InstallId = HashUtil.ServerToken(), + EmailId = email + }) + .ReceiveString(); + + if (string.IsNullOrEmpty(response)) + { + var provider = _cachingProviderFactory.GetCachingProvider(EasyCacheProfiles.License); + await provider.RemoveAsync(CacheKey); + return true; + } + + _logger.LogError("An error happened during the request to Kavita+ API: {ErrorMessage}", response); + throw new KavitaException(response); + } + catch (FlurlHttpException e) + { + _logger.LogError(e, "An error happened during the request to Kavita+ API"); + } + + return false; + } } diff --git a/README.md b/README.md index 484331e7e..ed948a773 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ your reading collection with your friends and family! [![Release](https://img.shields.io/github/release/Kareadita/Kavita.svg?style=flat&maxAge=3600)](https://github.com/Kareadita/Kavita/releases) [![License](https://img.shields.io/badge/license-GPLv3-blue.svg?style=flat)](https://github.com/Kareadita/Kavita/blob/master/LICENSE) [![Downloads](https://img.shields.io/github/downloads/Kareadita/Kavita/total.svg?style=flat)](https://github.com/Kareadita/Kavita/releases) -[![Docker Pulls](https://img.shields.io/docker/pulls/kizaing/kavita.svg)](https://hub.docker.com/r/jvmilazz0/kavita) +[![Docker Pulls](https://img.shields.io/docker/pulls/jvmilazz0/kavita.svg)](https://hub.docker.com/r/jvmilazz0/kavita) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=Kareadita_Kavita&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=Kareadita_Kavita) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=Kareadita_Kavita&metric=security_rating)](https://sonarcloud.io/dashboard?id=Kareadita_Kavita) [![Backers on Open Collective](https://opencollective.com/kavita/backers/badge.svg)](#backers) @@ -35,12 +35,11 @@ your reading collection with your friends and family! ## Support -[![Reddit](https://img.shields.io/badge/reddit-discussion-FF4500.svg?maxAge=60)](https://www.reddit.com/r/KavitaManga/) [![Discord](https://img.shields.io/badge/discord-chat-7289DA.svg?maxAge=60)](https://discord.gg/eczRp9eeem) [![GitHub - Bugs Only](https://img.shields.io/badge/github-issues-red.svg?maxAge=60)](https://github.com/Kareadita/Kavita/issues) ## Demo -If you want to try out Kavita, we have a demo up: +If you want to try out Kavita, a demo is available: [https://demo.kavitareader.com/](https://demo.kavitareader.com/) ``` Username: demouser @@ -52,8 +51,6 @@ The easiest way to get started is to visit our Wiki which has up-to-date informa install methods and platforms. [https://wiki.kavitareader.com/en/install](https://wiki.kavitareader.com/en/install) -**Note: Kavita is under heavy development and is being updated all the time, so the tag for bleeding edge builds is `:nightly`. The `:latest` tag will be the latest stable release.** - ## Feature Requests Got a great idea? Throw it up on our [Feature Request site](https://feats.kavitareader.com/), [Feature Discord Channel](https://discord.com/channels/821879810934439936/1164375153493422122) or vote on another idea. Please check the [Project Board](https://github.com/Kareadita/Kavita/projects?type=classic) first for a list of planned features before you submit an idea. @@ -71,7 +68,18 @@ expenses related to Kavita. Back us through [OpenCollective](https://opencollect If you are interested, you can use the promo code `FIRSTTIME` for your initial signup for a 50% discount on the first month (2$). This can be thought of as donating to Kavita's development and getting some sweet features out of it. -**If you already contribute via OpenCollective, please reach out to me for a provisioned license.** +**If you already contribute via OpenCollective, please reach out to majora2007 for a provisioned license.** + +## Localization +Thank you to [Weblate](https://hosted.weblate.org/engage/kavita/) who hosts our localization infrastructure pro-bono. If you want to see Kavita in your language, please help us localize. + + +Translation status + + +## PikaPods +If you are looking to try your hand at self-hosting but lack the machine, [PikaPods](https://www.pikapods.com/pods?run=kavita) is a great service that +allows you to easily spin up a server. 20% of app revenues are contributed back to Kavita via OpenCollective. ## Contributors @@ -103,17 +111,6 @@ Thank you to [ JetBrains](http: * [ Rider](http://www.jetbrains.com/rider/) * [ dotTrace](http://www.jetbrains.com/dottrace/) -## Localization -Thank you to [Weblate](https://hosted.weblate.org/engage/kavita/) who hosts our localization infrastructure pro-bono. If you want to see Kavita in your language, please help us localize. - - -Translation status - - -## PikaPods -If you are looking to try your hand at self-hosting but lack the machine, [PikaPods](https://www.pikapods.com/pods?run=kavita) is a great service that -allows you to easily spin up a server. 20% of app revenues are contributed back to Kavita via OpenCollective. - ### License * [GNU GPL v3](http://www.gnu.org/licenses/gpl.html) diff --git a/UI/Web/package-lock.json b/UI/Web/package-lock.json index 8e2476321..4bb7bdb06 100644 --- a/UI/Web/package-lock.json +++ b/UI/Web/package-lock.json @@ -978,6 +978,7 @@ "version": "17.0.6", "resolved": "https://registry.npmjs.org/@angular/compiler-cli/-/compiler-cli-17.0.6.tgz", "integrity": "sha512-C1Gfh9kbjYZezEMOwxnvUTHuPXa+6pk7mAfSj8e5oAO6E+wfo2dTxv1J5zxa3KYzxPYMNfF8OFvLuMKsw7lXjA==", + "dev": true, "dependencies": { "@babel/core": "7.23.2", "@jridgewell/sourcemap-codec": "^1.4.14", @@ -5817,6 +5818,7 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dev": true, "dependencies": { "normalize-path": "^3.0.0", "picomatch": "^2.0.4" @@ -6073,6 +6075,7 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "dev": true, "engines": { "node": ">=8" } @@ -6682,6 +6685,7 @@ "version": "3.5.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", + "dev": true, "funding": [ { "type": "individual", @@ -6969,7 +6973,8 @@ "node_modules/convert-source-map": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", - "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==" + "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==", + "dev": true }, "node_modules/cookie": { "version": "0.4.2", @@ -7972,6 +7977,7 @@ "version": "0.1.13", "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz", "integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==", + "dev": true, "optional": true, "dependencies": { "iconv-lite": "^0.6.2" @@ -7981,6 +7987,7 @@ "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dev": true, "optional": true, "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" @@ -9268,6 +9275,7 @@ "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, "hasInstallScript": true, "optional": true, "os": [ @@ -10051,6 +10059,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, "dependencies": { "binary-extensions": "^2.0.0" }, @@ -11963,6 +11972,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true, "engines": { "node": ">=0.10.0" } @@ -13390,6 +13400,7 @@ "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, "dependencies": { "picomatch": "^2.2.1" }, @@ -13400,7 +13411,8 @@ "node_modules/reflect-metadata": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", - "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" + "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==", + "dev": true }, "node_modules/regenerate": { "version": "1.4.2", @@ -13870,7 +13882,7 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "devOptional": true + "dev": true }, "node_modules/sass": { "version": "1.69.5", @@ -13986,6 +13998,7 @@ "version": "7.5.3", "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", + "dev": true, "dependencies": { "lru-cache": "^6.0.0" }, @@ -14000,6 +14013,7 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, "dependencies": { "yallist": "^4.0.0" }, @@ -14010,7 +14024,8 @@ "node_modules/semver/node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true }, "node_modules/send": { "version": "0.16.2", @@ -15261,6 +15276,7 @@ "version": "5.2.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/UI/Web/src/app/_services/account.service.ts b/UI/Web/src/app/_services/account.service.ts index 88dc2dc38..560303dbb 100644 --- a/UI/Web/src/app/_services/account.service.ts +++ b/UI/Web/src/app/_services/account.service.ts @@ -15,6 +15,7 @@ import { AgeRating } from '../_models/metadata/age-rating'; import { AgeRestriction } from '../_models/metadata/age-restriction'; import { TextResonse } from '../_types/text-response'; import {takeUntilDestroyed} from "@angular/core/rxjs-interop"; +import {ToastrService} from "ngx-toastr"; export enum Role { Admin = 'Admin', @@ -30,6 +31,8 @@ export enum Role { export class AccountService { private readonly destroyRef = inject(DestroyRef); + private readonly toastr = inject(ToastrService); + baseUrl = environment.apiUrl; userKey = 'kavita-user'; public static lastLoginKey = 'kavita-lastlogin'; @@ -88,6 +91,10 @@ export class AccountService { return this.httpClient.delete(this.baseUrl + 'license', TextResonse); } + resetLicense(license: string, email: string) { + return this.httpClient.post(this.baseUrl + 'license/reset', {license, email}, TextResonse); + } + hasValidLicense(forceCheck: boolean = false) { return this.httpClient.get(this.baseUrl + 'license/valid-license?forceCheck=' + forceCheck, TextResonse) .pipe( @@ -109,8 +116,8 @@ export class AccountService { ); } - updateUserLicense(license: string, email: string) { - return this.httpClient.post(this.baseUrl + 'license', {license, email}, TextResonse) + updateUserLicense(license: string, email: string, discordId?: string) { + return this.httpClient.post(this.baseUrl + 'license', {license, email, discordId}, TextResonse) .pipe(map(res => res === "true")); } diff --git a/UI/Web/src/app/admin/dashboard/dashboard.component.ts b/UI/Web/src/app/admin/dashboard/dashboard.component.ts index 7ffca3d09..d550d451e 100644 --- a/UI/Web/src/app/admin/dashboard/dashboard.component.ts +++ b/UI/Web/src/app/admin/dashboard/dashboard.component.ts @@ -46,6 +46,13 @@ enum TabID { }) export class DashboardComponent implements OnInit { + private readonly cdRef = inject(ChangeDetectorRef); + protected readonly route = inject(ActivatedRoute); + protected readonly navService = inject(NavService); + private readonly titleService = inject(Title); + protected readonly TabID = TabID; + + tabs: Array<{title: string, fragment: string}> = [ {title: 'general-tab', fragment: TabID.General}, {title: 'users-tab', fragment: TabID.Users}, @@ -59,14 +66,8 @@ export class DashboardComponent implements OnInit { ]; active = this.tabs[0]; - private readonly cdRef = inject(ChangeDetectorRef); - private readonly translocoService = inject(TranslocoService); - - get TabID() { - return TabID; - } - constructor(public route: ActivatedRoute, private titleService: Title, public navService: NavService) { + constructor() { this.route.fragment.subscribe(frag => { const tab = this.tabs.filter(item => item.fragment === frag); if (tab.length > 0) { diff --git a/UI/Web/src/app/admin/license/license.component.html b/UI/Web/src/app/admin/license/license.component.html index 5f92f9fc6..bc268788f 100644 --- a/UI/Web/src/app/admin/license/license.component.html +++ b/UI/Web/src/app/admin/license/license.component.html @@ -7,16 +7,15 @@

{{t('title')}}

- - + @if (hasLicense) { + @if (hasValidLicense) { {{t('manage')}} - - + } @else { {{t('renew')}} - + } - - + } @else { {{t('buy')}} - + }
- + @if (isViewMode) {
@@ -57,7 +55,8 @@

{{t('title')}}

{{t('no-license-key')}}
-
+ } +
@@ -70,12 +69,23 @@

{{t('title')}}

+
+ + +
- - + diff --git a/UI/Web/src/app/admin/license/license.component.ts b/UI/Web/src/app/admin/license/license.component.ts index b73d51beb..a47240be2 100644 --- a/UI/Web/src/app/admin/license/license.component.ts +++ b/UI/Web/src/app/admin/license/license.component.ts @@ -1,7 +1,7 @@ import { ChangeDetectionStrategy, ChangeDetectorRef, - Component, + Component, inject, OnInit } from '@angular/core'; import { FormControl, FormGroup, Validators, ReactiveFormsModule } from "@angular/forms"; @@ -14,17 +14,23 @@ import { NgbTooltip, NgbCollapse } from '@ng-bootstrap/ng-bootstrap'; import { NgIf } from '@angular/common'; import {environment} from "../../../environments/environment"; import {translate, TranslocoDirective} from "@ngneat/transloco"; +import {catchError} from "rxjs"; @Component({ - selector: 'app-license', - templateUrl: './license.component.html', - styleUrls: ['./license.component.scss'], - changeDetection: ChangeDetectionStrategy.OnPush, - standalone: true, + selector: 'app-license', + templateUrl: './license.component.html', + styleUrls: ['./license.component.scss'], + changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, imports: [NgIf, NgbTooltip, LoadingComponent, NgbCollapse, ReactiveFormsModule, TranslocoDirective] }) export class LicenseComponent implements OnInit { + private readonly cdRef = inject(ChangeDetectorRef); + private readonly toastr = inject(ToastrService); + private readonly confirmService = inject(ConfirmService); + protected readonly accountService = inject(AccountService); + formGroup: FormGroup = new FormGroup({}); isViewMode: boolean = true; @@ -38,13 +44,11 @@ export class LicenseComponent implements OnInit { - constructor(public accountService: AccountService, private scrobblingService: ScrobblingService, - private toastr: ToastrService, private readonly cdRef: ChangeDetectorRef, - private confirmService: ConfirmService) { } ngOnInit(): void { this.formGroup.addControl('licenseKey', new FormControl('', [Validators.required])); this.formGroup.addControl('email', new FormControl('', [Validators.required])); + this.formGroup.addControl('discordId', new FormControl('', [])); this.accountService.hasAnyLicense().subscribe(res => { this.hasLicense = res; this.cdRef.markForCheck(); @@ -59,13 +63,14 @@ export class LicenseComponent implements OnInit { resetForm() { this.formGroup.get('licenseKey')?.setValue(''); this.formGroup.get('email')?.setValue(''); + this.formGroup.get('discordId')?.setValue(''); this.cdRef.markForCheck(); } saveForm() { this.isSaving = true; this.cdRef.markForCheck(); - this.accountService.updateUserLicense(this.formGroup.get('licenseKey')!.value.trim(), this.formGroup.get('email')!.value.trim()) + this.accountService.updateUserLicense(this.formGroup.get('licenseKey')!.value.trim(), this.formGroup.get('email')!.value.trim(), this.formGroup.get('discordId')!.value.trim()) .subscribe(() => { this.accountService.hasValidLicense(true).subscribe(isValid => { this.hasValidLicense = isValid; @@ -81,13 +86,13 @@ export class LicenseComponent implements OnInit { this.cdRef.markForCheck(); }); }, err => { + this.isSaving = false; + this.cdRef.markForCheck(); if (err.hasOwnProperty('error')) { - this.toastr.error(JSON.parse(err['error'])['message']); + this.toastr.error(JSON.parse(err['error'])); } else { this.toastr.error(translate('toasts.k+-error')); } - this.isSaving = false; - this.cdRef.markForCheck(); }); } @@ -101,7 +106,16 @@ export class LicenseComponent implements OnInit { this.toggleViewMode(); this.validateLicense(); }); + } + async resetLicense() { + if (!await this.confirmService.confirm(translate('toasts.k+-reset-key'))) { + return; + } + + this.accountService.resetLicense(this.formGroup.get('licenseKey')!.value.trim(), this.formGroup.get('email')!.value.trim()).subscribe(() => { + this.toastr.success(translate('toasts.k+-reset-key-success')); + }); } diff --git a/UI/Web/src/app/sidenav/_components/side-nav/side-nav.component.ts b/UI/Web/src/app/sidenav/_components/side-nav/side-nav.component.ts index 53eed71e0..bd30c27bd 100644 --- a/UI/Web/src/app/sidenav/_components/side-nav/side-nav.component.ts +++ b/UI/Web/src/app/sidenav/_components/side-nav/side-nav.component.ts @@ -206,6 +206,8 @@ export class SideNavComponent implements OnInit { } showLess() { + this.filterQuery = ''; + this.cdRef.markForCheck(); this.showAllSubject.next(false); } diff --git a/UI/Web/src/assets/langs/en.json b/UI/Web/src/assets/langs/en.json index cb507bcd9..d3c6a9839 100644 --- a/UI/Web/src/assets/langs/en.json +++ b/UI/Web/src/assets/langs/en.json @@ -590,7 +590,11 @@ "activate-description": "Enter the License Key and Email used to register with Stripe", "activate-license-label": "License Key", "activate-email-label": "{{common.email}}", - "activate-delete": "Delete", + "activate-discordId-label": "Discord UserId", + "activate-discordId-tooltip": "Link your Discord Account with Kavita+. This grants you access to hidden channels to help shape Kavita", + "activate-delete": "{{common.delete}}", + "activate-reset": "{{common.reset}}", + "activate-reset--tooltip": "Untie your license with this server. Requires both License and Email.", "activate-save": "{{common.save}}" }, @@ -1955,6 +1959,8 @@ "k+-unlocked": "Kavita+ unlocked!", "k+-error": "There was an error when activating your license. Please try again.", "k+-delete-key": "This will only delete Kavita's license key and allow a buy link to show. This will not cancel your subscription! Use this only if directed by support!", + "k+-reset-key": "This will untie your key from a server and allow you to re-register a Kavita instance.", + "k+-reset-key-success": "Your license has been un-registered. Use Edit button to re-register your instance and re-activate Kavita+", "library-deleted": "Library {{name}} has been removed", "copied-to-clipboard": "Copied to clipboard", "book-settings-info": "You can modify book settings, save those settings for all books, and view table of contents from the drawer.", diff --git a/openapi.json b/openapi.json index 629f4ea01..f81365409 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.7.11.5" + "version": "0.7.11.6" }, "servers": [ { @@ -3074,6 +3074,37 @@ } } }, + "/api/License/reset": { + "post": { + "tags": [ + "License" + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UpdateLicenseDto" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/UpdateLicenseDto" + } + }, + "application/*+json": { + "schema": { + "$ref": "#/components/schemas/UpdateLicenseDto" + } + } + } + }, + "responses": { + "200": { + "description": "Success" + } + } + } + }, "/api/Locale": { "get": { "tags": [ @@ -19097,6 +19128,11 @@ "type": "string", "description": "Email registered with Stripe", "nullable": true + }, + "discordId": { + "type": "string", + "description": "Optional DiscordId", + "nullable": true } }, "additionalProperties": false