From 8cad9600cc0fb4cc0f7a1489814ae492bc803bb5 Mon Sep 17 00:00:00 2001 From: ta264 Date: Thu, 21 Oct 2021 21:04:26 +0100 Subject: [PATCH] Tidy conversion to aspnetcore (cherry picked from commit 490f6e2e6aa3f220cc98f257a3ca3b2bea48fb80) (cherry picked from commit 8f3f90d4078d9d072d8ad4ccc3be35963b7435d6) (cherry picked from commit 2b0da546c9dae40fbc1b2654387be80a17c1848f) --- .../Authentication/AuthenticationController.cs | 5 ++--- src/Radarr.Http/Middleware/CacheableSpecification.cs | 6 +++--- .../REST/Attributes/RestGetByIdAttribute.cs | 10 ++-------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Radarr.Http/Authentication/AuthenticationController.cs b/src/Radarr.Http/Authentication/AuthenticationController.cs index c47b2d5f7..400091b99 100644 --- a/src/Radarr.Http/Authentication/AuthenticationController.cs +++ b/src/Radarr.Http/Authentication/AuthenticationController.cs @@ -14,12 +14,10 @@ namespace Radarr.Http.Authentication public class AuthenticationController : Controller { private readonly IAuthenticationService _authService; - private readonly IConfigFileProvider _configFileProvider; - public AuthenticationController(IAuthenticationService authService, IConfigFileProvider configFileProvider) + public AuthenticationController(IAuthenticationService authService) { _authService = authService; - _configFileProvider = configFileProvider; } [HttpPost("login")] @@ -43,6 +41,7 @@ public async Task Login([FromForm] LoginResource resource, [FromQ { IsPersistent = resource.RememberMe == "on" }; + await HttpContext.SignInAsync(AuthenticationType.Forms.ToString(), new ClaimsPrincipal(new ClaimsIdentity(claims, "Cookies", "user", "identifier")), authProperties); return Redirect("/"); diff --git a/src/Radarr.Http/Middleware/CacheableSpecification.cs b/src/Radarr.Http/Middleware/CacheableSpecification.cs index a9cf220d1..3457c2c7b 100644 --- a/src/Radarr.Http/Middleware/CacheableSpecification.cs +++ b/src/Radarr.Http/Middleware/CacheableSpecification.cs @@ -39,12 +39,12 @@ public bool IsCacheable(HttpContext context) return false; } - if (context.Request.Path.Equals("/index.js")) + if (context.Request.Path.Value?.EndsWith("/index.js") ?? false) { return false; } - if (context.Request.Path.Equals("/initialize.js")) + if (context.Request.Path.Value?.EndsWith("/initialize.js") ?? false) { return false; } @@ -55,7 +55,7 @@ public bool IsCacheable(HttpContext context) } if (context.Request.Path.StartsWithSegments("/log", StringComparison.CurrentCultureIgnoreCase) && - context.Request.Path.ToString().EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase)) + (context.Request.Path.Value?.EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase) ?? false)) { return false; } diff --git a/src/Radarr.Http/REST/Attributes/RestGetByIdAttribute.cs b/src/Radarr.Http/REST/Attributes/RestGetByIdAttribute.cs index 94eb9d333..6ed799017 100644 --- a/src/Radarr.Http/REST/Attributes/RestGetByIdAttribute.cs +++ b/src/Radarr.Http/REST/Attributes/RestGetByIdAttribute.cs @@ -1,21 +1,15 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Routing; namespace Radarr.Http.REST.Attributes { [AttributeUsage(AttributeTargets.Method)] - public class RestGetByIdAttribute : ActionFilterAttribute, IActionHttpMethodProvider, IRouteTemplateProvider + public class RestGetByIdAttribute : Attribute, IActionHttpMethodProvider, IRouteTemplateProvider { - public override void OnActionExecuting(ActionExecutingContext context) - { - Console.WriteLine($"OnExecuting {context.Controller.GetType()} {context.ActionDescriptor.DisplayName}"); - } - public IEnumerable HttpMethods => new[] { "GET" }; public string Template => "{id:int}"; - public new int? Order => 0; + public int? Order => 0; public string Name { get; } } }