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
Account Email Support (#1000)
Joseph Milazzoefb527035de8
diff --git a/.gitignore b/.gitignoreindex 1ee566816..bc03f54c7 100644--- a/.gitignore+++ b/.gitignore@@ -502,6 +502,9 @@ UI/Web/dist//API.Tests/Extensions/Test Data/modified on run.txt# All config files/folders in config except appsettings.json+/API/config-bak/+/API/config-bak/*.*+/API/config-bak/**//API/config/covers//API/config/logs//API/config/backups/diff --git a/API.Benchmark/TestBenchmark.cs b/API.Benchmark/TestBenchmark.csindex 618a8b93c..c5d2d18e1 100644--- a/API.Benchmark/TestBenchmark.cs+++ b/API.Benchmark/TestBenchmark.cs@@ -1,7 +1,6 @@using System;using System.Collections.Generic;using System.Linq;-using API.Comparators;using API.DTOs;using API.Extensions;using BenchmarkDotNet.Attributes;diff --git a/API.Tests/Extensions/SeriesExtensionsTests.cs b/API.Tests/Extensions/SeriesExtensionsTests.csindex fc5b5b8ca..c00ade1e8 100644--- a/API.Tests/Extensions/SeriesExtensionsTests.cs+++ b/API.Tests/Extensions/SeriesExtensionsTests.cs@@ -5,7 +5,6 @@ using API.Entities.Metadata;using API.Extensions;using API.Parser;using API.Services.Tasks.Scanner;-using API.Tests.Helpers;using Xunit;namespace API.Tests.Extensionsdiff --git a/API.Tests/Helpers/CacheHelperTests.cs b/API.Tests/Helpers/CacheHelperTests.csindex 9d1024ff0..723742bc6 100644--- a/API.Tests/Helpers/CacheHelperTests.cs+++ b/API.Tests/Helpers/CacheHelperTests.cs@@ -5,8 +5,6 @@ using System.IO.Abstractions.TestingHelpers;using API.Entities;using API.Helpers;using API.Services;-using Microsoft.Extensions.Logging;-using NSubstitute;using Xunit;namespace API.Tests.Helpers;diff --git a/API.Tests/Helpers/EntityFactory.cs b/API.Tests/Helpers/EntityFactory.csindex 25b807c32..7a9ed79be 100644--- a/API.Tests/Helpers/EntityFactory.cs+++ b/API.Tests/Helpers/EntityFactory.cs@@ -1,5 +1,4 @@-using System;-using System.Collections.Generic;+using System.Collections.Generic;using API.Entities;using API.Entities.Enums;using API.Entities.Metadata;diff --git a/API.Tests/Parser/ComicParserTests.cs b/API.Tests/Parser/ComicParserTests.csindex c2ebc80f2..73f7cede4 100644--- a/API.Tests/Parser/ComicParserTests.cs+++ b/API.Tests/Parser/ComicParserTests.cs@@ -1,6 +1,4 @@-using System.Collections.Generic;using System.IO.Abstractions.TestingHelpers;-using API.Entities.Enums;using API.Parser;using API.Services;using Microsoft.Extensions.Logging;diff --git a/API.Tests/Parser/MangaParserTests.cs b/API.Tests/Parser/MangaParserTests.csindex fe4dd5e42..171e582cb 100644--- a/API.Tests/Parser/MangaParserTests.cs+++ b/API.Tests/Parser/MangaParserTests.cs@@ -1,6 +1,4 @@-using System.Collections.Generic;using API.Entities.Enums;-using API.Parser;using Xunit;using Xunit.Abstractions;diff --git a/API.Tests/Parser/ParserTest.cs b/API.Tests/Parser/ParserTest.csindex 38637c10d..3ac183937 100644--- a/API.Tests/Parser/ParserTest.cs+++ b/API.Tests/Parser/ParserTest.cs@@ -1,5 +1,4 @@using System.Linq;-using API.Entities.Enums;using Xunit;using static API.Parser.Parser;diff --git a/API.Tests/Services/DirectoryServiceTests.cs b/API.Tests/Services/DirectoryServiceTests.csindex bdbb7a238..391b4eac4 100644--- a/API.Tests/Services/DirectoryServiceTests.cs+++ b/API.Tests/Services/DirectoryServiceTests.cs@@ -1,7 +1,6 @@using System;using System.Collections.Generic;using System.IO;-using System.IO.Abstractions;using System.IO.Abstractions.TestingHelpers;using System.Linq;using System.Text;diff --git a/API.Tests/Services/ParseScannedFilesTests.cs b/API.Tests/Services/ParseScannedFilesTests.csindex fd55143a1..bd1174416 100644--- a/API.Tests/Services/ParseScannedFilesTests.cs+++ b/API.Tests/Services/ParseScannedFilesTests.cs@@ -10,10 +10,8 @@ using API.Entities.Enums;using API.Parser;using API.Services;using API.Services.Tasks.Scanner;-using API.SignalR;using API.Tests.Helpers;using AutoMapper;-using Microsoft.AspNetCore.SignalR;using Microsoft.Data.Sqlite;using Microsoft.EntityFrameworkCore;using Microsoft.EntityFrameworkCore.Infrastructure;diff --git a/API.Tests/Services/ReaderServiceTests.cs b/API.Tests/Services/ReaderServiceTests.csindex 232a93c4e..75cfaf73f 100644--- a/API.Tests/Services/ReaderServiceTests.cs+++ b/API.Tests/Services/ReaderServiceTests.cs@@ -1,6 +1,5 @@using System.Collections.Generic;using System.Data.Common;-using System.IO;using System.IO.Abstractions.TestingHelpers;using System.Linq;using System.Threading.Tasks;@@ -153,9 +152,8 @@ public class ReaderServiceTestsawait _context.SaveChangesAsync();var fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());Assert.Equal(0, await readerService.CapPageToChapter(1, -1));Assert.Equal(1, await readerService.CapPageToChapter(1, 10));@@ -200,9 +198,8 @@ public class ReaderServiceTestsawait _context.SaveChangesAsync();var fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());var successful = await readerService.SaveReadingProgress(new ProgressDto(){@@ -252,9 +249,8 @@ public class ReaderServiceTestsawait _context.SaveChangesAsync();var fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());var successful = await readerService.SaveReadingProgress(new ProgressDto(){@@ -325,9 +321,8 @@ public class ReaderServiceTestsawait _context.SaveChangesAsync();var fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());var volumes = await _unitOfWork.VolumeRepository.GetVolumes(1);readerService.MarkChaptersAsRead(await _unitOfWork.UserRepository.GetUserByIdAsync(1, AppUserIncludes.Progress), 1, volumes.First().Chapters);@@ -379,8 +374,7 @@ public class ReaderServiceTestsvar fileSystem = new MockFileSystem();var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);+ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());var volumes = (await _unitOfWork.VolumeRepository.GetVolumes(1)).ToList();readerService.MarkChaptersAsRead(await _unitOfWork.UserRepository.GetUserByIdAsync(1, AppUserIncludes.Progress), 1, volumes.First().Chapters);@@ -441,9 +435,8 @@ public class ReaderServiceTestsawait _context.SaveChangesAsync();var fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());var nextChapter = await readerService.GetNextChapterIdAsync(1, 1, 1, 1);var actualChapter = await _unitOfWork.ChapterRepository.GetChapterAsync(nextChapter);@@ -490,9 +483,8 @@ public class ReaderServiceTestsawait _context.SaveChangesAsync();var fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());var nextChapter = await readerService.GetNextChapterIdAsync(1, 1, 2, 1);@@ -535,9 +527,8 @@ public class ReaderServiceTestsawait _context.SaveChangesAsync();var fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());var nextChapter = await readerService.GetNextChapterIdAsync(1, 1, 2, 1);@@ -579,9 +570,8 @@ public class ReaderServiceTestsawait _context.SaveChangesAsync();var fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());var nextChapter = await readerService.GetNextChapterIdAsync(1, 2, 3, 1);@@ -635,9 +625,8 @@ public class ReaderServiceTestsawait _context.SaveChangesAsync();var fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());var prevChapter = await readerService.GetPrevChapterIdAsync(1, 1, 2, 1);var actualChapter = await _unitOfWork.ChapterRepository.GetChapterAsync(prevChapter);@@ -684,9 +673,8 @@ public class ReaderServiceTestsawait _context.SaveChangesAsync();var fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());var prevChapter = await readerService.GetPrevChapterIdAsync(1, 2, 3, 1);@@ -729,9 +717,8 @@ public class ReaderServiceTestsawait _context.SaveChangesAsync();var fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());var prevChapter = await readerService.GetPrevChapterIdAsync(1, 1, 1, 1);@@ -775,9 +762,8 @@ public class ReaderServiceTestsawait _context.SaveChangesAsync();var fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());var prevChapter = await readerService.GetPrevChapterIdAsync(1, 2, 4, 1);@@ -830,9 +816,8 @@ public class ReaderServiceTestsvar fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());// Save progress on first volume chapters and 1st of second volumeawait readerService.SaveReadingProgress(new ProgressDto()@@ -905,9 +890,8 @@ public class ReaderServiceTestsvar fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());// Save progress on first volume chapters and 1st of second volumeawait readerService.SaveReadingProgress(new ProgressDto()@@ -973,9 +957,8 @@ public class ReaderServiceTestsvar fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());// Save progress on first volume chapters and 1st of second volumeawait readerService.SaveReadingProgress(new ProgressDto()@@ -1038,9 +1021,8 @@ public class ReaderServiceTestsvar fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());// Save progress on first volume chapters and 1st of second volumeawait readerService.SaveReadingProgress(new ProgressDto()@@ -1104,9 +1086,8 @@ public class ReaderServiceTestsvar fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());// Save progress on first volume chapters and 1st of second volumeawait readerService.SaveReadingProgress(new ProgressDto()@@ -1174,9 +1155,8 @@ public class ReaderServiceTestsvar fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync("majora2007", AppUserIncludes.Progress);await readerService.MarkChaptersUntilAsRead(user, 1, 5);@@ -1222,9 +1202,8 @@ public class ReaderServiceTestsvar fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync("majora2007", AppUserIncludes.Progress);await readerService.MarkChaptersUntilAsRead(user, 1, 2.5f);@@ -1271,9 +1250,8 @@ public class ReaderServiceTestsvar fileSystem = new MockFileSystem();- var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);- var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));- var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync("majora2007", AppUserIncludes.Progress);await readerService.MarkChaptersUntilAsRead(user, 1, 2);diff --git a/API.Tests/Services/ScannerServiceTests.cs b/API.Tests/Services/ScannerServiceTests.csindex b78c6be35..280fe5c10 100644--- a/API.Tests/Services/ScannerServiceTests.cs+++ b/API.Tests/Services/ScannerServiceTests.cs@@ -1,29 +1,12 @@-using System;-using System.Collections.Concurrent;-using System.Collections.Generic;-using System.Data.Common;-using System.IO;-using System.IO.Abstractions.TestingHelpers;+using System.Collections.Generic;using System.Linq;-using System.Threading.Tasks;-using API.Data;using API.Entities;using API.Entities.Enums;using API.Entities.Metadata;-using API.Helpers;using API.Parser;-using API.Services;using API.Services.Tasks;using API.Services.Tasks.Scanner;-using API.SignalR;using API.Tests.Helpers;-using AutoMapper;-using Microsoft.AspNetCore.SignalR;-using Microsoft.Data.Sqlite;-using Microsoft.EntityFrameworkCore;-using Microsoft.EntityFrameworkCore.Infrastructure;-using Microsoft.Extensions.Logging;-using NSubstitute;using Xunit;namespace API.Tests.Servicesdiff --git a/API/Constants/PolicyConstants.cs b/API/Constants/PolicyConstants.csindex 389a87eee..cbcd05872 100644--- a/API/Constants/PolicyConstants.cs+++ b/API/Constants/PolicyConstants.cs@@ -1,4 +1,7 @@-namespace API.Constants+using System.Collections.Generic;+using System.Collections.Immutable;++namespace API.Constants{/// <summary>/// Role-based Security@@ -17,5 +20,10 @@/// Used to give a user ability to download files from the server/// </summary>public const string DownloadRole = "Download";++ public static readonly ImmutableArray<string> ValidRoles = new ImmutableArray<string>()+ {+ AdminRole, PlebRole, DownloadRole+ };}}diff --git a/API/Controllers/AccountController.cs b/API/Controllers/AccountController.csindex cfc3a1c7a..ada167f1a 100644--- a/API/Controllers/AccountController.cs+++ b/API/Controllers/AccountController.cs@@ -1,20 +1,30 @@using System;using System.Collections.Generic;using System.Linq;+using System.Net;+using System.Net.Sockets;using System.Reflection;using System.Threading.Tasks;+using System.Web;using API.Constants;using API.Data;+using API.Data.Repositories;using API.DTOs;using API.DTOs.Account;+using API.DTOs.Email;using API.Entities;+using API.Errors;using API.Extensions;using API.Services;using AutoMapper;+using AutoMapper.QueryableExtensions;+using Flurl.Util;using Kavita.Common;+using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Identity;using Microsoft.AspNetCore.Mvc;using Microsoft.EntityFrameworkCore;+using Microsoft.Extensions.Hosting;using Microsoft.Extensions.Logging;namespace API.Controllers@@ -31,13 +41,15 @@ namespace API.Controllersprivate readonly ILogger<AccountController> _logger;private readonly IMapper _mapper;private readonly IAccountService _accountService;+ private readonly IEmailService _emailService;+ private readonly IHostEnvironment _environment;/// <inheritdoc />public AccountController(UserManager<AppUser> userManager,SignInManager<AppUser> signInManager,ITokenService tokenService, IUnitOfWork unitOfWork,ILogger<AccountController> logger,- IMapper mapper, IAccountService accountService)+ IMapper mapper, IAccountService accountService, IEmailService emailService, IHostEnvironment environment){_userManager = userManager;_signInManager = signInManager;@@ -46,6 +58,8 @@ namespace API.Controllers_logger = logger;_mapper = mapper;_accountService = accountService;+ _emailService = emailService;+ _environment = environment;}/// <summary>@@ -73,71 +87,71 @@ namespace API.Controllers}/// <summary>- /// Register a new user on the server+ /// Register the first user (admin) on the server. Will not do anything if an admin is already confirmed/// </summary>/// <param name="registerDto"></param>/// <returns></returns>[HttpPost("register")]- public async Task<ActionResult<UserDto>> Register(RegisterDto registerDto)+ public async Task<ActionResult<UserDto>> RegisterFirstUser(RegisterDto registerDto){+ var admins = await _userManager.GetUsersInRoleAsync("Admin");+ if (admins.Count > 0) return BadRequest("Not allowed");+try{- if (await _userManager.Users.AnyAsync(x => x.NormalizedUserName == registerDto.Username.ToUpper()))+ var usernameValidation = await _accountService.ValidateUsername(registerDto.Username);+ if (usernameValidation.Any()){- return BadRequest("Username is taken.");+ return BadRequest(usernameValidation);}- // If we are registering an admin account, ensure there are no existing admins or user registering is an admin- if (registerDto.IsAdmin)+ var user = new AppUser(){- var firstTimeFlow = !(await _userManager.GetUsersInRoleAsync("Admin")).Any();- if (!firstTimeFlow && !await _unitOfWork.UserRepository.IsUserAdminAsync(- await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername())))- {- return BadRequest("You are not permitted to create an admin account");- }- }-- var user = _mapper.Map<AppUser>(registerDto);- user.UserPreferences ??= new AppUserPreferences();- user.ApiKey = HashUtil.ApiKey();+ UserName = registerDto.Username,+ Email = registerDto.Email,+ UserPreferences = new AppUserPreferences(),+ ApiKey = HashUtil.ApiKey()+ };- var settings = await _unitOfWork.SettingsRepository.GetSettingsDtoAsync();- if (!settings.EnableAuthentication && !registerDto.IsAdmin)- {- _logger.LogInformation("User {UserName} is being registered as non-admin with no server authentication. Using default password", registerDto.Username);- registerDto.Password = AccountService.DefaultPassword;- }+ // I am removing Authentication disabled code+ // var settings = await _unitOfWork.SettingsRepository.GetSettingsDtoAsync();+ // if (!settings.EnableAuthentication && !registerDto.IsAdmin)+ // {+ // _logger.LogInformation("User {UserName} is being registered as non-admin with no server authentication. Using default password", registerDto.Username);+ // registerDto.Password = AccountService.DefaultPassword;+ // }var result = await _userManager.CreateAsync(user, registerDto.Password);-if (!result.Succeeded) return BadRequest(result.Errors);+ var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);+ if (string.IsNullOrEmpty(token)) return BadRequest("There was an issue generating a confirmation token.");+ if (!await ConfirmEmailToken(token, user)) return BadRequest($"There was an issue validating your email: {token}");- var role = registerDto.IsAdmin ? PolicyConstants.AdminRole : PolicyConstants.PlebRole;- var roleResult = await _userManager.AddToRoleAsync(user, role);+ var roleResult = await _userManager.AddToRoleAsync(user, PolicyConstants.AdminRole);if (!roleResult.Succeeded) return BadRequest(result.Errors);- // When we register an admin, we need to grant them access to all Libraries.- if (registerDto.IsAdmin)- {- _logger.LogInformation("{UserName} is being registered as admin. Granting access to all libraries",- user.UserName);- var libraries = (await _unitOfWork.LibraryRepository.GetLibrariesAsync()).ToList();- foreach (var lib in libraries)- {- lib.AppUsers ??= new List<AppUser>();- lib.AppUsers.Add(user);- }-- if (libraries.Any() && !await _unitOfWork.CommitAsync())- _logger.LogError("There was an issue granting library access. Please do this manually");- }+ // // When we register an admin, we need to grant them access to all Libraries.+ // if (registerDto.IsAdmin)+ // {+ // _logger.LogInformation("{UserName} is being registered as admin. Granting access to all libraries",+ // user.UserName);+ // var libraries = (await _unitOfWork.LibraryRepository.GetLibrariesAsync()).ToList();+ // foreach (var lib in libraries)+ // {+ // lib.AppUsers ??= new List<AppUser>();+ // lib.AppUsers.Add(user);+ // }+ //+ // if (libraries.Any() && !await _unitOfWork.CommitAsync())+ // _logger.LogError("There was an issue granting library access. Please do this manually");+ // }return new UserDto{Username = user.UserName,+ Email = user.Email,Token = await _tokenService.CreateToken(user),RefreshToken = await _tokenService.CreateRefreshToken(user),ApiKey = user.ApiKey,@@ -153,6 +167,7 @@ namespace API.Controllersreturn BadRequest("Something went wrong when registering user");}+/// <summary>/// Perform a login. Will send JWT Token of the logged in user back./// </summary>@@ -167,6 +182,15 @@ namespace API.Controllersif (user == null) return Unauthorized("Invalid username");+ // Check if the user has an email, if not, inform them so they can migrate+ var validPassword = await _signInManager.UserManager.CheckPasswordAsync(user, loginDto.Password);+ if (string.IsNullOrEmpty(user.Email) && !user.EmailConfirmed && validPassword)+ {+ _logger.LogCritical("User {UserName} does not have an email. Providing a one time migration", user.UserName);+ return Unauthorized(+ "You are missing an email on your account. Please wait while we migrate your account.");+ }+var isAdmin = await _unitOfWork.UserRepository.IsUserAdminAsync(user);var settings = await _unitOfWork.SettingsRepository.GetSettingsDtoAsync();if (!settings.EnableAuthentication && !isAdmin)@@ -178,7 +202,10 @@ namespace API.Controllersvar result = await _signInManager.CheckPasswordSignInAsync(user, loginDto.Password, false);- if (!result.Succeeded) return Unauthorized("Your credentials are not correct.");+ if (!result.Succeeded)+ {+ return Unauthorized(result.IsNotAllowed ? "You must confirm your email first" : "Your credentials are not correct.");+ }// Update LastActive on accountuser.LastActive = DateTime.Now;@@ -192,6 +219,7 @@ namespace API.Controllersreturn new UserDto{Username = user.UserName,+ Email = user.Email,Token = await _tokenService.CreateToken(user),RefreshToken = await _tokenService.CreateRefreshToken(user),ApiKey = user.ApiKey,@@ -285,5 +313,366 @@ namespace API.Controllersreturn BadRequest("Something went wrong, unable to reset key");}++ /// <summary>+ /// Update the user account. This can only affect Username, Email (will require confirming), Roles, and Library access.+ /// </summary>+ /// <param name="dto"></param>+ /// <returns></returns>+ [Authorize(Policy = "RequireAdminRole")]+ [HttpPost("update")]+ public async Task<ActionResult> UpdateAccount(UpdateUserDto dto)+ {+ var adminUser = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());+ if (!await _unitOfWork.UserRepository.IsUserAdminAsync(adminUser)) return Unauthorized("You do not have permission");++ var user = await _unitOfWork.UserRepository.GetUserByIdAsync(dto.UserId);+ if (user == null) return BadRequest("User does not exist");++ // Check if username is changing+ if (!user.UserName.Equals(dto.Username))+ {+ // Validate username change+ var errors = await _accountService.ValidateUsername(dto.Username);+ if (errors.Any()) return BadRequest("Username already taken");+ user.UserName = dto.Username;+ _unitOfWork.UserRepository.Update(user);+ }++ if (!user.Email.Equals(dto.Email))+ {+ // Validate username change+ var errors = await _accountService.ValidateEmail(dto.Email);+ if (errors.Any()) return BadRequest("Email already registered");+ // NOTE: This needs to be handled differently, like save it in a temp variable in DB until email is validated. For now, I wont allow it+ }++ // Update roles+ var existingRoles = await _userManager.GetRolesAsync(user);+ var hasAdminRole = dto.Roles.Contains(PolicyConstants.AdminRole);+ if (!hasAdminRole)+ {+ dto.Roles.Add(PolicyConstants.PlebRole);+ }+ if (existingRoles.Except(dto.Roles).Any())+ {+ var roles = dto.Roles;++ var roleResult = await _userManager.RemoveFromRolesAsync(user, existingRoles);+ if (!roleResult.Succeeded) return BadRequest(roleResult.Errors);+ roleResult = await _userManager.AddToRolesAsync(user, roles);+ if (!roleResult.Succeeded) return BadRequest(roleResult.Errors);+ }+++ var allLibraries = (await _unitOfWork.LibraryRepository.GetLibrariesAsync()).ToList();+ List<Library> libraries;+ if (hasAdminRole)+ {+ _logger.LogInformation("{UserName} is being registered as admin. Granting access to all libraries",+ user.UserName);+ libraries = allLibraries;+ }+ else+ {+ // Remove user from all libraries+ foreach (var lib in allLibraries)+ {+ lib.AppUsers ??= new List<AppUser>();+ lib.AppUsers.Remove(user);+ }++ libraries = (await _unitOfWork.LibraryRepository.GetLibraryForIdsAsync(dto.Libraries)).ToList();+ }++ foreach (var lib in libraries)+ {+ lib.AppUsers ??= new List<AppUser>();+ lib.AppUsers.Add(user);+ }++ if (!_unitOfWork.HasChanges()) return Ok();+ if (await _unitOfWork.CommitAsync())+ {+ return Ok();+ }++ await _unitOfWork.RollbackAsync();+ return BadRequest("There was an exception when updating the user");+ }+++ [Authorize(Policy = "RequireAdminRole")]+ [HttpPost("invite")]+ public async Task<ActionResult<string>> InviteUser(InviteUserDto dto)+ {+ var adminUser = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());+ _logger.LogInformation("{User} is inviting {Email} to the server", adminUser.UserName, dto.Email);++ // Check if there is an existing invite+ var emailValidationErrors = await _accountService.ValidateEmail(dto.Email);+ if (emailValidationErrors.Any())+ {+ var invitedUser = await _unitOfWork.UserRepository.GetUserByEmailAsync(dto.Email);+ if (await _userManager.IsEmailConfirmedAsync(invitedUser))+ return BadRequest($"User is already registered as {invitedUser.UserName}");+ return BadRequest("User is already invited under this email and has yet to accepted invite.");+ }++ // Create a new user+ var user = new AppUser()+ {+ UserName = dto.Email,+ Email = dto.Email,+ ApiKey = HashUtil.ApiKey(),+ UserPreferences = new AppUserPreferences()+ };++ try+ {+ var result = await _userManager.CreateAsync(user, AccountService.DefaultPassword);+ if (!result.Succeeded) return BadRequest(result.Errors);++ // Assign Roles+ var roles = dto.Roles;+ var hasAdminRole = dto.Roles.Contains(PolicyConstants.AdminRole);+ if (!hasAdminRole)+ {+ roles.Add(PolicyConstants.PlebRole);+ }++ foreach (var role in roles)+ {+ if (!PolicyConstants.ValidRoles.Contains(role)) continue;+ var roleResult = await _userManager.AddToRoleAsync(user, role);+ if (!roleResult.Succeeded)+ return+ BadRequest(roleResult.Errors); // TODO: Combine all these return BadRequest into one big thing+ }++ // Grant access to libraries+ List<Library> libraries;+ if (hasAdminRole)+ {+ _logger.LogInformation("{UserName} is being registered as admin. Granting access to all libraries",+ user.UserName);+ libraries = (await _unitOfWork.LibraryRepository.GetLibrariesAsync()).ToList();+ }+ else+ {+ libraries = (await _unitOfWork.LibraryRepository.GetLibraryForIdsAsync(dto.Libraries)).ToList();+ }++ foreach (var lib in libraries)+ {+ lib.AppUsers ??= new List<AppUser>();+ lib.AppUsers.Add(user);+ }++ await _unitOfWork.CommitAsync();+++ var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);+ if (string.IsNullOrEmpty(token)) return BadRequest("There was an issue sending email");++ var host = _environment.IsDevelopment() ? "localhost:4200" : Request.Host.ToString();+ var emailLink =+ $"{Request.Scheme}://{host}{Request.PathBase}/registration/confirm-email?token={HttpUtility.UrlEncode(token)}&email={HttpUtility.UrlEncode(dto.Email)}";+ _logger.LogInformation("[Invite User]: Email Link: {Link}", emailLink);+ if (dto.SendEmail)+ {+ await _emailService.SendConfirmationEmail(new ConfirmationEmailDto()+ {+ EmailAddress = dto.Email,+ InvitingUser = adminUser.UserName,+ ServerConfirmationLink = emailLink+ });+ }+ return Ok(emailLink);+ }+ catch (Exception ex)+ {+ _unitOfWork.UserRepository.Delete(user);+ await _unitOfWork.CommitAsync();+ }++ return BadRequest("There was an error setting up your account. Please check the logs");+ }++ [HttpPost("confirm-email")]+ public async Task<ActionResult<UserDto>> ConfirmEmail(ConfirmEmailDto dto)+ {+ var user = await _unitOfWork.UserRepository.GetUserByEmailAsync(dto.Email);++ // Validate Password and Username+ var validationErrors = new List<ApiException>();+ validationErrors.AddRange(await _accountService.ValidateUsername(dto.Username));+ validationErrors.AddRange(await _accountService.ValidatePassword(user, dto.Password));++ if (validationErrors.Any())+ {+ return BadRequest(validationErrors);+ }+++ if (!await ConfirmEmailToken(dto.Token, user)) return BadRequest("Invalid Email Token");++ user.UserName = dto.Username;+ var errors = await _accountService.ChangeUserPassword(user, dto.Password);+ if (errors.Any())+ {+ return BadRequest(errors);+ }+ await _unitOfWork.CommitAsync();+++ user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(user.UserName,+ AppUserIncludes.UserPreferences);++ // Perform Login code+ return new UserDto+ {+ Username = user.UserName,+ Email = user.Email,+ Token = await _tokenService.CreateToken(user),+ RefreshToken = await _tokenService.CreateRefreshToken(user),+ ApiKey = user.ApiKey,+ Preferences = _mapper.Map<UserPreferencesDto>(user.UserPreferences)+ };+ }++ [AllowAnonymous]+ [HttpPost("confirm-migration-email")]+ public async Task<ActionResult<UserDto>> ConfirmMigrationEmail(ConfirmMigrationEmailDto dto)+ {+ var user = await _unitOfWork.UserRepository.GetUserByEmailAsync(dto.Email);+ if (user == null) return Unauthorized("This email is not on system");++ if (!await ConfirmEmailToken(dto.Token, user)) return BadRequest("Invalid Email Token");++ await _unitOfWork.CommitAsync();++ user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(user.UserName,+ AppUserIncludes.UserPreferences);++ // Perform Login code+ return new UserDto+ {+ Username = user.UserName,+ Email = user.Email,+ Token = await _tokenService.CreateToken(user),+ RefreshToken = await _tokenService.CreateRefreshToken(user),+ ApiKey = user.ApiKey,+ Preferences = _mapper.Map<UserPreferencesDto>(user.UserPreferences)+ };+ }++ [HttpPost("resend-confirmation-email")]+ public async Task<ActionResult<string>> ResendConfirmationSendEmail([FromQuery] int userId)+ {+ var user = await _unitOfWork.UserRepository.GetUserByIdAsync(userId);+ if (user == null) return BadRequest("User does not exist");++ if (string.IsNullOrEmpty(user.Email))+ return BadRequest(+ "This user needs to migrate. Have them log out and login to trigger a migration flow");+ if (user.EmailConfirmed) return BadRequest("User already confirmed");++ var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);+ var host = _environment.IsDevelopment() ? "localhost:4200" : Request.Host.ToString();+ var emailLink =+ $"{Request.Scheme}://{host}{Request.PathBase}/registration/confirm-migration-email?token={HttpUtility.UrlEncode(token)}&email={HttpUtility.UrlEncode(user.Email)}";+ _logger.LogInformation("[Email Migration]: Email Link: {Link}", emailLink);+ await _emailService.SendMigrationEmail(new EmailMigrationDto()+ {+ EmailAddress = user.Email,+ Username = user.UserName,+ ServerConfirmationLink = emailLink+ });+++ return Ok(emailLink);+ }++ /// <summary>+ /// This is similar to invite. Essentially we authenticate the user's password then go through invite email flow+ /// </summary>+ /// <param name="dto"></param>+ /// <returns></returns>+ [AllowAnonymous]+ [HttpPost("migrate-email")]+ public async Task<ActionResult<string>> MigrateEmail(MigrateUserEmailDto dto)+ {+ // Check if there is an existing invite+ var emailValidationErrors = await _accountService.ValidateEmail(dto.Email);+ if (emailValidationErrors.Any())+ {+ var invitedUser = await _unitOfWork.UserRepository.GetUserByEmailAsync(dto.Email);+ if (await _userManager.IsEmailConfirmedAsync(invitedUser))+ return BadRequest($"User is already registered as {invitedUser.UserName}");+ return BadRequest("User is already invited under this email and has yet to accepted invite.");+ }+++ var user = await _userManager.Users+ .Include(u => u.UserPreferences)+ .SingleOrDefaultAsync(x => x.NormalizedUserName == dto.Username.ToUpper());+ if (user == null) return Unauthorized("Invalid username");++ var validPassword = await _signInManager.UserManager.CheckPasswordAsync(user, dto.Password);+ if (!validPassword) return Unauthorized("Your credentials are not correct");++ try+ {+ var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);+ if (string.IsNullOrEmpty(token)) return BadRequest("There was an issue sending email");+ user.Email = dto.Email;+ _unitOfWork.UserRepository.Update(user);+ await _unitOfWork.CommitAsync();++ var host = _environment.IsDevelopment() ? "localhost:4200" : Request.Host.ToString();+ var emailLink =+ $"{Request.Scheme}://{host}{Request.PathBase}/registration/confirm-migration-email?token={HttpUtility.UrlEncode(token)}&email={HttpUtility.UrlEncode(dto.Email)}";+ _logger.LogInformation("[Email Migration]: Email Link: {Link}", emailLink);+ if (dto.SendEmail)+ {+ await _emailService.SendMigrationEmail(new EmailMigrationDto()+ {+ EmailAddress = dto.Email,+ Username = user.UserName,+ ServerConfirmationLink = emailLink+ });+ }+ return Ok(emailLink);+ }+ catch (Exception ex)+ {+ _logger.LogError(ex, "There was an issue during email migration. Contact support");+ _unitOfWork.UserRepository.Delete(user);+ await _unitOfWork.CommitAsync();+ }++ return BadRequest("There was an error setting up your account. Please check the logs");+ }++ private async Task<bool> ConfirmEmailToken(string token, AppUser user)+ {+ var result = await _userManager.ConfirmEmailAsync(user, token);+ if (!result.Succeeded)+ {+ _logger.LogCritical("Email validation failed");+ if (result.Errors.Any())+ {+ foreach (var error in result.Errors)+ {+ _logger.LogCritical("Email validation error: {Message}", error.Description);+ }+ }++ return false;+ }++ return true;+ }}}diff --git a/API/Controllers/BookController.cs b/API/Controllers/BookController.csindex 473640df7..2bca8bb2f 100644--- a/API/Controllers/BookController.cs+++ b/API/Controllers/BookController.cs@@ -10,7 +10,6 @@ using API.Extensions;using API.Services;using HtmlAgilityPack;using Microsoft.AspNetCore.Mvc;-using Microsoft.Extensions.Hosting;using Microsoft.Extensions.Logging;using VersOne.Epub;diff --git a/API/Controllers/DownloadController.cs b/API/Controllers/DownloadController.csindex 09388d3af..b840c0cbb 100644--- a/API/Controllers/DownloadController.cs+++ b/API/Controllers/DownloadController.cs@@ -3,7 +3,6 @@ using System.Collections.Generic;using System.IO;using System.Linq;using System.Threading.Tasks;-using API.Comparators;using API.Constants;using API.Data;using API.DTOs.Downloads;diff --git a/API/Controllers/SeriesController.cs b/API/Controllers/SeriesController.csindex e3f75332c..e39ea1fd2 100644--- a/API/Controllers/SeriesController.cs+++ b/API/Controllers/SeriesController.cs@@ -3,7 +3,6 @@ using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using API.Data;-using API.Data.Metadata;using API.Data.Repositories;using API.DTOs;using API.DTOs.Filtering;diff --git a/API/Controllers/ServerController.cs b/API/Controllers/ServerController.csindex 45fb22ce5..0f2124d06 100644--- a/API/Controllers/ServerController.cs+++ b/API/Controllers/ServerController.cs@@ -1,6 +1,7 @@using System;using System.Collections.Generic;using System.IO;+using System.Net.NetworkInformation;using System.Threading.Tasks;using API.DTOs.Stats;using API.DTOs.Update;@@ -28,10 +29,11 @@ namespace API.Controllersprivate readonly IVersionUpdaterService _versionUpdaterService;private readonly IStatsService _statsService;private readonly ICleanupService _cleanupService;+ private readonly IEmailService _emailService;public ServerController(IHostApplicationLifetime applicationLifetime, ILogger<ServerController> logger, IConfiguration config,IBackupService backupService, IArchiveService archiveService, ICacheService cacheService,- IVersionUpdaterService versionUpdaterService, IStatsService statsService, ICleanupService cleanupService)+ IVersionUpdaterService versionUpdaterService, IStatsService statsService, ICleanupService cleanupService, IEmailService emailService){_applicationLifetime = applicationLifetime;_logger = logger;@@ -42,6 +44,7 @@ namespace API.Controllers_versionUpdaterService = versionUpdaterService;_statsService = statsService;_cleanupService = cleanupService;+ _emailService = emailService;}/// <summary>@@ -119,5 +122,16 @@ namespace API.Controllers{return Ok(await _versionUpdaterService.GetAllReleases());}++ /// <summary>+ /// Is this server accessible to the outside net+ /// </summary>+ /// <returns></returns>+ [HttpGet("accessible")]+ [AllowAnonymous]+ public async Task<ActionResult<bool>> IsServerAccessible()+ {+ return await _emailService.CheckIfAccessible(Request.Host.ToString());+ }}}diff --git a/API/Controllers/UsersController.cs b/API/Controllers/UsersController.csindex 7662fdf95..2f469309e 100644--- a/API/Controllers/UsersController.cs+++ b/API/Controllers/UsersController.cs@@ -36,19 +36,29 @@ namespace API.Controllers[HttpGet]public async Task<ActionResult<IEnumerable<MemberDto>>> GetUsers(){- return Ok(await _unitOfWork.UserRepository.GetMembersAsync());+ return Ok(await _unitOfWork.UserRepository.GetEmailConfirmedMemberDtosAsync());}+ [Authorize(Policy = "RequireAdminRole")]+ [HttpGet("pending")]+ public async Task<ActionResult<IEnumerable<MemberDto>>> GetPendingUsers()+ {+ return Ok(await _unitOfWork.UserRepository.GetPendingMemberDtosAsync());+ }+++[AllowAnonymous][HttpGet("names")]public async Task<ActionResult<IEnumerable<MemberDto>>> GetUserNames(){+ // This is only for disabled auth flow - being removedvar setting = await _unitOfWork.SettingsRepository.GetSettingsDtoAsync();if (setting.EnableAuthentication){return Unauthorized("This API cannot be used given your server's configuration");}- var members = await _unitOfWork.UserRepository.GetMembersAsync();+ var members = await _unitOfWork.UserRepository.GetEmailConfirmedMemberDtosAsync();return Ok(members.Select(m => m.Username));}@@ -94,5 +104,6 @@ namespace API.Controllersreturn BadRequest("There was an issue saving preferences.");}+}}diff --git a/API/DTOs/Account/ConfirmEmailDto.cs b/API/DTOs/Account/ConfirmEmailDto.csnew file mode 100644index 000000000..225835796--- /dev/null+++ b/API/DTOs/Account/ConfirmEmailDto.cs@@ -0,0 +1,16 @@+using System.ComponentModel.DataAnnotations;++namespace API.DTOs.Account;++public class ConfirmEmailDto+{+ [Required]+ public string Email { get; set; }+ [Required]+ public string Token { get; set; }+ [Required]+ [StringLength(32, MinimumLength = 6)]+ public string Password { get; set; }+ [Required]+ public string Username { get; set; }+}diff --git a/API/DTOs/Account/ConfirmMigrationEmailDto.cs b/API/DTOs/Account/ConfirmMigrationEmailDto.csnew file mode 100644index 000000000..07e0aa1ca--- /dev/null+++ b/API/DTOs/Account/ConfirmMigrationEmailDto.cs@@ -0,0 +1,7 @@+namespace API.DTOs.Account;++public class ConfirmMigrationEmailDto+{+ public string Email { get; set; }+ public string Token { get; set; }+}diff --git a/API/DTOs/Account/InviteUserDto.cs b/API/DTOs/Account/InviteUserDto.csnew file mode 100644index 000000000..04c9c1103--- /dev/null+++ b/API/DTOs/Account/InviteUserDto.cs@@ -0,0 +1,21 @@+using System.Collections.Generic;+using System.ComponentModel.DataAnnotations;++namespace API.DTOs.Account;++public class InviteUserDto+{+ [Required]+ public string Email { get; init; }+ /// <summary>+ /// List of Roles to assign to user. If admin not present, Pleb will be applied.+ /// If admin present, all libraries will be granted access and will ignore those from DTO.+ /// </summary>+ public ICollection<string> Roles { get; init; }+ /// <summary>+ /// A list of libraries to grant access to+ /// </summary>+ public IList<int> Libraries { get; init; }++ public bool SendEmail { get; init; } = true;+}diff --git a/API/DTOs/Account/MigrateUserEmailDto.cs b/API/DTOs/Account/MigrateUserEmailDto.csnew file mode 100644index 000000000..ec684a9be--- /dev/null+++ b/API/DTOs/Account/MigrateUserEmailDto.cs@@ -0,0 +1,11 @@+using System.ComponentModel.DataAnnotations;++namespace API.DTOs.Account;++public class MigrateUserEmailDto+{+ public string Email { get; set; }+ public string Username { get; set; }+ public string Password { get; set; }+ public bool SendEmail { get; set; }+}diff --git a/API/DTOs/Account/UpdateUserDto.cs b/API/DTOs/Account/UpdateUserDto.csnew file mode 100644index 000000000..f3afb98a5--- /dev/null+++ b/API/DTOs/Account/UpdateUserDto.cs@@ -0,0 +1,23 @@+using System.Collections.Generic;++namespace API.DTOs.Account;++public record UpdateUserDto+{+ public int UserId { get; set; }+ public string Username { get; set; }+ /// <summary>+ /// This field will not result in any change to the User model. Changing email is not supported.+ /// </summary>+ public string Email { get; set; }+ /// <summary>+ /// List of Roles to assign to user. If admin not present, Pleb will be applied.+ /// If admin present, all libraries will be granted access and will ignore those from DTO.+ /// </summary>+ public IList<string> Roles { get; init; }+ /// <summary>+ /// A list of libraries to grant access to+ /// </summary>+ public IList<int> Libraries { get; init; }++}diff --git a/API/DTOs/ChapterDto.cs b/API/DTOs/ChapterDto.csindex 6a4effe16..10956b529 100644--- a/API/DTOs/ChapterDto.cs+++ b/API/DTOs/ChapterDto.cs@@ -1,7 +1,6 @@using System;using System.Collections.Generic;using API.DTOs.Metadata;-using API.Entities;namespace API.DTOs{diff --git a/API/DTOs/Email/ConfirmationEmailDto.cs b/API/DTOs/Email/ConfirmationEmailDto.csnew file mode 100644index 000000000..1754ece22--- /dev/null+++ b/API/DTOs/Email/ConfirmationEmailDto.cs@@ -0,0 +1,8 @@+namespace API.DTOs.Email;++public class ConfirmationEmailDto+{+ public string InvitingUser { get; init; }+ public string EmailAddress { get; init; }+ public string ServerConfirmationLink { get; init; }+}diff --git a/API/DTOs/Email/EmailMigrationDto.cs b/API/DTOs/Email/EmailMigrationDto.csnew file mode 100644index 000000000..0da3bd5eb--- /dev/null+++ b/API/DTOs/Email/EmailMigrationDto.cs@@ -0,0 +1,8 @@+namespace API.DTOs.Email;++public class EmailMigrationDto+{+ public string EmailAddress { get; init; }+ public string Username { get; init; }+ public string ServerConfirmationLink { get; init; }+}diff --git a/API/DTOs/Filtering/ReadStatus.cs b/API/DTOs/Filtering/ReadStatus.csindex e2452fdc1..eeb786714 100644--- a/API/DTOs/Filtering/ReadStatus.cs+++ b/API/DTOs/Filtering/ReadStatus.cs@@ -1,6 +1,4 @@-using System;--namespace API.DTOs.Filtering;+namespace API.DTOs.Filtering;/// <summary>/// Represents the Reading Status. This is a flag and allows multiple statuesdiff --git a/API/DTOs/MemberDto.cs b/API/DTOs/MemberDto.csindex 88a16aa7c..8215cebc2 100644--- a/API/DTOs/MemberDto.cs+++ b/API/DTOs/MemberDto.cs@@ -4,15 +4,16 @@ using System.Collections.Generic;namespace API.DTOs{/// <summary>- /// Represents a member of a Kavita server.+ /// Represents a member of a Kavita server./// </summary>public class MemberDto{public int Id { get; init; }public string Username { get; init; }+ public string Email { get; init; }public DateTime Created { get; init; }public DateTime LastActive { get; init; }public IEnumerable<LibraryDto> Libraries { get; init; }public IEnumerable<string> Roles { get; init; }}-}\ No newline at end of file+}diff --git a/API/DTOs/Reader/ChapterInfoDto.cs b/API/DTOs/Reader/ChapterInfoDto.csindex e29f3798c..7c847d926 100644--- a/API/DTOs/Reader/ChapterInfoDto.cs+++ b/API/DTOs/Reader/ChapterInfoDto.cs@@ -1,5 +1,4 @@-using System;-using API.Entities.Enums;+using API.Entities.Enums;namespace API.DTOs.Reader{diff --git a/API/DTOs/RegisterDto.cs b/API/DTOs/RegisterDto.csindex 1bf598f5d..33dc62212 100644--- a/API/DTOs/RegisterDto.cs+++ b/API/DTOs/RegisterDto.cs@@ -7,6 +7,8 @@ namespace API.DTOs[Required]public string Username { get; init; }[Required]+ public string Email { get; init; }+ [Required][StringLength(32, MinimumLength = 6)]public string Password { get; set; }public bool IsAdmin { get; init; }diff --git a/API/DTOs/UserDto.cs b/API/DTOs/UserDto.csindex d7d6be2e9..7a7a234e7 100644--- a/API/DTOs/UserDto.cs+++ b/API/DTOs/UserDto.cs@@ -4,6 +4,7 @@ namespace API.DTOspublic class UserDto{public string Username { get; init; }+ public string Email { get; init; }public string Token { get; init; }public string RefreshToken { get; init; }public string ApiKey { get; init; }diff --git a/API/Data/MigrateConfigFiles.cs b/API/Data/MigrateConfigFiles.csindex 51ee37167..1acc81b13 100644--- a/API/Data/MigrateConfigFiles.cs+++ b/API/Data/MigrateConfigFiles.cs@@ -1,7 +1,6 @@using System;using System.Collections.Generic;using System.IO;-using System.IO.Abstractions;using System.Linq;using API.Services;using Kavita.Common;diff --git a/API/Data/Repositories/LibraryRepository.cs b/API/Data/Repositories/LibraryRepository.csindex 26fc517a2..a97826c75 100644--- a/API/Data/Repositories/LibraryRepository.cs+++ b/API/Data/Repositories/LibraryRepository.cs@@ -1,4 +1,5 @@using System;+using System.Collections;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;@@ -36,6 +37,7 @@ public interface ILibraryRepositoryTask<bool> DeleteLibrary(int libraryId);Task<IEnumerable<Library>> GetLibrariesForUserIdAsync(int userId);Task<LibraryType> GetLibraryTypeAsync(int libraryId);+ Task<IEnumerable<Library>> GetLibraryForIdsAsync(IList<int> libraryIds);}public class LibraryRepository : ILibraryRepository@@ -108,6 +110,13 @@ public class LibraryRepository : ILibraryRepository.SingleAsync();}+ public async Task<IEnumerable<Library>> GetLibraryForIdsAsync(IList<int> libraryIds)+ {+ return await _context.Library+ .Where(x => libraryIds.Contains(x.Id))+ .ToListAsync();+ }+public async Task<IEnumerable<LibraryDto>> GetLibraryDtosAsync(){return await _context.Librarydiff --git a/API/Data/Repositories/TagRepository.cs b/API/Data/Repositories/TagRepository.csindex 772957aa9..50d566aae 100644--- a/API/Data/Repositories/TagRepository.cs+++ b/API/Data/Repositories/TagRepository.cs@@ -50,13 +50,13 @@ public class TagRepository : ITagRepositorypublic async Task RemoveAllTagNoLongerAssociated(bool removeExternal = false){- var TagsWithNoConnections = await _context.Tag+ var tagsWithNoConnections = await _context.Tag.Include(p => p.SeriesMetadatas).Include(p => p.Chapters).Where(p => p.SeriesMetadatas.Count == 0 && p.Chapters.Count == 0 && p.ExternalTag == removeExternal).ToListAsync();- _context.Tag.RemoveRange(TagsWithNoConnections);+ _context.Tag.RemoveRange(tagsWithNoConnections);await _context.SaveChangesAsync();}diff --git a/API/Data/Repositories/UserRepository.cs b/API/Data/Repositories/UserRepository.csindex 138ef15b8..b4e8a97f7 100644--- a/API/Data/Repositories/UserRepository.cs+++ b/API/Data/Repositories/UserRepository.cs@@ -1,5 +1,6 @@using System;using System.Collections.Generic;+using System.ComponentModel.DataAnnotations;using System.Linq;using System.Threading.Tasks;using API.Constants;@@ -20,7 +21,8 @@ public enum AppUserIncludesProgress = 2,Bookmarks = 4,ReadingLists = 8,- Ratings = 16+ Ratings = 16,+ UserPreferences = 32}public interface IUserRepository@@ -29,7 +31,8 @@ public interface IUserRepositoryvoid Update(AppUserPreferences preferences);void Update(AppUserBookmark bookmark);public void Delete(AppUser user);- Task<IEnumerable<MemberDto>> GetMembersAsync();+ Task<IEnumerable<MemberDto>> GetEmailConfirmedMemberDtosAsync();+ Task<IEnumerable<MemberDto>> GetPendingMemberDtosAsync();Task<IEnumerable<AppUser>> GetAdminUsersAsync();Task<IEnumerable<AppUser>> GetNonAdminUsersAsync();Task<bool> IsUserAdminAsync(AppUser user);@@ -48,6 +51,7 @@ public interface IUserRepositoryTask<int> GetUserIdByUsernameAsync(string username);Task<AppUser> GetUserWithReadingListsByUsernameAsync(string username);Task<IList<AppUserBookmark>> GetAllBookmarksByIds(IList<int> bookmarkIds);+ Task<AppUser> GetUserByEmailAsync(string email);}public class UserRepository : IUserRepository@@ -156,6 +160,13 @@ public class UserRepository : IUserRepositoryquery = query.Include(u => u.Ratings);}+ if (includeFlags.HasFlag(AppUserIncludes.UserPreferences))+ {+ query = query.Include(u => u.UserPreferences);+ }+++return query;}@@ -198,6 +209,11 @@ public class UserRepository : IUserRepository.ToListAsync();}+ public async Task<AppUser> GetUserByEmailAsync(string email)+ {+ return await _context.AppUser.SingleOrDefaultAsync(u => u.Email.Equals(email));+ }+public async Task<IEnumerable<AppUser>> GetAdminUsersAsync(){return await _userManager.GetUsersInRoleAsync(PolicyConstants.AdminRole);@@ -280,9 +296,10 @@ public class UserRepository : IUserRepository}- public async Task<IEnumerable<MemberDto>> GetMembersAsync()+ public async Task<IEnumerable<MemberDto>> GetEmailConfirmedMemberDtosAsync(){return await _context.Users+ .Where(u => u.EmailConfirmed).Include(x => x.Libraries).Include(r => r.UserRoles).ThenInclude(r => r.Role)@@ -291,6 +308,7 @@ public class UserRepository : IUserRepository{Id = u.Id,Username = u.UserName,+ Email = u.Email,Created = u.Created,LastActive = u.LastActive,Roles = u.UserRoles.Select(r => r.Role.Name).ToList(),@@ -305,4 +323,42 @@ public class UserRepository : IUserRepository.AsNoTracking().ToListAsync();}++ public async Task<IEnumerable<MemberDto>> GetPendingMemberDtosAsync()+ {+ return await _context.Users+ .Where(u => !u.EmailConfirmed)+ .Include(x => x.Libraries)+ .Include(r => r.UserRoles)+ .ThenInclude(r => r.Role)+ .OrderBy(u => u.UserName)+ .Select(u => new MemberDto+ {+ Id = u.Id,+ Username = u.UserName,+ Email = u.Email,+ Created = u.Created,+ LastActive = u.LastActive,+ Roles = u.UserRoles.Select(r => r.Role.Name).ToList(),+ Libraries = u.Libraries.Select(l => new LibraryDto+ {+ Name = l.Name,+ Type = l.Type,+ LastScanned = l.LastScanned,+ Folders = l.Folders.Select(x => x.Path).ToList()+ }).ToList()+ })+ .AsNoTracking()+ .ToListAsync();+ }++ public async Task<bool> ValidateUserExists(string username)+ {+ if (await _userManager.Users.AnyAsync(x => x.NormalizedUserName == username.ToUpper()))+ {+ throw new ValidationException("Username is taken.");+ }++ return true;+ }}diff --git a/API/Data/Repositories/VolumeRepository.cs b/API/Data/Repositories/VolumeRepository.csindex e63b469e6..6ab2ca113 100644--- a/API/Data/Repositories/VolumeRepository.cs+++ b/API/Data/Repositories/VolumeRepository.cs@@ -1,7 +1,6 @@using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;-using API.Comparators;using API.DTOs;using API.Entities;using API.Extensions;diff --git a/API/Entities/Enums/AgeRating.cs b/API/Entities/Enums/AgeRating.csindex ddb288ee1..ed9deac25 100644--- a/API/Entities/Enums/AgeRating.cs+++ b/API/Entities/Enums/AgeRating.cs@@ -21,6 +21,7 @@ public enum AgeRating[Description("Everyone 10+")]Everyone10Plus = 5,[Description("PG")]+ // ReSharper disable once InconsistentNamingPG = 6,[Description("Kids to Adults")]KidsToAdults = 7,diff --git a/API/Entities/Metadata/SeriesMetadata.cs b/API/Entities/Metadata/SeriesMetadata.csindex 54ea8ccc0..81fcba090 100644--- a/API/Entities/Metadata/SeriesMetadata.cs+++ b/API/Entities/Metadata/SeriesMetadata.cs@@ -1,5 +1,4 @@-using System;-using System.Collections.Generic;+using System.Collections.Generic;using System.ComponentModel.DataAnnotations;using API.Entities.Enums;using API.Entities.Interfaces;diff --git a/API/Extensions/ApplicationServiceExtensions.cs b/API/Extensions/ApplicationServiceExtensions.csindex fd0c5f5ca..edc3cf4e9 100644--- a/API/Extensions/ApplicationServiceExtensions.cs+++ b/API/Extensions/ApplicationServiceExtensions.cs@@ -37,6 +37,7 @@ namespace API.Extensionsservices.AddScoped<IReaderService, ReaderService>();services.AddScoped<IReadingItemService, ReadingItemService>();services.AddScoped<IAccountService, AccountService>();+ services.AddScoped<IEmailService, EmailService>();services.AddScoped<IFileSystem, FileSystem>();diff --git a/API/Extensions/HttpExtensions.cs b/API/Extensions/HttpExtensions.csindex 68655f43d..f0b3d5399 100644--- a/API/Extensions/HttpExtensions.cs+++ b/API/Extensions/HttpExtensions.cs@@ -1,6 +1,5 @@using System.IO;using System.Linq;-using System.Runtime.Intrinsics.Arm;using System.Security.Cryptography;using System.Text;using System.Text.Json;diff --git a/API/Extensions/IdentityServiceExtensions.cs b/API/Extensions/IdentityServiceExtensions.csindex bdf177586..763f3a5a4 100644--- a/API/Extensions/IdentityServiceExtensions.cs+++ b/API/Extensions/IdentityServiceExtensions.cs@@ -1,12 +1,9 @@-using System;-using System.Text;+using System.Text;using System.Threading.Tasks;using API.Constants;using API.Data;using API.Entities;-using ExCSS;using Microsoft.AspNetCore.Authentication.JwtBearer;-using Microsoft.AspNetCore.Authorization.Infrastructure;using Microsoft.AspNetCore.Identity;using Microsoft.Extensions.Configuration;using Microsoft.Extensions.DependencyInjection;@@ -27,6 +24,8 @@ namespace API.Extensionsopt.Password.RequireUppercase = false;opt.Password.RequireNonAlphanumeric = false;opt.Password.RequiredLength = 6;++ opt.SignIn.RequireConfirmedEmail = true;}).AddTokenProvider<DataProtectorTokenProvider<AppUser>>(TokenOptions.DefaultProvider).AddRoles<AppRole>()@@ -35,6 +34,7 @@ namespace API.Extensions.AddRoleValidator<RoleValidator<AppRole>>().AddEntityFrameworkStores<DataContext>();+services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>{diff --git a/API/Extensions/ParserInfoListExtensions.cs b/API/Extensions/ParserInfoListExtensions.csindex 31a65c819..262a8012a 100644--- a/API/Extensions/ParserInfoListExtensions.cs+++ b/API/Extensions/ParserInfoListExtensions.cs@@ -1,7 +1,6 @@using System.Collections.Generic;using System.Linq;using API.Entities;-using API.Entities.Enums;using API.Parser;namespace API.Extensionsdiff --git a/API/Helpers/ParserInfoHelpers.cs b/API/Helpers/ParserInfoHelpers.csindex 48421cd70..a97601a43 100644--- a/API/Helpers/ParserInfoHelpers.cs+++ b/API/Helpers/ParserInfoHelpers.cs@@ -1,7 +1,6 @@using System.Collections.Generic;using API.Entities;using API.Entities.Enums;-using API.Extensions;using API.Parser;using API.Services.Tasks.Scanner;diff --git a/API/Helpers/SQLHelper.cs b/API/Helpers/SQLHelper.csindex d06d246ef..fcd44e7da 100644--- a/API/Helpers/SQLHelper.cs+++ b/API/Helpers/SQLHelper.cs@@ -2,7 +2,6 @@using System.Collections.Generic;using System.Data;using System.Data.Common;-using API.DTOs;using Microsoft.EntityFrameworkCore;namespace API.Helpersdiff --git a/API/Parser/Parser.cs b/API/Parser/Parser.csindex 847b0b62b..be9d8e8af 100644--- a/API/Parser/Parser.cs+++ b/API/Parser/Parser.cs@@ -3,7 +3,6 @@ using System.IO;using System.Linq;using System.Text.RegularExpressions;using API.Entities.Enums;-using API.Services;namespace API.Parser{diff --git a/API/Program.cs b/API/Program.csindex 286a0f0cd..c6cb7ed69 100644--- a/API/Program.cs+++ b/API/Program.cs@@ -8,7 +8,6 @@ using API.Data;using API.Entities;using API.Entities.Enums;using API.Services;-using API.Services.Tasks;using Kavita.Common;using Kavita.Common.EnvironmentInfo;using Microsoft.AspNetCore.Hosting;diff --git a/API/Services/AccountService.cs b/API/Services/AccountService.csindex 0591770ec..62f5386fb 100644--- a/API/Services/AccountService.cs+++ b/API/Services/AccountService.cs@@ -1,9 +1,12 @@-using System.Collections.Generic;+using System;+using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;+using API.Data;using API.Entities;using API.Errors;using Microsoft.AspNetCore.Identity;+using Microsoft.EntityFrameworkCore;using Microsoft.Extensions.Logging;namespace API.Services@@ -11,30 +14,29 @@ namespace API.Servicespublic interface IAccountService{Task<IEnumerable<ApiException>> ChangeUserPassword(AppUser user, string newPassword);+ Task<IEnumerable<ApiException>> ValidatePassword(AppUser user, string password);+ Task<IEnumerable<ApiException>> ValidateUsername(string username);+ Task<IEnumerable<ApiException>> ValidateEmail(string email);}public class AccountService : IAccountService{private readonly UserManager<AppUser> _userManager;private readonly ILogger<AccountService> _logger;+ private readonly IUnitOfWork _unitOfWork;public const string DefaultPassword = "[k.2@RZ!mxCQkJzE";- public AccountService(UserManager<AppUser> userManager, ILogger<AccountService> logger)+ public AccountService(UserManager<AppUser> userManager, ILogger<AccountService> logger, IUnitOfWork unitOfWork){_userManager = userManager;_logger = logger;+ _unitOfWork = unitOfWork;}public async Task<IEnumerable<ApiException>> ChangeUserPassword(AppUser user, string newPassword){- foreach (var validator in _userManager.PasswordValidators)- {- var validationResult = await validator.ValidateAsync(_userManager, user, newPassword);- if (!validationResult.Succeeded)- {- return validationResult.Errors.Select(e => new ApiException(400, e.Code, e.Description));- }- }+ var passwordValidationIssues = (await ValidatePassword(user, newPassword)).ToList();+ if (passwordValidationIssues.Any()) return passwordValidationIssues;var result = await _userManager.RemovePasswordAsync(user);if (!result.Succeeded)@@ -53,5 +55,42 @@ namespace API.Servicesreturn new List<ApiException>();}++ public async Task<IEnumerable<ApiException>> ValidatePassword(AppUser user, string password)+ {+ foreach (var validator in _userManager.PasswordValidators)+ {+ var validationResult = await validator.ValidateAsync(_userManager, user, password);+ if (!validationResult.Succeeded)+ {+ return validationResult.Errors.Select(e => new ApiException(400, e.Code, e.Description));+ }+ }++ return Array.Empty<ApiException>();+ }+ public async Task<IEnumerable<ApiException>> ValidateUsername(string username)+ {+ if (await _userManager.Users.AnyAsync(x => x.NormalizedUserName == username.ToUpper()))+ {+ return new List<ApiException>()+ {+ new ApiException(400, "Username is already taken")+ };+ }++ return Array.Empty<ApiException>();+ }++ public async Task<IEnumerable<ApiException>> ValidateEmail(string email)+ {+ var user = await _unitOfWork.UserRepository.GetUserByEmailAsync(email);+ if (user == null) return Array.Empty<ApiException>();++ return new List<ApiException>()+ {+ new ApiException(400, "Email is already registered")+ };+ }}}diff --git a/API/Services/ArchiveService.cs b/API/Services/ArchiveService.csindex cdf4df4db..db098aa0f 100644--- a/API/Services/ArchiveService.cs+++ b/API/Services/ArchiveService.cs@@ -7,7 +7,6 @@ using System.Linq;using System.Threading.Tasks;using System.Xml.Serialization;using API.Archive;-using API.Comparators;using API.Data.Metadata;using API.Extensions;using API.Services.Tasks;diff --git a/API/Services/BookService.cs b/API/Services/BookService.csindex d4fb303f0..5d40437d3 100644--- a/API/Services/BookService.cs+++ b/API/Services/BookService.cs@@ -171,7 +171,7 @@ namespace API.ServicesstylesheetHtml = stylesheetHtml.Insert(0, importBuilder.ToString());- EscapeCSSImportReferences(ref stylesheetHtml, apiBase, prepend);+ EscapeCssImportReferences(ref stylesheetHtml, apiBase, prepend);EscapeFontFamilyReferences(ref stylesheetHtml, apiBase, prepend);@@ -200,7 +200,7 @@ namespace API.Servicesreturn RemoveWhiteSpaceFromStylesheets(stylesheet.ToCss());}- private static void EscapeCSSImportReferences(ref string stylesheetHtml, string apiBase, string prepend)+ private static void EscapeCssImportReferences(ref string stylesheetHtml, string apiBase, string prepend){foreach (Match match in Parser.Parser.CssImportUrlRegex.Matches(stylesheetHtml)){diff --git a/API/Services/CacheService.cs b/API/Services/CacheService.csindex 0b6c4aa0d..c5396f4ed 100644--- a/API/Services/CacheService.cs+++ b/API/Services/CacheService.cs@@ -1,6 +1,4 @@-using System;-using System.Collections.Generic;-using System.Collections.Immutable;+using System.Collections.Generic;using System.IO;using System.Linq;using System.Threading.Tasks;diff --git a/API/Services/DirectoryService.cs b/API/Services/DirectoryService.csindex bf3c01d25..4862e40d8 100644--- a/API/Services/DirectoryService.cs+++ b/API/Services/DirectoryService.cs@@ -1,5 +1,4 @@using System;-using System.Collections;using System.Collections.Generic;using System.Collections.Immutable;using System.IO;@@ -7,7 +6,7 @@ using System.IO.Abstractions;using System.Linq;using System.Text.RegularExpressions;using System.Threading.Tasks;-using API.Comparators;+using API.Entities.Enums;using API.Extensions;using Microsoft.Extensions.Logging;@@ -22,7 +21,7 @@ namespace API.Servicesstring TempDirectory { get; }string ConfigDirectory { get; }/// <summary>- /// Original BookmarkDirectory. Only used for resetting directory. Use <see cref="ServerSettings.BackupDirectory"/> for actual path.+ /// Original BookmarkDirectory. Only used for resetting directory. Use <see cref="ServerSettingKey.BackupDirectory"/> for actual path./// </summary>string BookmarkDirectory { get; }/// <summary>@@ -682,7 +681,7 @@ namespace API.ServicesFileSystem.Path.Join(directoryName, "test.txt"),string.Empty);}- catch (Exception ex)+ catch (Exception){ClearAndDeleteDirectory(directoryName);return false;diff --git a/API/Services/EmailService.cs b/API/Services/EmailService.csnew file mode 100644index 000000000..4e2ba162e--- /dev/null+++ b/API/Services/EmailService.cs@@ -0,0 +1,103 @@+using System;+using System.Net.Http;+using System.Threading.Tasks;+using API.DTOs.Email;+using API.Services.Tasks;+using Flurl.Http;+using Kavita.Common.EnvironmentInfo;+using Microsoft.AspNetCore.Http;+using Microsoft.Extensions.Logging;++namespace API.Services;++public interface IEmailService+{+ Task SendConfirmationEmail(ConfirmationEmailDto data);+ Task<bool> CheckIfAccessible(string host);+ Task SendMigrationEmail(EmailMigrationDto data);+}++public class EmailService : IEmailService+{+ private readonly ILogger<EmailService> _logger;+ private const string ApiUrl = "https://email.kavitareader.com";++ public EmailService(ILogger<EmailService> logger)+ {+ _logger = logger;++ FlurlHttp.ConfigureClient(ApiUrl, cli =>+ cli.Settings.HttpClientFactory = new UntrustedCertClientFactory());+ }++ public async Task SendConfirmationEmail(ConfirmationEmailDto data)+ {++ var success = await SendEmailWithPost(ApiUrl + "/api/email/confirm", data);+ if (!success)+ {+ _logger.LogError("There was a critical error sending Confirmation email");+ }+ }++ public async Task<bool> CheckIfAccessible(string host)+ {+ return await SendEmailWithGet(ApiUrl + "/api/email/reachable?host=" + host);+ }++ public async Task SendMigrationEmail(EmailMigrationDto data)+ {+ await SendEmailWithPost(ApiUrl + "/api/email/email-migration", data);+ }++ private static async Task<bool> SendEmailWithGet(string url)+ {+ try+ {+ var response = await (url)+ .WithHeader("Accept", "application/json")+ .WithHeader("User-Agent", "Kavita")+ .WithHeader("x-api-key", "MsnvA2DfQqxSK5jh")+ .WithHeader("x-kavita-version", BuildInfo.Version)+ .WithHeader("Content-Type", "application/json")+ .WithTimeout(TimeSpan.FromSeconds(30))+ .GetStringAsync();++ if (!string.IsNullOrEmpty(response) && bool.Parse(response))+ {+ return true;+ }+ }+ catch (Exception)+ {+ return false;+ }+ return false;+ }+++ private static async Task<bool> SendEmailWithPost(string url, object data)+ {+ try+ {+ var response = await (url)+ .WithHeader("Accept", "application/json")+ .WithHeader("User-Agent", "Kavita")+ .WithHeader("x-api-key", "MsnvA2DfQqxSK5jh")+ .WithHeader("x-kavita-version", BuildInfo.Version)+ .WithHeader("Content-Type", "application/json")+ .WithTimeout(TimeSpan.FromSeconds(30))+ .PostJsonAsync(data);++ if (response.StatusCode != StatusCodes.Status200OK)+ {+ return false;+ }+ }+ catch (Exception)+ {+ return false;+ }+ return true;+ }+}diff --git a/API/Services/MetadataService.cs b/API/Services/MetadataService.csindex b6d45c77e..ed446ec19 100644--- a/API/Services/MetadataService.cs+++ b/API/Services/MetadataService.cs@@ -1,16 +1,13 @@using System;using System.Collections.Generic;using System.Diagnostics;-using System.IO;using System.Linq;using System.Threading.Tasks;using API.Comparators;using API.Data;-using API.Data.Metadata;using API.Data.Repositories;using API.Data.Scanner;using API.Entities;-using API.Entities.Enums;using API.Extensions;using API.Helpers;using API.SignalR;@@ -70,7 +67,7 @@ public class MetadataService : IMetadataServiceif (firstFile == null) return false;- _logger.LogDebug("[MetadataService] Generating cover image for {File}", firstFile?.FilePath);+ _logger.LogDebug("[MetadataService] Generating cover image for {File}", firstFile.FilePath);chapter.CoverImage = _readingItemService.GetCoverImage(firstFile.FilePath, ImageService.GetChapterFormat(chapter.Id, chapter.VolumeId), firstFile.Format);return true;@@ -144,7 +141,7 @@ public class MetadataService : IMetadataService/// </summary>/// <param name="series"></param>/// <param name="forceUpdate"></param>- private void ProcessSeriesMetadataUpdate(Series series, ICollection<Person> allPeople, ICollection<Genre> allGenres, ICollection<Tag> allTags, bool forceUpdate)+ private void ProcessSeriesMetadataUpdate(Series series, bool forceUpdate){_logger.LogDebug("[MetadataService] Processing series {SeriesName}", series.OriginalName);try@@ -220,17 +217,12 @@ public class MetadataService : IMetadataService});_logger.LogDebug("[MetadataService] Fetched {SeriesCount} series for refresh", nonLibrarySeries.Count);- var allPeople = await _unitOfWork.PersonRepository.GetAllPeople();- var allGenres = await _unitOfWork.GenreRepository.GetAllGenresAsync();- var allTags = await _unitOfWork.TagRepository.GetAllTagsAsync();--var seriesIndex = 0;foreach (var series in nonLibrarySeries){try{- ProcessSeriesMetadataUpdate(series, allPeople, allGenres, allTags, forceUpdate);+ ProcessSeriesMetadataUpdate(series, forceUpdate);}catch (Exception ex){@@ -270,12 +262,11 @@ public class MetadataService : IMetadataServiceawait _unitOfWork.GenreRepository.RemoveAllGenreNoLongerAssociated();}- // TODO: I can probably refactor RefreshMetadata and RefreshMetadataForSeries to be the same by utilizing chunk size of 1, so most of the code can be the same.+ // TODO: Write out a single piece of code that can iterate over a collection/chunk and perform custom actionsprivate async Task PerformScan(Library library, bool forceUpdate, Action<int, Chunk> action){var chunkInfo = await _unitOfWork.SeriesRepository.GetChunkInfo(library.Id);var stopwatch = Stopwatch.StartNew();- var totalTime = 0L;_logger.LogInformation("[MetadataService] Refreshing Library {LibraryName}. Total Items: {TotalSize}. Total Chunks: {TotalChunks} with {ChunkSize} size", library.Name, chunkInfo.TotalSize, chunkInfo.TotalChunks, chunkInfo.ChunkSize);await _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadataProgress,MessageFactory.RefreshMetadataProgressEvent(library.Id, 0F));@@ -283,7 +274,6 @@ public class MetadataService : IMetadataServicefor (var chunk = 1; chunk <= chunkInfo.TotalChunks; chunk++){if (chunkInfo.TotalChunks == 0) continue;- totalTime += stopwatch.ElapsedMilliseconds;stopwatch.Restart();action(chunk, chunkInfo);@@ -346,11 +336,7 @@ public class MetadataService : IMetadataServiceawait _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadataProgress,MessageFactory.RefreshMetadataProgressEvent(libraryId, 0F));- var allPeople = await _unitOfWork.PersonRepository.GetAllPeople();- var allGenres = await _unitOfWork.GenreRepository.GetAllGenresAsync();- var allTags = await _unitOfWork.TagRepository.GetAllTagsAsync();-- ProcessSeriesMetadataUpdate(series, allPeople, allGenres, allTags, forceUpdate);+ ProcessSeriesMetadataUpdate(series, forceUpdate);await _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadataProgress,MessageFactory.RefreshMetadataProgressEvent(libraryId, 1F));diff --git a/API/Services/ReaderService.cs b/API/Services/ReaderService.csindex be43c78cf..c59cd8549 100644--- a/API/Services/ReaderService.cs+++ b/API/Services/ReaderService.cs@@ -30,17 +30,13 @@ public class ReaderService : IReaderService{private readonly IUnitOfWork _unitOfWork;private readonly ILogger<ReaderService> _logger;- private readonly IDirectoryService _directoryService;- private readonly ICacheService _cacheService;private readonly ChapterSortComparer _chapterSortComparer = new ChapterSortComparer();private readonly ChapterSortComparerZeroFirst _chapterSortComparerForInChapterSorting = new ChapterSortComparerZeroFirst();- public ReaderService(IUnitOfWork unitOfWork, ILogger<ReaderService> logger, IDirectoryService directoryService, ICacheService cacheService)+ public ReaderService(IUnitOfWork unitOfWork, ILogger<ReaderService> logger){_unitOfWork = unitOfWork;_logger = logger;- _directoryService = directoryService;- _cacheService = cacheService;}public static string FormatBookmarkFolderPath(string baseDirectory, int userId, int seriesId, int chapterId)diff --git a/API/Services/TaskScheduler.cs b/API/Services/TaskScheduler.csindex 9f91bf75c..6c1d914cf 100644--- a/API/Services/TaskScheduler.cs+++ b/API/Services/TaskScheduler.cs@@ -35,7 +35,6 @@ public class TaskScheduler : ITaskSchedulerprivate readonly IStatsService _statsService;private readonly IVersionUpdaterService _versionUpdaterService;- private readonly IDirectoryService _directoryService;public static BackgroundJobServer Client => new BackgroundJobServer();private static readonly Random Rnd = new Random();@@ -43,8 +42,7 @@ public class TaskScheduler : ITaskSchedulerpublic TaskScheduler(ICacheService cacheService, ILogger<TaskScheduler> logger, IScannerService scannerService,IUnitOfWork unitOfWork, IMetadataService metadataService, IBackupService backupService,- ICleanupService cleanupService, IStatsService statsService, IVersionUpdaterService versionUpdaterService,- IDirectoryService directoryService)+ ICleanupService cleanupService, IStatsService statsService, IVersionUpdaterService versionUpdaterService){_cacheService = cacheService;_logger = logger;@@ -55,7 +53,6 @@ public class TaskScheduler : ITaskScheduler_cleanupService = cleanupService;_statsService = statsService;_versionUpdaterService = versionUpdaterService;- _directoryService = directoryService;}public async Task ScheduleTasks()diff --git a/API/Services/Tasks/ScannerService.cs b/API/Services/Tasks/ScannerService.csindex 7c6a51f2c..374bffb3d 100644--- a/API/Services/Tasks/ScannerService.cs+++ b/API/Services/Tasks/ScannerService.cs@@ -569,7 +569,7 @@ public class ScannerService : IScannerServicePersonHelper.UpdatePeople(allPeople, chapter.People.Where(p => p.Role == PersonRole.Translator).Select(p => p.Name), PersonRole.Translator,person => PersonHelper.AddPersonIfNotExists(series.Metadata.People, person));- TagHelper.UpdateTag(allTags, chapter.Tags.Select(t => t.Title), false, (tag, added) =>+ TagHelper.UpdateTag(allTags, chapter.Tags.Select(t => t.Title), false, (tag, _) =>TagHelper.AddTagIfNotExists(series.Metadata.Tags, tag));GenreHelper.UpdateGenre(allGenres, chapter.Genres.Select(t => t.Title), false, genre =>@@ -821,7 +821,7 @@ public class ScannerService : IScannerService// Remove all tags that aren't matching between chapter tags and metadataTagHelper.KeepOnlySameTagBetweenLists(chapter.Tags, tags.Select(t => DbFactory.Tag(t, false)).ToList());TagHelper.UpdateTag(allTags, tags, false,- (tag, added) =>+ (tag, _) =>{chapter.Tags.Add(tag);});diff --git a/API/Startup.cs b/API/Startup.csindex 00bfdd589..6fd0d2ff0 100644--- a/API/Startup.cs+++ b/API/Startup.cs@@ -6,7 +6,6 @@ using System.Net;using System.Net.Sockets;using System.Threading.Tasks;using API.Data;-using API.Entities;using API.Extensions;using API.Middleware;using API.Services;@@ -21,10 +20,8 @@ using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Hosting;using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.HttpOverrides;-using Microsoft.AspNetCore.Identity;using Microsoft.AspNetCore.ResponseCompression;using Microsoft.AspNetCore.StaticFiles;-using Microsoft.EntityFrameworkCore;using Microsoft.Extensions.Configuration;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Hosting;diff --git a/Kavita.Common/AppSettingsConfig.cs b/Kavita.Common/AppSettingsConfig.csdeleted file mode 100644index c7718b230..000000000--- a/Kavita.Common/AppSettingsConfig.cs+++ /dev/null@@ -1,7 +0,0 @@-namespace Kavita.Common-{- public class AppSettingsConfig- {-- }-}diff --git a/Kavita.Common/Configuration.cs b/Kavita.Common/Configuration.csindex 7593ae84a..55aa99598 100644--- a/Kavita.Common/Configuration.cs+++ b/Kavita.Common/Configuration.cs@@ -329,7 +329,7 @@ namespace Kavita.Common}/// <summary>- /// This should NEVER be called except by <see cref="MigrateConfigFiles"/>+ /// This should NEVER be called except by MigrateConfigFiles/// </summary>/// <param name="filePath"></param>/// <param name="updatedPath"></param>diff --git a/UI/Web/src/app/_models/member.ts b/UI/Web/src/app/_models/member.tsindex 0b8f17423..e1ef5ea77 100644--- a/UI/Web/src/app/_models/member.ts+++ b/UI/Web/src/app/_models/member.ts@@ -1,7 +1,9 @@import { Library } from './library';export interface Member {+ id: number;username: string;+ email: string;lastActive: string; // datetimecreated: string; // datetimeisAdmin: boolean;diff --git a/UI/Web/src/app/_services/account.service.ts b/UI/Web/src/app/_services/account.service.tsindex 7b6159b51..e19bcacf4 100644--- a/UI/Web/src/app/_services/account.service.ts+++ b/UI/Web/src/app/_services/account.service.ts@@ -49,7 +49,7 @@ export class AccountService implements OnDestroy {return this.httpClient.get<string[]>(this.baseUrl + 'account/roles');}- login(model: any): Observable<any> {+ login(model: {username: string, password: string}): Observable<any> {return this.httpClient.post<User>(this.baseUrl + 'account/login', model).pipe(map((response: User) => {const user = response;@@ -91,25 +91,13 @@ export class AccountService implements OnDestroy {this.messageHub.stopHubConnection();}- // setCurrentUser() {- // // TODO: Refactor this to setCurentUser in accoutnService- // const user = this.getUserFromLocalStorage();--- // if (user) {- // this.navService.setDarkMode(user.preferences.siteDarkMode);- // this.messageHub.createHubConnection(user, this.accountService.hasAdminRole(user));- // this.libraryService.getLibraryNames().pipe(take(1)).subscribe(() => {/* No Operation */});- // } else {- // this.navService.setDarkMode(true);- // }- // }-- register(model: {username: string, password: string, isAdmin?: boolean}) {- if (!model.hasOwnProperty('isAdmin')) {- model.isAdmin = false;- }+ /**+ * Registers the first admin on the account. Only used for that. All other registrations must occur through invite+ * @param model+ * @returns+ */+ register(model: {username: string, password: string, email: string}) {return this.httpClient.post<User>(this.baseUrl + 'account/register', model).pipe(map((user: User) => {return user;@@ -118,6 +106,26 @@ export class AccountService implements OnDestroy {);}+ migrateUser(model: {email: string, username: string, password: string, sendEmail: boolean}) {+ return this.httpClient.post<string>(this.baseUrl + 'account/migrate-email', model, {responseType: 'text' as 'json'});+ }++ confirmMigrationEmail(model: {email: string, token: string}) {+ return this.httpClient.post<User>(this.baseUrl + 'account/confirm-migration-email', model);+ }++ resendConfirmationEmail(userId: number) {+ return this.httpClient.post<string>(this.baseUrl + 'account/resend-confirmation-email?userId=' + userId, {}, {responseType: 'text' as 'json'});+ }++ inviteUser(model: {email: string, roles: Array<string>, libraries: Array<number>, sendEmail: boolean}) {+ return this.httpClient.post<string>(this.baseUrl + 'account/invite', model, {responseType: 'text' as 'json'});+ }++ confirmEmail(model: {email: string, username: string, password: string, token: string}) {+ return this.httpClient.post<User>(this.baseUrl + 'account/confirm-email', model);+ }+getDecodedToken(token: string) {return JSON.parse(atob(token.split('.')[1]));}@@ -126,6 +134,10 @@ export class AccountService implements OnDestroy {return this.httpClient.post(this.baseUrl + 'account/reset-password', {username, password}, {responseType: 'json' as 'text'});}+ update(model: {email: string, roles: Array<string>, libraries: Array<number>, userId: number}) {+ return this.httpClient.post(this.baseUrl + 'account/update', model);+ }+updatePreferences(userPreferences: Preferences) {return this.httpClient.post<Preferences>(this.baseUrl + 'users/update-preferences', userPreferences).pipe(map(settings => {if (this.currentUser !== undefined || this.currentUser != null) {diff --git a/UI/Web/src/app/_services/member.service.ts b/UI/Web/src/app/_services/member.service.tsindex 3e59347f7..1c7820e8a 100644--- a/UI/Web/src/app/_services/member.service.ts+++ b/UI/Web/src/app/_services/member.service.ts@@ -39,4 +39,8 @@ export class MemberService {updateMemberRoles(username: string, roles: string[]) {return this.httpClient.post(this.baseUrl + 'account/update-rbs', {username, roles});}++ getPendingInvites() {+ return this.httpClient.get<Array<Member>>(this.baseUrl + 'users/pending');+ }}diff --git a/UI/Web/src/app/_services/server.service.ts b/UI/Web/src/app/_services/server.service.tsindex 4538d17db..fcc94435c 100644--- a/UI/Web/src/app/_services/server.service.ts+++ b/UI/Web/src/app/_services/server.service.ts@@ -36,4 +36,8 @@ export class ServerService {getChangelog() {return this.httpClient.get<UpdateVersionEvent[]>(this.baseUrl + 'server/changelog', {});}++ isServerAccessible() {+ return this.httpClient.get<boolean>(this.baseUrl + 'server/accessible');+ }}diff --git a/UI/Web/src/app/admin/_modals/edit-rbs-modal/edit-rbs-modal.component.ts b/UI/Web/src/app/admin/_modals/edit-rbs-modal/edit-rbs-modal.component.tsindex ff6346152..54f27f926 100644--- a/UI/Web/src/app/admin/_modals/edit-rbs-modal/edit-rbs-modal.component.ts+++ b/UI/Web/src/app/admin/_modals/edit-rbs-modal/edit-rbs-modal.component.ts@@ -4,6 +4,8 @@ import { Member } from 'src/app/_models/member';import { AccountService } from 'src/app/_services/account.service';import { MemberService } from 'src/app/_services/member.service';+// TODO: Remove this component, edit-user will take over+@Component({selector: 'app-edit-rbs-modal',templateUrl: './edit-rbs-modal.component.html',diff --git a/UI/Web/src/app/admin/_modals/library-access-modal/library-access-modal.component.ts b/UI/Web/src/app/admin/_modals/library-access-modal/library-access-modal.component.tsindex 4c7791b4d..50023b3e7 100644--- a/UI/Web/src/app/admin/_modals/library-access-modal/library-access-modal.component.ts+++ b/UI/Web/src/app/admin/_modals/library-access-modal/library-access-modal.component.ts@@ -21,7 +21,6 @@ export class LibraryAccessModalComponent implements OnInit {isLoading: boolean = false;get hasSomeSelected() {- console.log(this.selections != null && this.selections.hasSomeSelected());return this.selections != null && this.selections.hasSomeSelected();}diff --git a/UI/Web/src/app/admin/admin.module.ts b/UI/Web/src/app/admin/admin.module.tsindex 5ffadf3a1..49bbf1153 100644--- a/UI/Web/src/app/admin/admin.module.ts+++ b/UI/Web/src/app/admin/admin.module.ts@@ -16,6 +16,10 @@ import { EditRbsModalComponent } from './_modals/edit-rbs-modal/edit-rbs-modal.cimport { ManageSystemComponent } from './manage-system/manage-system.component';import { ChangelogComponent } from './changelog/changelog.component';import { PipeModule } from '../pipe/pipe.module';+import { InviteUserComponent } from './invite-user/invite-user.component';+import { RoleSelectorComponent } from './role-selector/role-selector.component';+import { LibrarySelectorComponent } from './library-selector/library-selector.component';+import { EditUserComponent } from './edit-user/edit-user.component';@@ -33,6 +37,10 @@ import { PipeModule } from '../pipe/pipe.module';EditRbsModalComponent,ManageSystemComponent,ChangelogComponent,+ InviteUserComponent,+ RoleSelectorComponent,+ LibrarySelectorComponent,+ EditUserComponent,],imports: [CommonModule,diff --git a/UI/Web/src/app/admin/edit-user/edit-user.component.html b/UI/Web/src/app/admin/edit-user/edit-user.component.htmlnew file mode 100644index 000000000..db7af4508--- /dev/null+++ b/UI/Web/src/app/admin/edit-user/edit-user.component.html@@ -0,0 +1,58 @@+<div class="modal-header">+ <h4 class="modal-title" id="modal-basic-title">Edit {{member.username | sentenceCase}}</h4>+ <button type="button" class="close" aria-label="Close" (click)="close()">+ <span aria-hidden="true">×</span>+ </button>+</div>+<div class="modal-body">++ <form [formGroup]="userForm">+ <div class="row no-gutters">+ <div class="col-md-6 col-sm-12 pr-2">+ <div class="form-group">+ <label for="username">Username</label>+ <input id="username" class="form-control" formControlName="username" type="text">+ <div id="inviteForm-validations" class="invalid-feedback" *ngIf="userForm.dirty || userForm.touched">+ <div *ngIf="userForm.get('username')?.errors?.required">+ This field is required+ </div>+ </div>+ </div>+ </div>+ <div class="col-md-6 col-sm-12">+ <div class="form-group" style="width:100%">+ <label for="email">Email</label>+ <input class="form-control" type="email" id="email" formControlName="email" [disabled]="true">+ <div id="inviteForm-validations" class="invalid-feedback" *ngIf="userForm.dirty || userForm.touched">+ <div *ngIf="userForm.get('email')?.errors?.required">+ This field is required+ </div>+ <div *ngIf="userForm.get('email')?.errors?.email">+ This must be a valid email address+ </div>+ </div>+ </div>+ </div>+ </div>++ <div class="row no-gutters">+ <div class="col-md-6">+ <app-role-selector (selected)="updateRoleSelection($event)" [allowAdmin]="true" [member]="member"></app-role-selector>+ </div>++ <div class="col-md-6">+ <app-library-selector (selected)="updateLibrarySelection($event)" [member]="member"></app-library-selector>+ </div>+ </div>+ </form>++</div>+<div class="modal-footer">+ <button type="button" class="btn btn-secondary" (click)="close()">+ Cancel+ </button>+ <button type="button" class="btn btn-primary" (click)="save()" [disabled]="isSaving || !userForm.valid">+ <span *ngIf="isSaving" class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>+ <span>{{isSaving ? 'Saving...' : 'Update'}}</span>+ </button>+</div>diff --git a/UI/Web/src/app/admin/edit-user/edit-user.component.scss b/UI/Web/src/app/admin/edit-user/edit-user.component.scssnew file mode 100644index 000000000..e69de29bbdiff --git a/UI/Web/src/app/admin/edit-user/edit-user.component.ts b/UI/Web/src/app/admin/edit-user/edit-user.component.tsnew file mode 100644index 000000000..ceec62cae--- /dev/null+++ b/UI/Web/src/app/admin/edit-user/edit-user.component.ts@@ -0,0 +1,62 @@+import { Component, Input, OnInit } from '@angular/core';+import { FormGroup, FormControl, Validators } from '@angular/forms';+import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';+import { ConfirmService } from 'src/app/shared/confirm.service';+import { Library } from 'src/app/_models/library';+import { Member } from 'src/app/_models/member';+import { AccountService } from 'src/app/_services/account.service';+import { ServerService } from 'src/app/_services/server.service';++// TODO: Rename this to EditUserModal+@Component({+ selector: 'app-edit-user',+ templateUrl: './edit-user.component.html',+ styleUrls: ['./edit-user.component.scss']+})+export class EditUserComponent implements OnInit {++ @Input() member!: Member;++ selectedRoles: Array<string> = [];+ selectedLibraries: Array<number> = [];+ isSaving: boolean = false;++ userForm: FormGroup = new FormGroup({});++ public get email() { return this.userForm.get('email'); }+ public get username() { return this.userForm.get('username'); }+ public get password() { return this.userForm.get('password'); }++ constructor(public modal: NgbActiveModal, private accountService: AccountService, private serverService: ServerService,+ private confirmService: ConfirmService) { }++ ngOnInit(): void {+ this.userForm.addControl('email', new FormControl(this.member.email, [Validators.required, Validators.email]));+ this.userForm.addControl('username', new FormControl(this.member.username, [Validators.required]));++ this.userForm.get('email')?.disable();+ }++ updateRoleSelection(roles: Array<string>) {+ this.selectedRoles = roles;+ }++ updateLibrarySelection(libraries: Array<Library>) {+ this.selectedLibraries = libraries.map(l => l.id);+ }++ close() {+ this.modal.close(false);+ }++ save() {+ const model = this.userForm.getRawValue();+ model.userId = this.member.id;+ model.roles = this.selectedRoles;+ model.libraries = this.selectedLibraries;+ this.accountService.update(model).subscribe(() => {+ this.modal.close(true);+ });+ }++}diff --git a/UI/Web/src/app/admin/invite-user/invite-user.component.html b/UI/Web/src/app/admin/invite-user/invite-user.component.htmlnew file mode 100644index 000000000..41954f2b7--- /dev/null+++ b/UI/Web/src/app/admin/invite-user/invite-user.component.html@@ -0,0 +1,56 @@+<div class="modal-header">+ <h4 class="modal-title" id="modal-basic-title">Invite User</h4>+ <button type="button" class="close" aria-label="Close" (click)="close()">+ <span aria-hidden="true">×</span>+ </button>+</div>+<div class="modal-body">+ <p>+ Invite a user to your server. Enter their email in and we will send them an email to create an account.+ </p>++ <p *ngIf="!checkedAccessibility">+ <span class="spinner-border text-primary" style="width: 1.5rem; height: 1.5rem;" role="status" aria-hidden="true"></span>+ Checking accessibility of server...+ </p>+++ <form [formGroup]="inviteForm">+ <div class="row no-gutters">+ <div class="form-group" style="width:100%">+ <label for="email">Email</label>+ <input class="form-control" type="email" id="email" formControlName="email" required>+ <div id="inviteForm-validations" class="invalid-feedback" *ngIf="inviteForm.dirty || inviteForm.touched">+ <div *ngIf="email?.errors?.required">+ This field is required+ </div>+ </div>+ </div>+ </div>++ <ng-container *ngIf="emailLink !== '' && checkedAccessibility && !accessible">+ <p>Use this link to finish setting up the user account due to your server not being accessible outside your local network.</p>+ <a href="{{emailLink}}" target="_blank">{{emailLink}}</a>+ </ng-container>++ <div class="row no-gutters">+ <div class="col-md-6">+ <app-role-selector (selected)="updateRoleSelection($event)" [allowAdmin]="true"></app-role-selector>+ </div>++ <div class="col-md-6">+ <app-library-selector (selected)="updateLibrarySelection($event)"></app-library-selector>+ </div>+ </div>+ </form>++</div>+<div class="modal-footer">+ <button type="button" class="btn btn-secondary" (click)="close()">+ Cancel+ </button>+ <button type="button" class="btn btn-primary" (click)="invite()" [disabled]="isSending || !inviteForm.valid || !checkedAccessibility || emailLink !== ''">+ <span *ngIf="isSending" class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>+ <span>{{isSending ? 'Inviting...' : 'Invite'}}</span>+ </button>+</div>diff --git a/UI/Web/src/app/admin/invite-user/invite-user.component.scss b/UI/Web/src/app/admin/invite-user/invite-user.component.scssnew file mode 100644index 000000000..e69de29bbdiff --git a/UI/Web/src/app/admin/invite-user/invite-user.component.ts b/UI/Web/src/app/admin/invite-user/invite-user.component.tsnew file mode 100644index 000000000..e8cebcb19--- /dev/null+++ b/UI/Web/src/app/admin/invite-user/invite-user.component.ts@@ -0,0 +1,80 @@+import { Component, OnInit } from '@angular/core';+import { FormControl, FormGroup, Validators } from '@angular/forms';+import { DomSanitizer, SafeUrl } from '@angular/platform-browser';+import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';+import { ConfirmService } from 'src/app/shared/confirm.service';+import { Library } from 'src/app/_models/library';+import { AccountService } from 'src/app/_services/account.service';+import { ServerService } from 'src/app/_services/server.service';++@Component({+ selector: 'app-invite-user',+ templateUrl: './invite-user.component.html',+ styleUrls: ['./invite-user.component.scss']+})+export class InviteUserComponent implements OnInit {++ /**+ * Maintains if the backend is sending an email+ */+ isSending: boolean = false;+ inviteForm: FormGroup = new FormGroup({});+ /**+ * If a user would be able to load this server up externally+ */+ accessible: boolean = true;+ checkedAccessibility: boolean = false;+ selectedRoles: Array<string> = [];+ selectedLibraries: Array<number> = [];+ emailLink: string = '';++ public get email() { return this.inviteForm.get('email'); }++ constructor(public modal: NgbActiveModal, private accountService: AccountService, private serverService: ServerService,+ private confirmService: ConfirmService) { }++ ngOnInit(): void {+ this.inviteForm.addControl('email', new FormControl('', [Validators.required]));++ this.serverService.isServerAccessible().subscribe(async (accessibile) => {+ if (!accessibile) {+ await this.confirmService.alert('This server is not accessible outside the network. You cannot invite via Email. You wil be given a link to finish registration with instead.');+ this.accessible = accessibile;+ }+ this.checkedAccessibility = true;+ });+ }++ close() {+ this.modal.close(false);+ }++ invite() {++ this.isSending = true;+ const email = this.inviteForm.get('email')?.value;+ this.accountService.inviteUser({+ email,+ libraries: this.selectedLibraries,+ roles: this.selectedRoles,+ sendEmail: this.accessible+ }).subscribe(email => {+ this.emailLink = email;+ this.isSending = false;+ if (this.accessible) {+ this.modal.close(true);+ }+ }, err => {+ this.isSending = false;+ });+ }++ updateRoleSelection(roles: Array<string>) {+ this.selectedRoles = roles;+ }++ updateLibrarySelection(libraries: Array<Library>) {+ this.selectedLibraries = libraries.map(l => l.id);+ }++}diff --git a/UI/Web/src/app/admin/library-selector/library-selector.component.html b/UI/Web/src/app/admin/library-selector/library-selector.component.htmlnew file mode 100644index 000000000..132ac1750--- /dev/null+++ b/UI/Web/src/app/admin/library-selector/library-selector.component.html@@ -0,0 +1,20 @@+<h4>Libraries</h4>+<div class="list-group" *ngIf="!isLoading">+ <div class="form-check" *ngIf="allLibraries.length > 0">+ <input id="selectall" type="checkbox" class="form-check-input"+ [ngModel]="selectAll" (change)="toggleAll()" [indeterminate]="hasSomeSelected">+ <label for="selectall" class="form-check-label">{{selectAll ? 'Deselect' : 'Select'}} All</label>+ </div>+ <ul>+ <li class="list-group-item" *ngFor="let library of allLibraries; let i = index">+ <div class="form-check">+ <input id="library-{{i}}" type="checkbox" class="form-check-input" attr.aria-label="Library {{library.name}}"+ [ngModel]="selections.isSelected(library)" (change)="handleSelection(library)">+ <label attr.for="library-{{i}}" class="form-check-label">{{library.name}}</label>+ </div>+ </li>+ <li class="list-group-item" *ngIf="allLibraries.length === 0">+ There are no libraries setup yet.+ </li>+ </ul>+</div>\ No newline at end of filediff --git a/UI/Web/src/app/admin/library-selector/library-selector.component.scss b/UI/Web/src/app/admin/library-selector/library-selector.component.scssnew file mode 100644index 000000000..3f2adc8d1--- /dev/null+++ b/UI/Web/src/app/admin/library-selector/library-selector.component.scss@@ -0,0 +1,3 @@+.list-group-item {+ border: none;+}\ No newline at end of filediff --git a/UI/Web/src/app/admin/library-selector/library-selector.component.ts b/UI/Web/src/app/admin/library-selector/library-selector.component.tsnew file mode 100644index 000000000..c7172ced6--- /dev/null+++ b/UI/Web/src/app/admin/library-selector/library-selector.component.ts@@ -0,0 +1,71 @@+import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';+import { FormBuilder } from '@angular/forms';+import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';+import { SelectionModel } from 'src/app/typeahead/typeahead.component';+import { Library } from 'src/app/_models/library';+import { Member } from 'src/app/_models/member';+import { LibraryService } from 'src/app/_services/library.service';++@Component({+ selector: 'app-library-selector',+ templateUrl: './library-selector.component.html',+ styleUrls: ['./library-selector.component.scss']+})+export class LibrarySelectorComponent implements OnInit {++ @Input() member: Member | undefined;+ @Output() selected: EventEmitter<Array<Library>> = new EventEmitter<Array<Library>>();++ allLibraries: Library[] = [];+ selectedLibraries: Array<{selected: boolean, data: Library}> = [];+ selections!: SelectionModel<Library>;+ selectAll: boolean = false;+ isLoading: boolean = false;++ get hasSomeSelected() {+ return this.selections != null && this.selections.hasSomeSelected();+ }++ constructor(private libraryService: LibraryService, private fb: FormBuilder) { }++ ngOnInit(): void {+ this.libraryService.getLibraries().subscribe(libs => {+ this.allLibraries = libs;+ this.setupSelections();+ });+ }+++ setupSelections() {+ this.selections = new SelectionModel<Library>(false, this.allLibraries);+ this.isLoading = false;++ // If a member is passed in, then auto-select their libraries+ if (this.member !== undefined) {+ this.member.libraries.forEach(lib => {+ this.selections.toggle(lib, true, (a, b) => a.name === b.name);+ });+ this.selectAll = this.selections.selected().length === this.allLibraries.length;+ this.selected.emit(this.selections.selected());+ }+ }++ toggleAll() {+ this.selectAll = !this.selectAll;+ this.allLibraries.forEach(s => this.selections.toggle(s, this.selectAll));+ this.selected.emit(this.selections.selected());+ }++ handleSelection(item: Library) {+ this.selections.toggle(item);+ const numberOfSelected = this.selections.selected().length;+ if (numberOfSelected == 0) {+ this.selectAll = false;+ } else if (numberOfSelected == this.selectedLibraries.length) {+ this.selectAll = true;+ }++ this.selected.emit(this.selections.selected());+ }++}diff --git a/UI/Web/src/app/admin/manage-users/manage-users.component.html b/UI/Web/src/app/admin/manage-users/manage-users.component.htmlindex 5b6ce57b9..76cdd8747 100644--- a/UI/Web/src/app/admin/manage-users/manage-users.component.html+++ b/UI/Web/src/app/admin/manage-users/manage-users.component.html@@ -1,19 +1,53 @@<div class="container-fluid">- <div class="row mb-2">- <div class="col-8"><h3>Users</h3></div>- <div class="col-4"><button class="btn btn-primary float-right" (click)="createMember()"><i class="fa fa-plus" aria-hidden="true"></i><span class="phone-hidden"> Add User</span></button></div>- </div>- <ul class="list-group" *ngIf="!createMemberToggle; else createUser">+ <ng-container>+ <div class="row mb-2">+ <div class="col-8"><h3>Pending Invites</h3></div>+ <div class="col-4"><button class="btn btn-primary float-right" (click)="inviteUser()"><i class="fa fa-plus" aria-hidden="true"></i><span class="phone-hidden"> Invite</span></button></div>+ </div>+ <ul class="list-group">+ <li class="list-group-item" *ngFor="let invite of pendingInvites; let idx = index;">+ <div>+ <h4>+ <span id="member-name--{{idx}}">{{invite.username | titlecase}} </span>+ <div class="float-right">+ <button class="btn btn-danger mr-2" (click)="deleteUser(invite)">Cancel</button>+ <button class="btn btn-secondary mr-2" (click)="resendEmail(invite)">Resend</button>+ </div>+ </h4>++ <div>Invited: {{invite.created | date: 'short'}}</div>+ </div>+ </li>+ <li *ngIf="loadingMembers" class="list-group-item">+ <div class="spinner-border text-secondary" role="status">+ <span class="invisible">Loading...</span>+ </div>+ </li>+ <li class="list-group-item" *ngIf="pendingInvites.length === 0 && !loadingMembers">+ There are no invited Users+ </li>+ </ul>+ </ng-container>++++ <h3 class="mt-3">Active Users</h3>+ <ul class="list-group"><li *ngFor="let member of members; let idx = index;" class="list-group-item"><div><h4>- <i class="presence fa fa-circle" title="Active" aria-hidden="true" *ngIf="false && (messageHub.onlineUsers$ | async)?.includes(member.username)"></i><span id="member-name--{{idx}}">{{member.username | titlecase}} </span><span *ngIf="member.username === loggedInUsername">(You)</span>+ <i class="presence fa fa-circle" title="Active" aria-hidden="true" *ngIf="false && (messageHub.onlineUsers$ | async)?.includes(member.username)"></i>+ <span id="member-name--{{idx}}">{{member.username | titlecase}} </span>+ <span *ngIf="member.username === loggedInUsername">+ <i class="fas fa-star" aria-hidden="true"></i>+ <span class="sr-only">(You)</span>+ </span><div class="float-right" *ngIf="canEditMember(member)"><button class="btn btn-danger mr-2" (click)="deleteUser(member)" placement="top" ngbTooltip="Delete User" attr.aria-label="Delete User {{member.username | titlecase}}"><i class="fa fa-trash" aria-hidden="true"></i></button><button class="btn btn-secondary mr-2" (click)="updatePassword(member)" placement="top" ngbTooltip="Change Password" attr.aria-label="Change Password for {{member.username | titlecase}}"><i class="fa fa-key" aria-hidden="true"></i></button>- <button class="btn btn-primary" (click)="openEditLibraryAccess(member)" placement="top" ngbTooltip="Edit" attr.aria-label="Edit {{member.username | titlecase}}"><i class="fa fa-pen" aria-hidden="true"></i></button>+ <button class="btn btn-primary" (click)="openEditUser(member)" placement="top" ngbTooltip="Edit" attr.aria-label="Edit {{member.username | titlecase}}"><i class="fa fa-pen" aria-hidden="true"></i></button></div></h4><div>Last Active:@@ -44,7 +78,4 @@There are no other users.</li></ul>- <ng-template #createUser>- <app-register-member (created)="onMemberCreated($event)"></app-register-member>- </ng-template></div>\ No newline at end of filediff --git a/UI/Web/src/app/admin/manage-users/manage-users.component.ts b/UI/Web/src/app/admin/manage-users/manage-users.component.tsindex c1982f130..1dc25ce53 100644--- a/UI/Web/src/app/admin/manage-users/manage-users.component.ts+++ b/UI/Web/src/app/admin/manage-users/manage-users.component.ts@@ -5,13 +5,15 @@ import { MemberService } from 'src/app/_services/member.service';import { Member } from 'src/app/_models/member';import { User } from 'src/app/_models/user';import { AccountService } from 'src/app/_services/account.service';-import { LibraryAccessModalComponent } from '../_modals/library-access-modal/library-access-modal.component';import { ToastrService } from 'ngx-toastr';import { ResetPasswordModalComponent } from '../_modals/reset-password-modal/reset-password-modal.component';import { ConfirmService } from 'src/app/shared/confirm.service';import { EditRbsModalComponent } from '../_modals/edit-rbs-modal/edit-rbs-modal.component';import { Subject } from 'rxjs';import { MessageHubService } from 'src/app/_services/message-hub.service';+import { InviteUserComponent } from '../invite-user/invite-user.component';+import { EditUserComponent } from '../edit-user/edit-user.component';+import { ServerService } from 'src/app/_services/server.service';@Component({selector: 'app-manage-users',@@ -21,10 +23,8 @@ import { MessageHubService } from 'src/app/_services/message-hub.service';export class ManageUsersComponent implements OnInit, OnDestroy {members: Member[] = [];+ pendingInvites: Member[] = [];loggedInUsername = '';-- // Create User functionality- createMemberToggle = false;loadingMembers = false;private onDestroy = new Subject<void>();@@ -34,7 +34,8 @@ export class ManageUsersComponent implements OnInit, OnDestroy {private modalService: NgbModal,private toastr: ToastrService,private confirmService: ConfirmService,- public messageHub: MessageHubService) {+ public messageHub: MessageHubService,+ private serverService: ServerService) {this.accountService.currentUser$.pipe(take(1)).subscribe((user: User) => {this.loggedInUsername = user.username;});@@ -43,6 +44,8 @@ export class ManageUsersComponent implements OnInit, OnDestroy {ngOnInit(): void {this.loadMembers();++ this.loadPendingInvites();}ngOnDestroy() {@@ -69,31 +72,41 @@ export class ManageUsersComponent implements OnInit, OnDestroy {});}- canEditMember(member: Member): boolean {- return this.loggedInUsername !== member.username;- }+ loadPendingInvites() {+ this.memberService.getPendingInvites().subscribe(members => {+ this.pendingInvites = members;+ // Show logged in user at the top of the list+ this.pendingInvites.sort((a: Member, b: Member) => {+ if (a.username === this.loggedInUsername) return 1;+ if (b.username === this.loggedInUsername) return 1;- createMember() {- this.createMemberToggle = true;+ const nameA = a.username.toUpperCase();+ const nameB = b.username.toUpperCase();+ if (nameA < nameB) return -1;+ if (nameA > nameB) return 1;+ return 0;+ })+ });}- onMemberCreated(createdUser: User | null) {- this.createMemberToggle = false;- this.loadMembers();+ canEditMember(member: Member): boolean {+ return this.loggedInUsername !== member.username;}- openEditLibraryAccess(member: Member) {- const modalRef = this.modalService.open(LibraryAccessModalComponent);+ openEditUser(member: Member) {+ const modalRef = this.modalService.open(EditUserComponent, {size: 'lg'});modalRef.componentInstance.member = member;modalRef.closed.subscribe(() => {this.loadMembers();});}+async deleteUser(member: Member) {if (await this.confirmService.confirm('Are you sure you want to delete this user?')) {this.memberService.deleteMember(member.username).subscribe(() => {this.loadMembers();+ this.loadPendingInvites();this.toastr.success(member.username + ' has been deleted.');});}@@ -106,7 +119,32 @@ export class ManageUsersComponent implements OnInit, OnDestroy {if (updatedMember !== undefined) {member = updatedMember;}- })+ });+ }++ inviteUser() {+ const modalRef = this.modalService.open(InviteUserComponent, {size: 'lg'});+ modalRef.closed.subscribe((successful: boolean) => {+ if (successful) {+ this.loadPendingInvites();+ }+ });+ }++ resendEmail(member: Member) {++ this.serverService.isServerAccessible().subscribe(canAccess => {+ this.accountService.resendConfirmationEmail(member.id).subscribe(async (email) => {+ if (canAccess) {+ this.toastr.info('Email sent to ' + member.username);+ return;+ }+ await this.confirmService.alert(+ 'Please click this link to confirm your email. You must confirm to be able to login. You may need to log out of the current account before clicking. <br/> <a href="' + email + '" target="_blank">' + email + '</a>');++ });+ });+}updatePassword(member: Member) {diff --git a/UI/Web/src/app/admin/role-selector/role-selector.component.html b/UI/Web/src/app/admin/role-selector/role-selector.component.htmlnew file mode 100644index 000000000..1eb806aab--- /dev/null+++ b/UI/Web/src/app/admin/role-selector/role-selector.component.html@@ -0,0 +1,10 @@+<h4>Roles</h4>+<ul class="list-group">+ <li class="list-group-item" *ngFor="let role of selectedRoles; let i = index">+ <div class="form-check">+ <input id="role-{{i}}" type="checkbox" attr.aria-label="Role {{role.data}}" class="form-check-input"+ [(ngModel)]="role.selected" name="role" (ngModelChange)="handleModelUpdate()">+ <label attr.for="role-{{i}}" class="form-check-label">{{role.data}}</label>+ </div>+ </li>+</ul>\ No newline at end of filediff --git a/UI/Web/src/app/admin/role-selector/role-selector.component.scss b/UI/Web/src/app/admin/role-selector/role-selector.component.scssnew file mode 100644index 000000000..3f2adc8d1--- /dev/null+++ b/UI/Web/src/app/admin/role-selector/role-selector.component.scss@@ -0,0 +1,3 @@+.list-group-item {+ border: none;+}\ No newline at end of filediff --git a/UI/Web/src/app/admin/role-selector/role-selector.component.ts b/UI/Web/src/app/admin/role-selector/role-selector.component.tsnew file mode 100644index 000000000..79b04f70d--- /dev/null+++ b/UI/Web/src/app/admin/role-selector/role-selector.component.ts@@ -0,0 +1,57 @@+import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';+import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';+import { Member } from 'src/app/_models/member';+import { AccountService } from 'src/app/_services/account.service';+import { MemberService } from 'src/app/_services/member.service';++@Component({+ selector: 'app-role-selector',+ templateUrl: './role-selector.component.html',+ styleUrls: ['./role-selector.component.scss']+})+export class RoleSelectorComponent implements OnInit {++ @Input() member: Member | undefined;+ /**+ * Allows the selection of Admin role+ */+ @Input() allowAdmin: boolean = false;+ @Output() selected: EventEmitter<string[]> = new EventEmitter<string[]>();++ allRoles: string[] = [];+ selectedRoles: Array<{selected: boolean, data: string}> = [];++ constructor(public modal: NgbActiveModal, private accountService: AccountService, private memberService: MemberService) { }++ ngOnInit(): void {+ this.accountService.getRoles().subscribe(roles => {+ let bannedRoles = ['Pleb'];+ if (!this.allowAdmin) {+ bannedRoles.push('Admin');+ }+ roles = roles.filter(item => !bannedRoles.includes(item));+ this.allRoles = roles;+ this.selectedRoles = roles.map(item => {+ return {selected: false, data: item};+ });+ this.selected.emit(this.selectedRoles.filter(item => item.selected).map(item => item.data));+ this.preselect();+ });+ }++ preselect() {+ if (this.member !== undefined) {+ this.member.roles.forEach(role => {+ const foundRole = this.selectedRoles.filter(item => item.data === role);+ if (foundRole.length > 0) {+ foundRole[0].selected = true;+ }+ });+ }+ }++ handleModelUpdate() {+ this.selected.emit(this.selectedRoles.filter(item => item.selected).map(item => item.data));+ }++}diff --git a/UI/Web/src/app/app-routing.module.ts b/UI/Web/src/app/app-routing.module.tsindex 7f8bd88f7..87eb0cfba 100644--- a/UI/Web/src/app/app-routing.module.ts+++ b/UI/Web/src/app/app-routing.module.ts@@ -65,7 +65,11 @@ const routes: Routes = []},- {path: 'login', component: UserLoginComponent},+ {+ path: 'registration',+ loadChildren: () => import('../app/registration/registration.module').then(m => m.RegistrationModule)+ },+ {path: 'login', component: UserLoginComponent}, // TODO: move this to registration module{path: 'no-connection', component: NotConnectedComponent},{path: '**', component: UserLoginComponent, pathMatch: 'full'}];diff --git a/UI/Web/src/app/nav-header/nav-header.component.html b/UI/Web/src/app/nav-header/nav-header.component.htmlindex d2e99de03..f12c58494 100644--- a/UI/Web/src/app/nav-header/nav-header.component.html+++ b/UI/Web/src/app/nav-header/nav-header.component.html@@ -1,7 +1,7 @@<nav class="navbar navbar-expand-md navbar-dark fixed-top" *ngIf="navService?.navbarVisible$ | async"><div class="container-fluid"><a class="sr-only sr-only-focusable focus-visible" href="javascript:void(0);" (click)="moveFocus()">Skip to main content</a>- <a class="navbar-brand" routerLink="/library" routerLinkActive="active"><img class="logo" src="../../assets/images/logo.png" alt="kavita icon" aria-hidden="true"/><span class="phone-hidden"> Kavita</span></a>+ <a class="navbar-brand dark-exempt" routerLink="/library" routerLinkActive="active"><img class="logo" src="../../assets/images/logo.png" alt="kavita icon" aria-hidden="true"/><span class="phone-hidden"> Kavita</span></a><ul class="navbar-nav col mr-auto"><div class="nav-item" *ngIf="(accountService.currentUser$ | async) as user">@@ -62,17 +62,25 @@</button></div>- <div class="nav-item" *ngIf="(accountService.currentUser$ | async) as user">- <app-nav-events-toggle [user]="user"></app-nav-events-toggle>- </div>+ <ng-container *ngIf="(accountService.currentUser$ | async) as user">+ <div class="nav-item">+ <app-nav-events-toggle [user]="user"></app-nav-events-toggle>+ </div>+ <div class="nav-item pr-2">+ <a routerLink="/admin/dashboard" *ngIf="user.roles.includes('Admin')" class="dark-exempt" style="padding: 5px">+ <i class="fa fa-cogs" aria-hidden="true" style="color: white"></i>+ <span class="sr-only">Server Settings</span>+ </a>+ </div>+ </ng-container>+<div ngbDropdown class="nav-item dropdown" display="dynamic" placement="bottom-right" *ngIf="(accountService.currentUser$ | async) as user" dropdown><button class="btn btn-outline-secondary primary-text" ngbDropdownToggle>{{user.username | sentenceCase}}</button><div ngbDropdownMenu>- <a ngbDropdownItem routerLink="/preferences/">User Settings</a>- <a ngbDropdownItem routerLink="/admin/dashboard" *ngIf="user.roles.includes('Admin')">Server Settings</a>+ <a ngbDropdownItem routerLink="/preferences/">Settings</a><a ngbDropdownItem (click)="logout()">Logout</a></div></div>diff --git a/UI/Web/src/app/register-member/register-member.component.html b/UI/Web/src/app/register-member/register-member.component.htmldeleted file mode 100644index 5b757f889..000000000--- a/UI/Web/src/app/register-member/register-member.component.html+++ /dev/null@@ -1,32 +0,0 @@--<div class="text-danger" *ngIf="errors.length > 0">- <p>Errors:</p>- <ul>- <li *ngFor="let error of errors">{{error}}</li>- </ul>-</div>-<form [formGroup]="registerForm" (ngSubmit)="register()">- <div class="form-group">- <label for="username">Username</label>- <input id="username" class="form-control" formControlName="username" type="text">- </div>-- <div class="form-group" *ngIf="registerForm.get('isAdmin')?.value || !authDisabled">- <label for="password">Password</label> <i class="fa fa-info-circle" placement="right" [ngbTooltip]="passwordTooltip" role="button" tabindex="0"></i>- <ng-template #passwordTooltip>- Password must be between 6 and 32 characters in length- </ng-template>- <span class="sr-only" id="password-help"><ng-container [ngTemplateOutlet]="passwordTooltip"></ng-container></span>- <input id="password" class="form-control" formControlName="password" type="password" aria-describedby="password-help">- </div>-- <div class="form-check" *ngIf="!firstTimeFlow">- <input id="admin" type="checkbox" aria-label="Admin" class="form-check-input" formControlName="isAdmin">- <label for="admin" class="form-check-label">Admin</label>- </div>-- <div class="float-right">- <button class="btn btn-secondary mr-2" type="button" (click)="cancel()" *ngIf="!firstTimeFlow">Cancel</button>- <button class="btn btn-primary {{firstTimeFlow ? 'alt' : ''}}" type="submit">Register</button>- </div>-</form>diff --git a/UI/Web/src/app/register-member/register-member.component.scss b/UI/Web/src/app/register-member/register-member.component.scssdeleted file mode 100644index 5fc352dbb..000000000--- a/UI/Web/src/app/register-member/register-member.component.scss+++ /dev/null@@ -1,18 +0,0 @@-.alt {- background-color: #424c72;- border-color: #444f75;-}--.alt:hover {- background-color: #3b4466;-}--.alt:focus {- background-color: #343c59;- box-shadow: 0 0 0 0.2rem rgb(68 79 117 / 50%);-}--input {- background-color: #fff !important;- color: black !important;-}\ No newline at end of filediff --git a/UI/Web/src/app/register-member/register-member.component.ts b/UI/Web/src/app/register-member/register-member.component.tsdeleted file mode 100644index 8a705700c..000000000--- a/UI/Web/src/app/register-member/register-member.component.ts+++ /dev/null@@ -1,54 +0,0 @@-import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';-import { FormGroup, FormControl, Validators } from '@angular/forms';-import { take } from 'rxjs/operators';-import { AccountService } from 'src/app/_services/account.service';-import { SettingsService } from '../admin/settings.service';-import { User } from '../_models/user';--@Component({- selector: 'app-register-member',- templateUrl: './register-member.component.html',- styleUrls: ['./register-member.component.scss']-})-export class RegisterMemberComponent implements OnInit {-- @Input() firstTimeFlow = false;- /**- * Emits the new user created.- */- @Output() created = new EventEmitter<User | null>();-- adminExists = false;- authDisabled: boolean = false;- registerForm: FormGroup = new FormGroup({- username: new FormControl('', [Validators.required]),- password: new FormControl('', []),- isAdmin: new FormControl(false, [])- });- errors: string[] = [];-- constructor(private accountService: AccountService, private settingsService: SettingsService) {- }-- ngOnInit(): void {- this.settingsService.getAuthenticationEnabled().pipe(take(1)).subscribe(authEnabled => {- this.authDisabled = !authEnabled;- });- if (this.firstTimeFlow) {- this.registerForm.get('isAdmin')?.setValue(true);- }- }-- register() {- this.accountService.register(this.registerForm.value).subscribe(user => {- this.created.emit(user);- }, err => {- this.errors = err;- });- }-- cancel() {- this.created.emit(null);- }--}diff --git a/UI/Web/src/app/registration/add-email-to-account-migration-modal/add-email-to-account-migration-modal.component.html b/UI/Web/src/app/registration/add-email-to-account-migration-modal/add-email-to-account-migration-modal.component.htmlnew file mode 100644index 000000000..ac5bb349f--- /dev/null+++ b/UI/Web/src/app/registration/add-email-to-account-migration-modal/add-email-to-account-migration-modal.component.html@@ -0,0 +1,55 @@+<div class="modal-header">+ <h4 class="modal-title" id="modal-basic-title">Account Migration</h4>+ <button type="button" class="close" aria-label="Close" (click)="close()">+ <span aria-hidden="true">×</span>+ </button>+</div>+<div class="modal-body">+ <p>Your account does not have an email on file. This is a one-time migration. Please add your email to the account. A verficiation link will be sent to your email for you+ to confirm and will then be allowed to authenticate with this server. This is required.+ </p>+ <form [formGroup]="registerForm">+ <div class="form-group">+ <label for="username">Username</label>+ <input id="username" class="form-control" formControlName="username" type="text">+ <div id="inviteForm-validations" class="invalid-feedback" *ngIf="registerForm.dirty || registerForm.touched">+ <div *ngIf="registerForm.get('username')?.errors?.required">+ This field is required+ </div>+ </div>+ </div>++ <div class="form-group" style="width:100%">+ <label for="email">Email</label>+ <input class="form-control" type="email" id="email" formControlName="email" required>+ <div id="inviteForm-validations" class="invalid-feedback" *ngIf="registerForm.dirty || registerForm.touched">+ <div *ngIf="registerForm.get('email')?.errors?.required">+ This field is required+ </div>+ <div *ngIf="registerForm.get('email')?.errors?.email">+ This must be a valid email address+ </div>+ </div>+ </div>++ <div class="form-group">+ <label for="password">Password</label>+ <input id="password" class="form-control" maxlength="32" minlength="6" formControlName="password" type="password" aria-describedby="password-help">+ <div id="inviteForm-validations" class="invalid-feedback" *ngIf="registerForm.dirty || registerForm.touched">+ <div *ngIf="registerForm.get('password')?.errors?.required">+ This field is required+ </div>+ </div>+ </div>+ </form>++</div>+<div class="modal-footer">+ <button type="button" class="btn btn-secondary" (click)="close()">+ Cancel+ </button>+ <button type="button" class="btn btn-primary" (click)="save()" [disabled]="isSaving || !registerForm.valid">+ <span *ngIf="isSaving" class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>+ <span>Submit</span>+ </button>+</div>diff --git a/UI/Web/src/app/registration/add-email-to-account-migration-modal/add-email-to-account-migration-modal.component.scss b/UI/Web/src/app/registration/add-email-to-account-migration-modal/add-email-to-account-migration-modal.component.scssnew file mode 100644index 000000000..e69de29bbdiff --git a/UI/Web/src/app/registration/add-email-to-account-migration-modal/add-email-to-account-migration-modal.component.ts b/UI/Web/src/app/registration/add-email-to-account-migration-modal/add-email-to-account-migration-modal.component.tsnew file mode 100644index 000000000..279c7f523--- /dev/null+++ b/UI/Web/src/app/registration/add-email-to-account-migration-modal/add-email-to-account-migration-modal.component.ts@@ -0,0 +1,60 @@+import { Component, Input, OnInit } from '@angular/core';+import { FormControl, FormGroup, Validators } from '@angular/forms';+import { SafeUrl } from '@angular/platform-browser';+import { ActivatedRoute, Router } from '@angular/router';+import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';+import { ToastrService } from 'ngx-toastr';+import { ConfirmService } from 'src/app/shared/confirm.service';+import { AccountService } from 'src/app/_services/account.service';+import { MemberService } from 'src/app/_services/member.service';+import { ServerService } from 'src/app/_services/server.service';++@Component({+ selector: 'app-add-email-to-account-migration-modal',+ templateUrl: './add-email-to-account-migration-modal.component.html',+ styleUrls: ['./add-email-to-account-migration-modal.component.scss']+})+export class AddEmailToAccountMigrationModalComponent implements OnInit {++ @Input() username!: string;+ @Input() password!: string;++ isSaving: boolean = false;+ registerForm: FormGroup = new FormGroup({});+ emailLink: string = '';+ emailLinkUrl: SafeUrl | undefined;++ constructor(private accountService: AccountService, private modal: NgbActiveModal,+ private serverService: ServerService, private confirmService: ConfirmService) {+ }++ ngOnInit(): void {+ this.registerForm.addControl('username', new FormControl(this.username, [Validators.required]));+ this.registerForm.addControl('email', new FormControl('', [Validators.required, Validators.email]));+ this.registerForm.addControl('password', new FormControl(this.password, [Validators.required]));+ }++ close() {+ this.modal.close(false);+ }++ save() {+ this.serverService.isServerAccessible().subscribe(canAccess => {+ const model = this.registerForm.getRawValue();+ model.sendEmail = canAccess;+ this.accountService.migrateUser(model).subscribe(async (email) => {+ if (!canAccess) {+ // Display the email to the user+ this.emailLink = email;+ await this.confirmService.alert('Please click this link to confirm your email. You must confirm to be able to login. You may need to log out of the current account before clicking. <br/> <a href="' + this.emailLink + '" target="_blank">' + this.emailLink + '</a>');+ } else {+ await this.confirmService.alert('Please check your email for the confirmation link. You must confirm to be able to login.');+ }+ });+ });++ }++++}diff --git a/UI/Web/src/app/registration/confirm-email/confirm-email.component.html b/UI/Web/src/app/registration/confirm-email/confirm-email.component.htmlnew file mode 100644index 000000000..ed7852b8c--- /dev/null+++ b/UI/Web/src/app/registration/confirm-email/confirm-email.component.html@@ -0,0 +1,58 @@+<!--+<div class="text-danger" *ngIf="errors.length > 0">+ <p>Errors:</p>+ <ul>+ <li *ngFor="let error of errors">{{error}}</li>+ </ul>+</div> -->+<app-splash-container>+ <ng-container title><h2>Register</h2></ng-container>+ <ng-container body>+ <p>Complete the form to complete your registration</p>+ <form [formGroup]="registerForm" (ngSubmit)="submit()">+ <div class="form-group">+ <label for="username">Username</label>+ <input id="username" class="form-control" formControlName="username" type="text">+ <div id="inviteForm-validations" class="invalid-feedback" *ngIf="registerForm.dirty || registerForm.touched">+ <div *ngIf="registerForm.get('username')?.errors?.required">+ This field is required+ </div>+ </div>+ </div>++ <div class="form-group" style="width:100%">+ <label for="email">Email</label>+ <input class="form-control" type="email" id="email" formControlName="email" required>+ <div id="inviteForm-validations" class="invalid-feedback" *ngIf="registerForm.dirty || registerForm.touched">+ <div *ngIf="registerForm.get('email')?.errors?.required">+ This field is required+ </div>+ <div *ngIf="registerForm.get('email')?.errors?.email">+ This must be a valid email address+ </div>+ </div>+ </div>++ <div class="form-group">+ <label for="password">Password</label> <i class="fa fa-info-circle" placement="right" [ngbTooltip]="passwordTooltip" role="button" tabindex="0"></i>+ <ng-template #passwordTooltip>+ Password must be between 6 and 32 characters in length+ </ng-template>+ <span class="sr-only" id="password-help"><ng-container [ngTemplateOutlet]="passwordTooltip"></ng-container></span>+ <input id="password" class="form-control" maxlength="32" minlength="6" formControlName="password" type="password" aria-describedby="password-help">+ <div id="inviteForm-validations" class="invalid-feedback" *ngIf="registerForm.dirty || registerForm.touched">+ <div *ngIf="registerForm.get('password')?.errors?.required">+ This field is required+ </div>+ <div *ngIf="registerForm.get('password')?.errors?.minlength || registerForm.get('password')?.errors?.maxLength">+ Password must be between 6 and 32 characters in length+ </div>+ </div>+ </div>++ <div class="float-right">+ <button class="btn btn-secondary alt" type="submit">Register</button>+ </div>+ </form>+ </ng-container>+</app-splash-container>diff --git a/UI/Web/src/app/registration/confirm-email/confirm-email.component.scss b/UI/Web/src/app/registration/confirm-email/confirm-email.component.scssnew file mode 100644index 000000000..b3a96fcce--- /dev/null+++ b/UI/Web/src/app/registration/confirm-email/confirm-email.component.scss@@ -0,0 +1,4 @@+input {+ background-color: #fff !important;+ color: black;+}\ No newline at end of filediff --git a/UI/Web/src/app/registration/confirm-email/confirm-email.component.ts b/UI/Web/src/app/registration/confirm-email/confirm-email.component.tsnew file mode 100644index 000000000..cd82cf417--- /dev/null+++ b/UI/Web/src/app/registration/confirm-email/confirm-email.component.ts@@ -0,0 +1,60 @@+import { Component, Input, OnInit } from '@angular/core';+import { FormControl, FormGroup, Validators } from '@angular/forms';+import { ActivatedRoute, Router } from '@angular/router';+import { ToastrService } from 'ngx-toastr';+import { AccountService } from 'src/app/_services/account.service';++@Component({+ selector: 'app-confirm-email',+ templateUrl: './confirm-email.component.html',+ styleUrls: ['./confirm-email.component.scss']+})+export class ConfirmEmailComponent implements OnInit {+++ /**+ * Email token used for validating+ */+ token: string = '';++ registerForm: FormGroup = new FormGroup({+ email: new FormControl('', [Validators.required, Validators.email]),+ username: new FormControl('', [Validators.required]),+ password: new FormControl('', [Validators.required, Validators.maxLength(32), Validators.minLength(6)]),+ });++ /**+ * Validation errors from API+ */+ errors: Array<string> = [];+++ constructor(private route: ActivatedRoute, private router: Router, private accountService: AccountService, private toastr: ToastrService) {++ const token = this.route.snapshot.queryParamMap.get('token');+ const email = this.route.snapshot.queryParamMap.get('email');+ if (token == undefined || token === '' || token === null) {+ // This is not a valid url, redirect to login+ this.toastr.error('Invalid confirmation email');+ this.router.navigateByUrl('login');+ return;+ }+ this.token = token;+ this.registerForm.get('email')?.setValue(email || '');+ }++ ngOnInit(): void {+ }++ submit() {+ let model = this.registerForm.getRawValue();+ model.token = this.token;+ this.accountService.confirmEmail(model).subscribe((user) => {+ this.toastr.success('Account registration complete');+ this.router.navigateByUrl('login');+ }, err => {+ this.errors = err;+ });+ }++}diff --git a/UI/Web/src/app/registration/confirm-migration-email/confirm-migration-email.component.html b/UI/Web/src/app/registration/confirm-migration-email/confirm-migration-email.component.htmlnew file mode 100644index 000000000..e69de29bbdiff --git a/UI/Web/src/app/registration/confirm-migration-email/confirm-migration-email.component.scss b/UI/Web/src/app/registration/confirm-migration-email/confirm-migration-email.component.scssnew file mode 100644index 000000000..e69de29bbdiff --git a/UI/Web/src/app/registration/confirm-migration-email/confirm-migration-email.component.ts b/UI/Web/src/app/registration/confirm-migration-email/confirm-migration-email.component.tsnew file mode 100644index 000000000..554dd9d30--- /dev/null+++ b/UI/Web/src/app/registration/confirm-migration-email/confirm-migration-email.component.ts@@ -0,0 +1,34 @@+import { Component, OnInit } from '@angular/core';+import { ActivatedRoute, Router } from '@angular/router';+import { ToastrService } from 'ngx-toastr';+import { AccountService } from 'src/app/_services/account.service';++@Component({+ selector: 'app-confirm-migration-email',+ templateUrl: './confirm-migration-email.component.html',+ styleUrls: ['./confirm-migration-email.component.scss']+})+export class ConfirmMigrationEmailComponent implements OnInit {++ constructor(private route: ActivatedRoute, private router: Router, private accountService: AccountService, private toastr: ToastrService) {++ const token = this.route.snapshot.queryParamMap.get('token');+ const email = this.route.snapshot.queryParamMap.get('email');+ if (token === undefined || token === '' || token === null || email === undefined || email === '' || email === null) {+ // This is not a valid url, redirect to login+ this.toastr.error('Invalid confirmation email');+ this.router.navigateByUrl('login');+ return;+ }+ this.accountService.confirmMigrationEmail({token: token, email}).subscribe((user) => {+ this.toastr.success('Account migration complete');+ this.router.navigateByUrl('login');+ });++ }+++ ngOnInit(): void {+ }++}diff --git a/UI/Web/src/app/registration/register/register.component.html b/UI/Web/src/app/registration/register/register.component.htmlnew file mode 100644index 000000000..d6e4c987d--- /dev/null+++ b/UI/Web/src/app/registration/register/register.component.html@@ -0,0 +1,58 @@+<!--+<div class="text-danger" *ngIf="errors.length > 0">+ <p>Errors:</p>+ <ul>+ <li *ngFor="let error of errors">{{error}}</li>+ </ul>+</div> -->+<app-splash-container>+ <ng-container title><h2>Register</h2></ng-container>+ <ng-container body>+ <p>Complete the form to register an admin account</p>+ <form [formGroup]="registerForm" (ngSubmit)="submit()">+ <div class="form-group">+ <label for="username">Username</label>+ <input id="username" class="form-control" formControlName="username" type="text">+ <div id="inviteForm-validations" class="invalid-feedback" *ngIf="registerForm.dirty || registerForm.touched">+ <div *ngIf="registerForm.get('username')?.errors?.required">+ This field is required+ </div>+ </div>+ </div>++ <div class="form-group" style="width:100%">+ <label for="email">Email</label>+ <input class="form-control" type="email" id="email" formControlName="email" required>+ <div id="inviteForm-validations" class="invalid-feedback" *ngIf="registerForm.dirty || registerForm.touched">+ <div *ngIf="registerForm.get('email')?.errors?.required">+ This field is required+ </div>+ <div *ngIf="registerForm.get('email')?.errors?.email">+ This must be a valid email address+ </div>+ </div>+ </div>++ <div class="form-group">+ <label for="password">Password</label> <i class="fa fa-info-circle" placement="right" [ngbTooltip]="passwordTooltip" role="button" tabindex="0"></i>+ <ng-template #passwordTooltip>+ Password must be between 6 and 32 characters in length+ </ng-template>+ <span class="sr-only" id="password-help"><ng-container [ngTemplateOutlet]="passwordTooltip"></ng-container></span>+ <input id="password" class="form-control" maxlength="32" minlength="6" formControlName="password" type="password" aria-describedby="password-help">+ <div id="inviteForm-validations" class="invalid-feedback" *ngIf="registerForm.dirty || registerForm.touched">+ <div *ngIf="registerForm.get('password')?.errors?.required">+ This field is required+ </div>+ <div *ngIf="registerForm.get('password')?.errors?.minlength || registerForm.get('password')?.errors?.maxLength">+ Password must be between 6 and 32 characters in length+ </div>+ </div>+ </div>++ <div class="float-right">+ <button class="btn btn-secondary alt" type="submit">Register</button>+ </div>+ </form>+ </ng-container>+</app-splash-container>diff --git a/UI/Web/src/app/registration/register/register.component.scss b/UI/Web/src/app/registration/register/register.component.scssnew file mode 100644index 000000000..b3a96fcce--- /dev/null+++ b/UI/Web/src/app/registration/register/register.component.scss@@ -0,0 +1,4 @@+input {+ background-color: #fff !important;+ color: black;+}\ No newline at end of filediff --git a/UI/Web/src/app/registration/register/register.component.ts b/UI/Web/src/app/registration/register/register.component.tsnew file mode 100644index 000000000..9cf3f4443--- /dev/null+++ b/UI/Web/src/app/registration/register/register.component.ts@@ -0,0 +1,46 @@+import { Component, OnInit } from '@angular/core';+import { FormGroup, FormControl, Validators } from '@angular/forms';+import { ActivatedRoute, Router } from '@angular/router';+import { ToastrService } from 'ngx-toastr';+import { take } from 'rxjs/operators';+import { AccountService } from 'src/app/_services/account.service';+import { MemberService } from 'src/app/_services/member.service';++/**+ * This is exclusivly used to register the first user on the server and nothing else+ */+@Component({+ selector: 'app-register',+ templateUrl: './register.component.html',+ styleUrls: ['./register.component.scss']+})+export class RegisterComponent implements OnInit {++ registerForm: FormGroup = new FormGroup({+ email: new FormControl('', [Validators.required, Validators.email]),+ username: new FormControl('', [Validators.required]),+ password: new FormControl('', [Validators.required, Validators.maxLength(32), Validators.minLength(6)]),+ });++ constructor(private route: ActivatedRoute, private router: Router, private accountService: AccountService, private toastr: ToastrService, private memberService: MemberService) {+ this.memberService.adminExists().pipe(take(1)).subscribe(adminExists => {+ if (adminExists) {+ this.router.navigateByUrl('login');+ }+ });+ }++ ngOnInit(): void {+ }++ submit() {+ const model = this.registerForm.getRawValue();+ this.accountService.register(model).subscribe((user) => {+ this.toastr.success('Account registration complete');+ this.router.navigateByUrl('login');+ }, err => {+ // TODO: Handle errors+ });+ }++}diff --git a/UI/Web/src/app/registration/registration.module.ts b/UI/Web/src/app/registration/registration.module.tsnew file mode 100644index 000000000..91f5dc3df--- /dev/null+++ b/UI/Web/src/app/registration/registration.module.ts@@ -0,0 +1,29 @@+import { NgModule } from '@angular/core';+import { CommonModule } from '@angular/common';+import { ConfirmEmailComponent } from './confirm-email/confirm-email.component';+import { RegistrationRoutingModule } from './registration.router.module';+import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';+import { ReactiveFormsModule } from '@angular/forms';+import { SplashContainerComponent } from './splash-container/splash-container.component';+import { RegisterComponent } from './register/register.component';+import { AddEmailToAccountMigrationModalComponent } from './add-email-to-account-migration-modal/add-email-to-account-migration-modal.component';+import { ConfirmMigrationEmailComponent } from './confirm-migration-email/confirm-migration-email.component';++++@NgModule({+ declarations: [+ ConfirmEmailComponent,+ SplashContainerComponent,+ RegisterComponent,+ AddEmailToAccountMigrationModalComponent,+ ConfirmMigrationEmailComponent+ ],+ imports: [+ CommonModule,+ RegistrationRoutingModule,+ NgbTooltipModule,+ ReactiveFormsModule+ ]+})+export class RegistrationModule { }diff --git a/UI/Web/src/app/registration/registration.router.module.ts b/UI/Web/src/app/registration/registration.router.module.tsnew file mode 100644index 000000000..688b43d70--- /dev/null+++ b/UI/Web/src/app/registration/registration.router.module.ts@@ -0,0 +1,27 @@+import { NgModule } from '@angular/core';+import { Routes, RouterModule } from '@angular/router';+import { ConfirmEmailComponent } from './confirm-email/confirm-email.component';+import { ConfirmMigrationEmailComponent } from './confirm-migration-email/confirm-migration-email.component';+import { RegisterComponent } from './register/register.component';++const routes: Routes = [+ {+ path: 'confirm-email',+ component: ConfirmEmailComponent,+ },+ {+ path: 'confirm-migration-email',+ component: ConfirmMigrationEmailComponent,+ },+ {+ path: 'register',+ component: RegisterComponent,+ }+];+++@NgModule({+ imports: [RouterModule.forChild(routes), ],+ exports: [RouterModule]+})+export class RegistrationRoutingModule { }diff --git a/UI/Web/src/app/registration/splash-container/splash-container.component.html b/UI/Web/src/app/registration/splash-container/splash-container.component.htmlnew file mode 100644index 000000000..04ec3d8c8--- /dev/null+++ b/UI/Web/src/app/registration/splash-container/splash-container.component.html@@ -0,0 +1,20 @@+<div class="mx-auto login">++ <div class="row row-cols-4 row-cols-md-4 row-cols-sm-2 row-cols-xs-2">+ <div class="col align-self-center card p-3 m-3" style="max-width: 12rem;">+ <span>+ <div class="logo-container">+ <h3 class="card-title text-center">+ <ng-content select="[title]"></ng-content>+ </h3>+ </div>+ </span>++ <div class="card-text">+ <ng-content select="[body]"></ng-content>+ </div>+ </div>++ </div>++</div>\ No newline at end of filediff --git a/UI/Web/src/app/registration/splash-container/splash-container.component.scss b/UI/Web/src/app/registration/splash-container/splash-container.component.scssnew file mode 100644index 000000000..ac14abbc4--- /dev/null+++ b/UI/Web/src/app/registration/splash-container/splash-container.component.scss@@ -0,0 +1,85 @@+@use "../../../theme/colors";++.login {+ display: flex;+ align-items: center;+ justify-content: center;+ margin-top: -61px; // To offset the navbar+ height: calc(100vh);+ min-height: 289px;+ position: relative;+ width: 100vw;+ max-width: 100vw;+++ &::before {+ content: "";+ background-image: url('../../../assets/images/login-bg.jpg');+ background-size: cover;+ position: absolute;+ top: 0;+ right: 0;+ bottom: 0;+ opacity: 0.1;+ width: 100%;+ }++ .logo-container {+ .logo {+ display:inline-block;+ height: 50px;+ }+ }++ .row {+ margin-top: 10vh;+ }++ .card {+ background-color: colors.$primary-color;+ color: #fff;+ min-width: 300px;++ &:focus {+ border: 2px solid white;++ }+++ .card-title {+ font-family: 'Spartan', sans-serif;+ font-weight: bold;+ display: inline-block;+ vertical-align: middle;+ width: 280px;+ }++ .card-text {+ font-family: "EBGaramond", "Helvetica Neue", sans-serif;+ }++ .alt {+ background-color: #424c72;+ border-color: #444f75;+ }++ .alt:hover {+ background-color: #3b4466;+ }++ .alt:focus {+ background-color: #343c59;+ box-shadow: 0 0 0 0.2rem rgb(68 79 117 / 50%);+ }+ }+}++.invalid-feedback {+ display: inline-block;+ color: #343c59;+}++input {+ background-color: #fff !important;+ color: black;+}\ No newline at end of filediff --git a/UI/Web/src/app/registration/splash-container/splash-container.component.ts b/UI/Web/src/app/registration/splash-container/splash-container.component.tsnew file mode 100644index 000000000..1be131f78--- /dev/null+++ b/UI/Web/src/app/registration/splash-container/splash-container.component.ts@@ -0,0 +1,15 @@+import { Component, OnInit } from '@angular/core';++@Component({+ selector: 'app-splash-container',+ templateUrl: './splash-container.component.html',+ styleUrls: ['./splash-container.component.scss']+})+export class SplashContainerComponent implements OnInit {++ constructor() { }++ ngOnInit(): void {+ }++}diff --git a/UI/Web/src/app/shared/confirm-dialog/confirm-dialog.component.html b/UI/Web/src/app/shared/confirm-dialog/confirm-dialog.component.htmlindex 7f390dc9e..f18a390c3 100644--- a/UI/Web/src/app/shared/confirm-dialog/confirm-dialog.component.html+++ b/UI/Web/src/app/shared/confirm-dialog/confirm-dialog.component.html@@ -6,7 +6,7 @@<span aria-hidden="true">×</span></button></div>-<div class="modal-body" [innerHtml]="config.content | safeHtml">+<div class="modal-body" style="overflow-x: auto" [innerHtml]="config.content | safeHtml"></div><div class="modal-footer"><div *ngFor="let btn of config.buttons">diff --git a/UI/Web/src/app/shared/shared.module.ts b/UI/Web/src/app/shared/shared.module.tsindex 6ae54f582..d4e3ceedd 100644--- a/UI/Web/src/app/shared/shared.module.ts+++ b/UI/Web/src/app/shared/shared.module.ts@@ -4,7 +4,6 @@ import { ReactiveFormsModule } from '@angular/forms';import { NgbCollapseModule, NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';import { ConfirmDialogComponent } from './confirm-dialog/confirm-dialog.component';import { SafeHtmlPipe } from './safe-html.pipe';-import { RegisterMemberComponent } from '../register-member/register-member.component';import { ReadMoreComponent } from './read-more/read-more.component';import { RouterModule } from '@angular/router';import { DrawerComponent } from './drawer/drawer.component';@@ -21,7 +20,6 @@ import { BadgeExpanderComponent } from './badge-expander/badge-expander.componen@NgModule({declarations: [- RegisterMemberComponent,ConfirmDialogComponent,SafeHtmlPipe,ReadMoreComponent,@@ -45,7 +43,6 @@ import { BadgeExpanderComponent } from './badge-expander/badge-expander.componenNgCircleProgressModule.forRoot(),],exports: [- RegisterMemberComponent,SafeHtmlPipe,SentenceCasePipe,ReadMoreComponent,diff --git a/UI/Web/src/app/user-login/user-login.component.html b/UI/Web/src/app/user-login/user-login.component.htmlindex 226b42057..e3cd003a9 100644--- a/UI/Web/src/app/user-login/user-login.component.html+++ b/UI/Web/src/app/user-login/user-login.component.html@@ -1,14 +1,6 @@<div class="mx-auto login"><ng-container *ngIf="isLoaded">- <div class="display: inline-block" *ngIf="firstTimeFlow">- <h3 class="card-title text-center">Create an Admin Account</h3>- <div class="card p-3">- <p>Please create an admin account for yourself to start your reading journey.</p>- <app-register-member (created)="onAdminCreated($event)" [firstTimeFlow]="firstTimeFlow"></app-register-member>- </div>- </div>-<form [formGroup]="loginForm" (ngSubmit)="login()" novalidate class="needs-validation" *ngIf="!firstTimeFlow"><div class="row row-cols-4 row-cols-md-4 row-cols-sm-2 row-cols-xs-2"><ng-container *ngFor="let member of memberNames">diff --git a/UI/Web/src/app/user-login/user-login.component.ts b/UI/Web/src/app/user-login/user-login.component.tsindex 7ca50dcec..79ffd3b94 100644--- a/UI/Web/src/app/user-login/user-login.component.ts+++ b/UI/Web/src/app/user-login/user-login.component.ts@@ -1,9 +1,11 @@import { Component, OnInit } from '@angular/core';import { FormGroup, FormControl, Validators } from '@angular/forms';import { Router } from '@angular/router';+import { NgbModal } from '@ng-bootstrap/ng-bootstrap';import { ToastrService } from 'ngx-toastr';import { first, take } from 'rxjs/operators';import { SettingsService } from '../admin/settings.service';+import { AddEmailToAccountMigrationModalComponent } from '../registration/add-email-to-account-migration-modal/add-email-to-account-migration-modal.component';import { User } from '../_models/user';import { AccountService } from '../_services/account.service';import { MemberService } from '../_services/member.service';@@ -35,7 +37,7 @@ export class UserLoginComponent implements OnInit {isLoaded: boolean = false;constructor(private accountService: AccountService, private router: Router, private memberService: MemberService,- private toastr: ToastrService, private navService: NavService, private settingsService: SettingsService) { }+ private toastr: ToastrService, private navService: NavService, private settingsService: SettingsService, private modalService: NgbModal) { }ngOnInit(): void {this.navService.showNavBar();@@ -62,6 +64,12 @@ export class UserLoginComponent implements OnInit {} else {this.memberService.adminExists().pipe(take(1)).subscribe(adminExists => {this.firstTimeFlow = !adminExists;++ if (this.firstTimeFlow) {+ this.router.navigateByUrl('registration/register');+ return;+ }+this.setupAuthenticatedLoginFlow();this.isLoaded = true;});@@ -95,7 +103,7 @@ export class UserLoginComponent implements OnInit {}login() {- this.model = {username: this.loginForm.get('username')?.value, password: this.loginForm.get('password')?.value};+ this.model = this.loginForm.getRawValue();this.accountService.login(this.model).subscribe(() => {this.loginForm.reset();this.navService.showNavBar();@@ -109,9 +117,19 @@ export class UserLoginComponent implements OnInit {this.router.navigateByUrl('/library');}}, err => {- this.toastr.error(err.error);+ if (err.error === 'You are missing an email on your account. Please wait while we migrate your account.') {+ // TODO: Implement this flow+ const modalRef = this.modalService.open(AddEmailToAccountMigrationModalComponent, { scrollable: true, size: 'md' });+ modalRef.componentInstance.username = this.model.username;+ modalRef.closed.pipe(take(1)).subscribe(() => {++ });+ } else {+ this.toastr.error(err.error);+ }});+ // TODO: Move this into account service so it always happensthis.accountService.currentUser$.pipe(first(x => (x !== null && x !== undefined && typeof x !== 'undefined'))).subscribe(currentUser => {diff --git a/UI/Web/src/assets/themes/dark.scss b/UI/Web/src/assets/themes/dark.scssindex dfeea5dac..55a56aa2e 100644--- a/UI/Web/src/assets/themes/dark.scss+++ b/UI/Web/src/assets/themes/dark.scss@@ -9,7 +9,7 @@color: $dark-text-color;}- a, .btn-link {+ a:not(.dark-exempt), .btn-link {color: $dark-hover-color;> i {color: $dark-hover-color !important;diff --git a/UI/Web/src/styles.scss b/UI/Web/src/styles.scssindex 03861b498..580091f78 100644--- a/UI/Web/src/styles.scss+++ b/UI/Web/src/styles.scss@@ -52,6 +52,21 @@ body {cursor: pointer;}+.btn.btn-secondary.alt {+ background-color: #424c72;+ border-color: #444f75;++ &:hover {+ background-color: #3b4466;+ }++ &:focus {+ background-color: #343c59;+ box-shadow: 0 0 0 0.2rem rgb(68 79 117 / 50%);+ }+}++app-root {background-color: inherit;}