mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
Kavita+ Reset License & Discord Integration (#2516)
This commit is contained in:
parent
138794ffed
commit
c37596889a
@ -8,7 +8,6 @@ using API.Entities.Enums;
|
||||
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<LicenseController> logger,
|
||||
ILicenseService licenseService,
|
||||
ILocalizationService localizationService)
|
||||
: BaseApiController
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly ILogger<LicenseController> _logger;
|
||||
private readonly ILicenseService _licenseService;
|
||||
private readonly ILocalizationService _localizationService;
|
||||
|
||||
public LicenseController(IUnitOfWork unitOfWork, ILogger<LicenseController> logger,
|
||||
ILicenseService licenseService, ILocalizationService localizationService)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_logger = logger;
|
||||
_licenseService = licenseService;
|
||||
_localizationService = localizationService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the user's license is valid or not
|
||||
/// </summary>
|
||||
@ -41,7 +31,7 @@ public class LicenseController : BaseApiController
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.LicenseCache)]
|
||||
public async Task<ActionResult<bool>> HasValidLicense(bool forceCheck = false)
|
||||
{
|
||||
return Ok(await _licenseService.HasActiveLicense(forceCheck));
|
||||
return Ok(await licenseService.HasActiveLicense(forceCheck));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -54,7 +44,7 @@ public class LicenseController : BaseApiController
|
||||
public async Task<ActionResult<bool>> 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 class LicenseController : BaseApiController
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.LicenseCache)]
|
||||
public async Task<ActionResult> 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<ActionResult> 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+"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates server license
|
||||
/// </summary>
|
||||
@ -81,11 +81,11 @@ public class LicenseController : BaseApiController
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
||||
|
8
API/DTOs/License/ResetLicenseDto.cs
Normal file
8
API/DTOs/License/ResetLicenseDto.cs
Normal file
@ -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; }
|
||||
}
|
@ -10,4 +10,8 @@ public class UpdateLicenseDto
|
||||
/// Email registered with Stripe
|
||||
/// </summary>
|
||||
public required string Email { get; set; }
|
||||
/// <summary>
|
||||
/// Optional DiscordId
|
||||
/// </summary>
|
||||
public string? DiscordId { get; set; }
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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<bool> HasActiveLicense(bool forceCheck = false);
|
||||
Task<bool> ResetLicense(string license, string email);
|
||||
}
|
||||
|
||||
public class LicenseService : ILicenseService
|
||||
@ -87,7 +88,7 @@ public class LicenseService : ILicenseService
|
||||
/// <param name="license"></param>
|
||||
/// <param name="email"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<string> RegisterLicense(string license, string email)
|
||||
private async Task<string> RegisterLicense(string license, string email, string? discordId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(license) || string.IsNullOrWhiteSpace(email)) return string.Empty;
|
||||
try
|
||||
@ -104,7 +105,8 @@ public class LicenseService : ILicenseService
|
||||
{
|
||||
License = license.Trim(),
|
||||
InstallId = HashUtil.ServerToken(),
|
||||
EmailId = email.Trim()
|
||||
EmailId = email.Trim(),
|
||||
DiscordId = discordId?.Trim()
|
||||
})
|
||||
.ReceiveJson<RegisterLicenseResponseDto>();
|
||||
|
||||
@ -164,10 +166,10 @@ public class LicenseService : ILicenseService
|
||||
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 class LicenseService : ILicenseService
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> 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;
|
||||
}
|
||||
}
|
||||
|
31
README.md
31
README.md
@ -9,7 +9,7 @@ your reading collection with your friends and family!
|
||||
[](https://github.com/Kareadita/Kavita/releases)
|
||||
[](https://github.com/Kareadita/Kavita/blob/master/LICENSE)
|
||||
[](https://github.com/Kareadita/Kavita/releases)
|
||||
[](https://hub.docker.com/r/jvmilazz0/kavita)
|
||||
[](https://hub.docker.com/r/jvmilazz0/kavita)
|
||||
[](https://sonarcloud.io/dashboard?id=Kareadita_Kavita)
|
||||
[](https://sonarcloud.io/dashboard?id=Kareadita_Kavita)
|
||||
[](#backers)
|
||||
@ -35,12 +35,11 @@ your reading collection with your friends and family!
|
||||
|
||||
|
||||
## Support
|
||||
[](https://www.reddit.com/r/KavitaManga/)
|
||||
[](https://discord.gg/eczRp9eeem)
|
||||
[](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.
|
||||
|
||||
<a href="https://hosted.weblate.org/engage/kavita/">
|
||||
<img src="https://hosted.weblate.org/widget/kavita/horizontal-auto.svg" alt="Translation status" />
|
||||
</a>
|
||||
|
||||
## 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 [<img src="/Logo/jetbrains.svg" alt="" width="32"> JetBrains](http:
|
||||
* [<img src="/Logo/rider.svg" alt="" width="32"> Rider](http://www.jetbrains.com/rider/)
|
||||
* [<img src="/Logo/dottrace.svg" alt="" width="32"> 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.
|
||||
|
||||
<a href="https://hosted.weblate.org/engage/kavita/">
|
||||
<img src="https://hosted.weblate.org/widget/kavita/horizontal-auto.svg" alt="Translation status" />
|
||||
</a>
|
||||
|
||||
## 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)
|
||||
|
24
UI/Web/package-lock.json
generated
24
UI/Web/package-lock.json
generated
@ -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"
|
||||
|
@ -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<string>(this.baseUrl + 'license', TextResonse);
|
||||
}
|
||||
|
||||
resetLicense(license: string, email: string) {
|
||||
return this.httpClient.post<string>(this.baseUrl + 'license/reset', {license, email}, TextResonse);
|
||||
}
|
||||
|
||||
hasValidLicense(forceCheck: boolean = false) {
|
||||
return this.httpClient.get<string>(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<string>(this.baseUrl + 'license', {license, email}, TextResonse)
|
||||
updateUserLicense(license: string, email: string, discordId?: string) {
|
||||
return this.httpClient.post<string>(this.baseUrl + 'license', {license, email, discordId}, TextResonse)
|
||||
.pipe(map(res => res === "true"));
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -7,16 +7,15 @@
|
||||
<h4 id="license-key-header">{{t('title')}}</h4>
|
||||
</div>
|
||||
<div class="col-2 text-end">
|
||||
<ng-container *ngIf="hasLicense; else noLicense">
|
||||
<ng-container *ngIf="hasValidLicense; else invalidLicenseBuy">
|
||||
@if (hasLicense) {
|
||||
@if (hasValidLicense) {
|
||||
<a class="btn btn-primary btn-sm me-1" [href]="manageLink" target="_blank" rel="noreferrer nofollow">{{t('manage')}}</a>
|
||||
</ng-container>
|
||||
<ng-template #invalidLicenseBuy>
|
||||
} @else {
|
||||
<a class="btn btn-primary btn-sm me-1"
|
||||
[ngbTooltip]="t('invalid-license-tooltip')"
|
||||
href="mailto:kavitareader@gmail.com?subject=Kavita+Subscription+Renewal&body=Description%3A%0D%0A%0D%0ALicense%20Key%3A%0D%0A%0D%0AYour%20Email%3A"
|
||||
>{{t('renew')}}</a>
|
||||
</ng-template>
|
||||
}
|
||||
<button class="btn btn-secondary btn-sm me-1" style="width: 58px" (click)="validateLicense()">
|
||||
<span *ngIf="!isChecking">{{t('check')}}</span>
|
||||
<app-loading [loading]="isChecking" size="spinner-border-sm"></app-loading>
|
||||
@ -25,16 +24,15 @@
|
||||
<span *ngIf="!isViewMode">{{t('cancel')}}</span>
|
||||
<span *ngIf="isViewMode">{{t('edit')}}</span>
|
||||
</button>
|
||||
</ng-container>
|
||||
<ng-template #noLicense>
|
||||
} @else {
|
||||
<a class="btn btn-secondary btn-sm me-1" [href]="buyLink" target="_blank" rel="noreferrer nofollow">{{t('buy')}}</a>
|
||||
<button class="btn btn-primary btn-sm" (click)="toggleViewMode()">{{isViewMode ? t('activate') : t('cancel')}}</button>
|
||||
</ng-template>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ng-container *ngIf="isViewMode">
|
||||
@if (isViewMode) {
|
||||
<div class="container-fluid row">
|
||||
<span class="col-12">
|
||||
<ng-container *ngIf="hasLicense; else noToken">
|
||||
@ -57,7 +55,8 @@
|
||||
<ng-template #noToken>{{t('no-license-key')}}</ng-template>
|
||||
</span>
|
||||
</div>
|
||||
</ng-container>
|
||||
}
|
||||
|
||||
|
||||
<div #collapse="ngbCollapse" [(ngbCollapse)]="isViewMode">
|
||||
<form [formGroup]="formGroup">
|
||||
@ -70,12 +69,23 @@
|
||||
<label for="email">{{t('activate-email-label')}}</label>
|
||||
<input id="email" type="email" class="form-control" formControlName="email" autocomplete="off"/>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="discordId">{{t('activate-discordId-label')}}</label><i class="fa fa-circle-info ms-1" aria-hidden="true" [ngbTooltip]="t('activate-discordId-tooltip')"></i>
|
||||
<input id="discordId" type="text" class="form-control" formControlName="discordId" autocomplete="off"/>
|
||||
</div>
|
||||
</form>
|
||||
<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-danger me-1" aria-describedby="license-key-header" (click)="deleteLicense()">
|
||||
<button type="button" class="flex-fill btn btn-danger me-1" aria-describedby="license-key-header"
|
||||
(click)="deleteLicense()">
|
||||
{{t('activate-delete')}}
|
||||
</button>
|
||||
<button type="submit" class="flex-fill btn btn-primary" aria-describedby="license-key-header" [disabled]="!formGroup.get('email')?.value || !formGroup.get('licenseKey')?.value" (click)="saveForm()">
|
||||
<button type="button" class="flex-fill btn btn-danger me-1" aria-describedby="license-key-header"
|
||||
[ngbTooltip]="t('activate-reset--tooltip')"
|
||||
[disabled]="!formGroup.get('email')?.value || !formGroup.get('licenseKey')?.value" (click)="resetLicense()">
|
||||
{{t('activate-reset')}}
|
||||
</button>
|
||||
<button type="submit" class="flex-fill btn btn-primary" aria-describedby="license-key-header"
|
||||
[disabled]="!formGroup.get('email')?.value || !formGroup.get('licenseKey')?.value" (click)="saveForm()">
|
||||
<span *ngIf="!isSaving">{{t('activate-save')}}</span>
|
||||
<app-loading [loading]="isSaving" size="spinner-border-sm"></app-loading>
|
||||
</button>
|
||||
|
@ -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'));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -206,6 +206,8 @@ export class SideNavComponent implements OnInit {
|
||||
}
|
||||
|
||||
showLess() {
|
||||
this.filterQuery = '';
|
||||
this.cdRef.markForCheck();
|
||||
this.showAllSubject.next(false);
|
||||
}
|
||||
|
||||
|
@ -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.",
|
||||
|
38
openapi.json
38
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user