From b6d92a96c167d4f219abaf8d6dffc492496dc9ab Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 23 Apr 2021 22:35:32 +0200 Subject: [PATCH] Using static files for the login webapp --- Kyoo.WebLogin/{login.html => index.html} | 14 +++++------ Kyoo/Kyoo.csproj | 4 +-- Kyoo/Startup.cs | 1 + Kyoo/Views/AccountApi.cs | 31 ++++-------------------- Kyoo/settings.json | 7 ++++-- 5 files changed, 20 insertions(+), 37 deletions(-) rename Kyoo.WebLogin/{login.html => index.html} (91%) diff --git a/Kyoo.WebLogin/login.html b/Kyoo.WebLogin/index.html similarity index 91% rename from Kyoo.WebLogin/login.html rename to Kyoo.WebLogin/index.html index 0c32da3d..e875aab5 100644 --- a/Kyoo.WebLogin/login.html +++ b/Kyoo.WebLogin/index.html @@ -3,11 +3,11 @@ Kyoo - Login - - - - - + + + + +
@@ -85,6 +85,6 @@
- + - \ No newline at end of file + diff --git a/Kyoo/Kyoo.csproj b/Kyoo/Kyoo.csproj index 2d624b9c..0de3d730 100644 --- a/Kyoo/Kyoo.csproj +++ b/Kyoo/Kyoo.csproj @@ -92,7 +92,7 @@ true - login/%(LoginFiles.RecursiveDir)%(LoginFiles.Filename)%(LoginFiles.Extension) + wwwroot/login/%(LoginFiles.RecursiveDir)%(LoginFiles.Filename)%(LoginFiles.Extension) PreserveNewest true @@ -105,7 +105,7 @@ - + diff --git a/Kyoo/Startup.cs b/Kyoo/Startup.cs index 8e1485e3..f77ec15e 100644 --- a/Kyoo/Startup.cs +++ b/Kyoo/Startup.cs @@ -199,6 +199,7 @@ namespace Kyoo FileExtensionContentTypeProvider contentTypeProvider = new(); contentTypeProvider.Mappings[".data"] = "application/octet-stream"; + app.UseDefaultFiles(); app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = contentTypeProvider, diff --git a/Kyoo/Views/AccountApi.cs b/Kyoo/Views/AccountApi.cs index dc02fcda..dbf34c56 100644 --- a/Kyoo/Views/AccountApi.cs +++ b/Kyoo/Views/AccountApi.cs @@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.Configuration; using SignInResult = Microsoft.AspNetCore.Identity.SignInResult; @@ -47,29 +46,8 @@ namespace Kyoo.Api [FromForm(Name = "picture")] public IFormFile Picture { get; set; } } - - [ApiController] - public class AccountUiController : Controller - { - [HttpGet("login")] - public IActionResult Index() - { - return new PhysicalFileResult(Path.GetFullPath("login/login.html"), "text/html"); - } - - [HttpGet("login/{*file}")] - public IActionResult Index(string file) - { - string path = Path.Combine(Path.GetFullPath("login/"), file); - if (!System.IO.File.Exists(path)) - return NotFound(); - FileExtensionContentTypeProvider provider = new FileExtensionContentTypeProvider(); - if (!provider.TryGetContentType(path, out string contentType)) - contentType = "text/plain"; - return new PhysicalFileResult(path, contentType); - } - } - + + [Route("api/[controller]")] [ApiController] public class AccountController : Controller, IProfileService @@ -100,7 +78,7 @@ namespace Kyoo.Api return BadRequest(new[] {new {code = "username", description = "Username must be at least 4 characters."}}); if (!new EmailAddressAttribute().IsValid(user.Email)) return BadRequest(new[] {new {code = "email", description = "Email must be valid."}}); - User account = new User {UserName = user.Username, Email = user.Email}; + User account = new() {UserName = user.Username, Email = user.Email}; IdentityResult result = await _userManager.CreateAsync(account, user.Password); if (!result.Succeeded) return BadRequest(result.Errors); @@ -151,7 +129,7 @@ namespace Kyoo.Api User user = await _userManager.GetUserAsync(context.Subject); if (user != null) { - List claims = new List + List claims = new() { new Claim("email", user.Email), new Claim("username", user.UserName), @@ -207,6 +185,7 @@ namespace Kyoo.Api [HttpGet("default-permissions")] public ActionResult> GetDefaultPermissions() { + return new List(); return _configuration.GetValue("defaultPermissions").Split(","); } } diff --git a/Kyoo/settings.json b/Kyoo/settings.json index bdd2f362..8de53205 100644 --- a/Kyoo/settings.json +++ b/Kyoo/settings.json @@ -21,6 +21,11 @@ } }, + "permissions": { + "default": "read,play,write,admin", + "newUser": "read,play,write,admin" + }, + "parallelTasks": "1", "scheduledTasks": { @@ -35,8 +40,6 @@ "providerPath": "providers", "profilePicturePath": "users/", "plugins": "plugins/", - "defaultPermissions": "read,play,write,admin", - "newUserPermissions": "read,play,write,admin", "regex": "(?:\\/(?.*?))?\\/(?.*?)(?: \\(\\d+\\))?\\/\\k(?: \\(\\d+\\))?(?:(?: S(?\\d+)E(?\\d+))| (?\\d+))?.*$", "subtitleRegex": "^(?.*)\\.(?\\w{1,3})\\.(?default\\.)?(?forced\\.)?.*$" }