make sure totp copy isn't available if not premium

This commit is contained in:
Kyle Spearrin 2019-06-13 08:44:07 -04:00
parent 6c5979040f
commit 43cee53dc8
2 changed files with 17 additions and 8 deletions

View File

@ -651,15 +651,19 @@ namespace Bit.Droid.Services
private async Task CopyTotpAsync(CipherView cipher) private async Task CopyTotpAsync(CipherView cipher)
{ {
var autoCopyDisabled = await _storageService.GetAsync<bool?>(Constants.DisableAutoTotpCopyKey); if(!string.IsNullOrWhiteSpace(cipher?.Login?.Totp))
var canAccessPremium = await ServiceContainer.Resolve<IUserService>("userService").CanAccessPremiumAsync();
if((canAccessPremium || cipher.OrganizationUseTotp) && !autoCopyDisabled.GetValueOrDefault() &&
!string.IsNullOrWhiteSpace(cipher?.Login?.Totp))
{ {
var totp = await ServiceContainer.Resolve<ITotpService>("totpService").GetCodeAsync(cipher.Login.Totp); var userService = ServiceContainer.Resolve<IUserService>("userService");
if(totp != null) var autoCopyDisabled = await _storageService.GetAsync<bool?>(Constants.DisableAutoTotpCopyKey);
var canAccessPremium = await userService.CanAccessPremiumAsync();
if((canAccessPremium || cipher.OrganizationUseTotp) && !autoCopyDisabled.GetValueOrDefault())
{ {
CopyToClipboard(totp); var totpService = ServiceContainer.Resolve<ITotpService>("totpService");
var totp = await totpService.GetCodeAsync(cipher.Login.Totp);
if(totp != null)
{
CopyToClipboard(totp);
}
} }
} }
} }

View File

@ -29,7 +29,12 @@ namespace Bit.App.Utilities
} }
if(!string.IsNullOrWhiteSpace(cipher.Login.Totp)) if(!string.IsNullOrWhiteSpace(cipher.Login.Totp))
{ {
options.Add(AppResources.CopyTotp); var userService = ServiceContainer.Resolve<IUserService>("userService");
var canAccessPremium = await userService.CanAccessPremiumAsync();
if(canAccessPremium || cipher.OrganizationUseTotp)
{
options.Add(AppResources.CopyTotp);
}
} }
if(cipher.Login.CanLaunch) if(cipher.Login.CanLaunch)
{ {