mirror of
https://github.com/bitwarden/mobile
synced 2025-12-17 16:53:26 +00:00
hint page
This commit is contained in:
@@ -22,6 +22,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Update="Pages\Accounts\HintPage.xaml.cs">
|
||||||
|
<DependentUpon>HintPage.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Update="Pages\Accounts\LoginPage.xaml.cs">
|
<Compile Update="Pages\Accounts\LoginPage.xaml.cs">
|
||||||
<DependentUpon>LoginPage.xaml</DependentUpon>
|
<DependentUpon>LoginPage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
37
src/App/Pages/Accounts/HintPage.xaml
Normal file
37
src/App/Pages/Accounts/HintPage.xaml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<pages:BaseContentPage
|
||||||
|
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
x:Class="Bit.App.Pages.HintPage"
|
||||||
|
xmlns:pages="clr-namespace:Bit.App.Pages"
|
||||||
|
xmlns:u="clr-namespace:Bit.App.Utilities"
|
||||||
|
x:DataType="pages:HintPageViewModel"
|
||||||
|
Title="{Binding PageTitle}">
|
||||||
|
|
||||||
|
<ContentPage.BindingContext>
|
||||||
|
<pages:HintPageViewModel />
|
||||||
|
</ContentPage.BindingContext>
|
||||||
|
|
||||||
|
<ContentPage.ToolbarItems>
|
||||||
|
<ToolbarItem Text="{u:I18n Submit}" Clicked="Submit_Clicked" />
|
||||||
|
</ContentPage.ToolbarItems>
|
||||||
|
|
||||||
|
<ScrollView>
|
||||||
|
<StackLayout StyleClass="box">
|
||||||
|
<StackLayout StyleClass="box-row">
|
||||||
|
<Label
|
||||||
|
Text="{u:I18n EmailAddress}"
|
||||||
|
StyleClass="box-label" />
|
||||||
|
<Entry
|
||||||
|
x:Name="_email"
|
||||||
|
Text="{Binding Email}"
|
||||||
|
Keyboard="Email"
|
||||||
|
StyleClass="box-value" />
|
||||||
|
</StackLayout>
|
||||||
|
<Label
|
||||||
|
Text="{u:I18n EnterEmailForHint}"
|
||||||
|
StyleClass="box-footer-label" />
|
||||||
|
</StackLayout>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
</pages:BaseContentPage>
|
||||||
27
src/App/Pages/Accounts/HintPage.xaml.cs
Normal file
27
src/App/Pages/Accounts/HintPage.xaml.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Bit.App.Pages
|
||||||
|
{
|
||||||
|
public partial class HintPage : BaseContentPage
|
||||||
|
{
|
||||||
|
private HintPageViewModel _vm;
|
||||||
|
|
||||||
|
public HintPage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_vm = BindingContext as HintPageViewModel;
|
||||||
|
_vm.Page = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnAppearing()
|
||||||
|
{
|
||||||
|
base.OnAppearing();
|
||||||
|
RequestFocus(_email);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void Submit_Clicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await _vm.SubmitAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
56
src/App/Pages/Accounts/HintPageViewModel.cs
Normal file
56
src/App/Pages/Accounts/HintPageViewModel.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using Bit.App.Abstractions;
|
||||||
|
using Bit.App.Resources;
|
||||||
|
using Bit.Core.Abstractions;
|
||||||
|
using Bit.Core.Exceptions;
|
||||||
|
using Bit.Core.Utilities;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bit.App.Pages
|
||||||
|
{
|
||||||
|
public class HintPageViewModel : BaseViewModel
|
||||||
|
{
|
||||||
|
private readonly IDeviceActionService _deviceActionService;
|
||||||
|
private readonly IApiService _apiService;
|
||||||
|
|
||||||
|
public HintPageViewModel()
|
||||||
|
{
|
||||||
|
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
||||||
|
_apiService = ServiceContainer.Resolve<IApiService>("apiService");
|
||||||
|
|
||||||
|
PageTitle = AppResources.PasswordHint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
public async Task SubmitAsync()
|
||||||
|
{
|
||||||
|
if(string.IsNullOrWhiteSpace(Email))
|
||||||
|
{
|
||||||
|
await Page.DisplayAlert(AppResources.AnErrorHasOccurred,
|
||||||
|
string.Format(AppResources.ValidationFieldRequired, AppResources.EmailAddress),
|
||||||
|
AppResources.Ok);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!Email.Contains("@"))
|
||||||
|
{
|
||||||
|
await Page.DisplayAlert(AppResources.AnErrorHasOccurred, AppResources.InvalidEmail, AppResources.Ok);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _deviceActionService.ShowLoadingAsync(AppResources.Submitting);
|
||||||
|
await _apiService.PostPasswordHintAsync(
|
||||||
|
new Core.Models.Request.PasswordHintRequest { Email = Email });
|
||||||
|
await _deviceActionService.HideLoadingAsync();
|
||||||
|
await Page.DisplayAlert(null, AppResources.PasswordHintAlert, AppResources.Ok);
|
||||||
|
await Page.Navigation.PopModalAsync();
|
||||||
|
}
|
||||||
|
catch(ApiException e)
|
||||||
|
{
|
||||||
|
await _deviceActionService.HideLoadingAsync();
|
||||||
|
await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,6 +33,7 @@
|
|||||||
<Entry
|
<Entry
|
||||||
x:Name="_email"
|
x:Name="_email"
|
||||||
Text="{Binding Email}"
|
Text="{Binding Email}"
|
||||||
|
Keyboard="Email"
|
||||||
StyleClass="box-value" />
|
StyleClass="box-value" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<Grid StyleClass="box-row">
|
<Grid StyleClass="box-row">
|
||||||
@@ -66,7 +67,7 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<StackLayout Padding="10, 0">
|
<StackLayout Padding="10, 0">
|
||||||
<Button Text="{u:I18n GetPasswordHint}"></Button>
|
<Button Text="{u:I18n GetPasswordHint}" Clicked="Hint_Clicked"></Button>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|||||||
@@ -35,5 +35,10 @@ namespace Bit.App.Pages
|
|||||||
{
|
{
|
||||||
await _vm.LogInAsync();
|
await _vm.LogInAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Hint_Clicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Navigation.PushModalAsync(new NavigationPage(new HintPage()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ namespace Bit.Core.Services
|
|||||||
var responseJsonString = await response.Content.ReadAsStringAsync();
|
var responseJsonString = await response.Content.ReadAsStringAsync();
|
||||||
return JsonConvert.DeserializeObject<TResponse>(responseJsonString);
|
return JsonConvert.DeserializeObject<TResponse>(responseJsonString);
|
||||||
}
|
}
|
||||||
else if(response.IsSuccessStatusCode)
|
else if(!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
var error = await HandleErrorAsync(response, false);
|
var error = await HandleErrorAsync(response, false);
|
||||||
throw new ApiException(error);
|
throw new ApiException(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user