1
0
mirror of https://github.com/bitwarden/server synced 2025-12-14 23:33:41 +00:00

CanAccessPremium checks instead of User.Premium

This commit is contained in:
Kyle Spearrin
2018-08-28 16:23:58 -04:00
parent 90387cca0c
commit c41a1e0936
12 changed files with 130 additions and 35 deletions

View File

@@ -4,19 +4,27 @@ using Microsoft.AspNetCore.Identity;
using Bit.Core.Models.Table;
using Bit.Core.Enums;
using OtpNet;
using Bit.Core.Services;
namespace Bit.Core.Identity
{
public class AuthenticatorTokenProvider : IUserTwoFactorTokenProvider<User>
{
public Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
private readonly IUserService _userService;
public AuthenticatorTokenProvider(IUserService userService)
{
_userService = userService;
}
public async Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
{
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Authenticator);
var canGenerate = user.TwoFactorProviderIsEnabled(TwoFactorProviderType.Authenticator)
&& !string.IsNullOrWhiteSpace((string)provider.MetaData["Key"]);
return Task.FromResult(canGenerate);
if(string.IsNullOrWhiteSpace((string)provider.MetaData["Key"]))
{
return false;
}
return await user.TwoFactorProviderIsEnabledAsync(TwoFactorProviderType.Authenticator, _userService);
}
public Task<string> GenerateAsync(string purpose, UserManager<User> manager, User user)