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,18 +651,22 @@ 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");
var autoCopyDisabled = await _storageService.GetAsync<bool?>(Constants.DisableAutoTotpCopyKey);
var canAccessPremium = await userService.CanAccessPremiumAsync();
if((canAccessPremium || cipher.OrganizationUseTotp) && !autoCopyDisabled.GetValueOrDefault())
{
var totpService = ServiceContainer.Resolve<ITotpService>("totpService");
var totp = await totpService.GetCodeAsync(cipher.Login.Totp);
if(totp != null) if(totp != null)
{ {
CopyToClipboard(totp); CopyToClipboard(totp);
} }
} }
} }
}
private void CopyToClipboard(string text) private void CopyToClipboard(string text)
{ {

View File

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