Merge branch 'develop' of https://github.com/tidusjar/ombi into develop

pull/2332/head
Jamie Rees 7 years ago
commit 4f49bf0255

@ -183,13 +183,15 @@
<tr>
<td>
{@RECENTLYADDED}
</td>
</tr>
<!-- END MAIN CONTENT AREA -->
</table>
<!-- START FOOTER -->
<div class="footer" style="clear: both; padding-top: 10px; text-align: center; width: 100%;">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;" width="100%">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;">
<tr>
<td class="content-block powered-by" style="font-family: sans-serif; vertical-align: top; padding-top: 10px; padding-bottom: 10px; font-size: 12px; color: #999999; text-align: center;" valign="top" align="center">
Powered by <a href="https://github.com/tidusjar/Ombi" style="color: #999999; font-size: 12px; text-align: center; text-decoration: underline;">Ombi</a>

@ -5,6 +5,7 @@ using System.Security.Principal;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Ombi.Core.Authentication;
using Ombi.Core.Settings;
using Ombi.Settings.Settings.Models;
@ -13,15 +14,11 @@ namespace Ombi
{
public class ApiKeyMiddlewear
{
public ApiKeyMiddlewear(RequestDelegate next, ISettingsService<OmbiSettings> repo, OmbiUserManager um)
public ApiKeyMiddlewear(RequestDelegate next)
{
_next = next;
_repo = repo;
_userManager = um;
}
private readonly RequestDelegate _next;
private readonly ISettingsService<OmbiSettings> _repo;
private readonly OmbiUserManager _userManager;
public async Task Invoke(HttpContext context)
{
@ -67,7 +64,8 @@ namespace Ombi
return;
}
var user = await _userManager.Users.FirstOrDefaultAsync(x => x.UserAccessToken == key);
var um = context.RequestServices.GetService<OmbiUserManager>();
var user = await um.Users.FirstOrDefaultAsync(x => x.UserAccessToken == key);
if (user == null)
{
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
@ -77,7 +75,7 @@ namespace Ombi
{
var identity = new GenericIdentity(user.UserName);
var roles = await _userManager.GetRolesAsync(user);
var roles = await um.GetRolesAsync(user);
var principal = new GenericPrincipal(identity, roles.ToArray());
context.User = principal;
await next.Invoke(context);
@ -86,7 +84,8 @@ namespace Ombi
private async Task ValidateApiKey(HttpContext context, RequestDelegate next, string key)
{
var ombiSettings = await _repo.GetSettingsAsync();
var repo = context.RequestServices.GetService<ISettingsService<OmbiSettings>>();
var ombiSettings = await repo.GetSettingsAsync();
var valid = ombiSettings.ApiKey.Equals(key, StringComparison.CurrentCultureIgnoreCase);
if (!valid)
{

Loading…
Cancel
Save