1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-18 16:33:15 +00:00

[SG-705] Popup when a request for authentication comes in on a logged-in account that is not active (#2135)

* [SG-705] Added pop up to perform account switching if the user receives a login request from another account.

* [SG-705] missing resource designer

* [SG-705] Fixed wrong key for state service variable.

* [SG-705] Fix formatting of account switch alert.

* [SG-705] dotnet format run

* [SG-705] Removed async

* [SG-705] Refactor on App
This commit is contained in:
André Bispo
2022-10-18 17:21:45 +01:00
committed by GitHub
parent d18efdea73
commit eefc9bd239
7 changed files with 242 additions and 207 deletions

View File

@@ -11,6 +11,7 @@ using Bit.Core;
using Bit.Core.Abstractions;
using Bit.Core.Enums;
using Bit.Core.Models.Data;
using Bit.Core.Models.Response;
using Bit.Core.Services;
using Bit.Core.Utilities;
using Xamarin.Forms;
@@ -168,13 +169,17 @@ namespace Bit.App
return;
}
var notification = await _stateService.GetPasswordlessLoginNotificationAsync();
if (notification == null)
{
return;
}
if (await CheckShouldSwitchActiveUserAsync(notification))
{
return;
}
// Delay to wait for the vault page to appear
await Task.Delay(2000);
var loginRequestData = await _authService.GetPasswordlessLoginRequestByIdAsync(notification.Id);
@@ -197,6 +202,27 @@ namespace Bit.App
}
}
private async Task<bool> CheckShouldSwitchActiveUserAsync(PasswordlessRequestNotification notification)
{
var activeUserId = await _stateService.GetActiveUserIdAsync();
if (notification.UserId == activeUserId)
{
return false;
}
var notificationUserEmail = await _stateService.GetEmailAsync(notification.UserId);
await Device.InvokeOnMainThreadAsync(async () =>
{
var result = await _deviceActionService.DisplayAlertAsync(AppResources.LogInRequested, string.Format(AppResources.LoginAttemptFromXDoYouWantToSwitchToThisAccount, notificationUserEmail), AppResources.Cancel, AppResources.Ok);
if (result == AppResources.Ok)
{
await _stateService.SetActiveUserAsync(notification.UserId);
_messagingService.Send(AccountsManagerMessageCommands.SWITCHED_ACCOUNT);
}
});
return true;
}
public AppOptions Options { get; private set; }
protected async override void OnStart()

File diff suppressed because it is too large Load Diff

View File

@@ -2464,4 +2464,9 @@ select Add TOTP to store the key safely</value>
<data name="LoginRequestHasAlreadyExpired" xml:space="preserve">
<value>Login request has already expired.</value>
</data>
<data name="LoginAttemptFromXDoYouWantToSwitchToThisAccount" xml:space="preserve">
<value>Login attempt from:
{0}
Do you want to switch to this account?</value>
</data>
</root>

View File

@@ -146,7 +146,7 @@ namespace Bit.App.Services
return;
}
await _stateService.Value.SetPasswordlessLoginNotificationAsync(passwordlessLoginMessage, passwordlessLoginMessage?.UserId);
await _stateService.Value.SetPasswordlessLoginNotificationAsync(passwordlessLoginMessage);
var userEmail = await _stateService.Value.GetEmailAsync(passwordlessLoginMessage?.UserId);
var notificationData = new PasswordlessNotificationData()
@@ -247,14 +247,10 @@ namespace Bit.App.Services
{
if (data is PasswordlessNotificationData passwordlessNotificationData)
{
var notificationUserId = await _stateService.Value.GetUserIdAsync(passwordlessNotificationData.UserEmail);
if (notificationUserId != null)
var savedNotification = await _stateService.Value.GetPasswordlessLoginNotificationAsync();
if (savedNotification != null)
{
var savedNotification = await _stateService.Value.GetPasswordlessLoginNotificationAsync(notificationUserId);
if (savedNotification != null)
{
await _stateService.Value.SetPasswordlessLoginNotificationAsync(null, notificationUserId);
}
await _stateService.Value.SetPasswordlessLoginNotificationAsync(null);
}
}
}