Allow users to login without a password

This commit is contained in:
Jamie 2017-12-20 13:40:36 +00:00
commit d5787e6625
8 changed files with 130 additions and 10 deletions

View file

@ -37,6 +37,7 @@ using Ombi.Api.Plex.Models;
using Ombi.Core.Settings;
using Ombi.Core.Settings.Models.External;
using Ombi.Helpers;
using Ombi.Settings.Settings.Models;
using Ombi.Store.Entities;
namespace Ombi.Core.Authentication
@ -47,20 +48,36 @@ namespace Ombi.Core.Authentication
IPasswordHasher<OmbiUser> passwordHasher, IEnumerable<IUserValidator<OmbiUser>> userValidators,
IEnumerable<IPasswordValidator<OmbiUser>> passwordValidators, ILookupNormalizer keyNormalizer,
IdentityErrorDescriber errors, IServiceProvider services, ILogger<UserManager<OmbiUser>> logger, IPlexApi plexApi,
IEmbyApi embyApi, ISettingsService<EmbySettings> embySettings)
IEmbyApi embyApi, ISettingsService<EmbySettings> embySettings, ISettingsService<AuthenticationSettings> auth)
: base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger)
{
_plexApi = plexApi;
_embyApi = embyApi;
_embySettings = embySettings;
_authSettings = auth;
}
private readonly IPlexApi _plexApi;
private readonly IEmbyApi _embyApi;
private readonly ISettingsService<EmbySettings> _embySettings;
private readonly ISettingsService<AuthenticationSettings> _authSettings;
public override async Task<bool> CheckPasswordAsync(OmbiUser user, string password)
{
var authSettings = await _authSettings.GetSettingsAsync();
if (authSettings.AllowNoPassword)
{
// Check their roles
var roles = await GetRolesAsync(user);
if (roles.Contains(OmbiRoles.Admin) || roles.Contains(OmbiRoles.PowerUser))
{
// Do nothing, let it continue to check the password
}
else
{
return true;
}
}
if (user.UserType == UserType.LocalUser)
{
return await base.CheckPasswordAsync(user, password);