1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-19 17:53:47 +00:00

[SG-471] Added mock services. Added Accept/reject command binding, navigation and toast messages.

This commit is contained in:
André Bispo
2022-07-27 17:42:50 +01:00
parent 90fe9f8600
commit 7b237b4efe
7 changed files with 83 additions and 2 deletions

View File

@@ -77,10 +77,12 @@
Margin="0,0,0,57"/> Margin="0,0,0,57"/>
<Button <Button
Text="{u:I18n ConfirmLogIn}" Text="{u:I18n ConfirmLogIn}"
Command="{Binding AcceptRequestCommand}"
Margin="0,0,0,17" Margin="0,0,0,17"
StyleClass="btn-primary"/> StyleClass="btn-primary"/>
<Button <Button
Text="{u:I18n DenyLogIn}" Text="{u:I18n DenyLogIn}"
Command="{Binding RejectRequestCommand}"
StyleClass="btn-secundary"/> StyleClass="btn-secundary"/>
</StackLayout> </StackLayout>
</ScrollView> </ScrollView>

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Threading.Tasks;
namespace Bit.App.Pages namespace Bit.App.Pages
{ {
@@ -20,6 +21,11 @@ namespace Bit.App.Pages
} }
private async void Close_Clicked(object sender, System.EventArgs e) private async void Close_Clicked(object sender, System.EventArgs e)
{
await Close();
}
public async Task Close()
{ {
if (DoOnce()) if (DoOnce())
{ {

View File

@@ -6,12 +6,16 @@ using Bit.Core.Utilities;
using Xamarin.Forms; using Xamarin.Forms;
using Bit.App.Utilities; using Bit.App.Utilities;
using System.Linq; using System.Linq;
using Xamarin.CommunityToolkit.ObjectModel;
using System.Windows.Input;
namespace Bit.App.Pages namespace Bit.App.Pages
{ {
public class LoginPasswordlessViewModel : BaseViewModel public class LoginPasswordlessViewModel : BaseViewModel
{ {
private IStateService _stateService; private IAuthService _authService;
private IPlatformUtilsService _platformUtilsService;
private ILogger _logger;
private string _logInAttempByLabel; private string _logInAttempByLabel;
private string _deviceType; private string _deviceType;
private FormattedString _fingerprintPhraseFormatted; private FormattedString _fingerprintPhraseFormatted;
@@ -24,10 +28,24 @@ namespace Bit.App.Pages
public LoginPasswordlessViewModel() public LoginPasswordlessViewModel()
{ {
_stateService = ServiceContainer.Resolve<IStateService>("stateService"); _authService = ServiceContainer.Resolve<IAuthService>("authService");
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
_logger = ServiceContainer.Resolve<ILogger>("logger");
PageTitle = AppResources.LogInRequested; PageTitle = AppResources.LogInRequested;
AcceptRequestCommand = new AsyncCommand(AcceptRequestAsync,
onException: ex => _logger.Exception(ex),
allowsMultipleExecutions: false);
RejectRequestCommand = new AsyncCommand(RejectRequestAsync,
onException: ex => _logger.Exception(ex),
allowsMultipleExecutions: false);
} }
public ICommand AcceptRequestCommand { get; }
public ICommand RejectRequestCommand { get; }
public string Email public string Email
{ {
get => _email; get => _email;
@@ -139,5 +157,33 @@ namespace Bit.App.Pages
return RequestDate.ToShortTimeString(); return RequestDate.ToShortTimeString();
} }
private async Task AcceptRequestAsync()
{
try
{
var res = await _authService.LogInPasswordlessAcceptAsync();
await ((LoginPasswordlessPage)this.Page).Close();
_platformUtilsService.ShowToast("info", null, AppResources.LogInAccepted);
}
catch (Exception ex)
{
_logger.Exception(ex);
}
}
private async Task RejectRequestAsync()
{
try
{
var res = await _authService.LogInPasswordlessRejectAsync();
await ((LoginPasswordlessPage)this.Page).Close();
_platformUtilsService.ShowToast("info", null, AppResources.LogInDenied);
}
catch (Exception ex)
{
_logger.Exception(ex);
}
}
} }
} }

View File

@@ -4132,5 +4132,17 @@ namespace Bit.App.Resources {
return ResourceManager.GetString("MinutesAgo", resourceCulture); return ResourceManager.GetString("MinutesAgo", resourceCulture);
} }
} }
public static string LogInAccepted {
get {
return ResourceManager.GetString("LogInAccepted", resourceCulture);
}
}
public static string LogInDenied {
get {
return ResourceManager.GetString("LogInDenied", resourceCulture);
}
}
} }
} }

View File

@@ -2305,4 +2305,10 @@
<data name="MinutesAgo" xml:space="preserve"> <data name="MinutesAgo" xml:space="preserve">
<value>minutes ago</value> <value>minutes ago</value>
</data> </data>
<data name="LogInAccepted" xml:space="preserve">
<value>Log in accepted</value>
</data>
<data name="LogInDenied" xml:space="preserve">
<value>Log in denied</value>
</data>
</root> </root>

View File

@@ -25,6 +25,11 @@ namespace Bit.Core.Abstractions
Task<AuthResult> LogInSsoAsync(string code, string codeVerifier, string redirectUrl, string orgId); Task<AuthResult> LogInSsoAsync(string code, string codeVerifier, string redirectUrl, string orgId);
Task<AuthResult> LogInCompleteAsync(string email, string masterPassword, TwoFactorProviderType twoFactorProvider, string twoFactorToken, bool? remember = null); Task<AuthResult> LogInCompleteAsync(string email, string masterPassword, TwoFactorProviderType twoFactorProvider, string twoFactorToken, bool? remember = null);
Task<AuthResult> LogInTwoFactorAsync(TwoFactorProviderType twoFactorProvider, string twoFactorToken, string captchaToken, bool? remember = null); Task<AuthResult> LogInTwoFactorAsync(TwoFactorProviderType twoFactorProvider, string twoFactorToken, string captchaToken, bool? remember = null);
Task<AuthResult> GetLogInPasswordlessRequestsAsync();
Task<AuthResult> LogInPasswordlessAcceptAsync();
Task<AuthResult> LogInPasswordlessRejectAsync();
void LogOut(Action callback); void LogOut(Action callback);
void Init(); void Init();
} }

View File

@@ -468,5 +468,9 @@ namespace Bit.Core.Services
TwoFactorProvidersData = null; TwoFactorProvidersData = null;
SelectedTwoFactorProviderType = null; SelectedTwoFactorProviderType = null;
} }
public async Task<AuthResult> GetLogInPasswordlessRequestsAsync() => await Task.FromResult<AuthResult>(new AuthResult());
public async Task<AuthResult> LogInPasswordlessAcceptAsync() => await Task.FromResult<AuthResult>(new AuthResult());
public async Task<AuthResult> LogInPasswordlessRejectAsync() => await Task.FromResult<AuthResult>(new AuthResult());
} }
} }