hint page

This commit is contained in:
Kyle Spearrin 2019-05-01 15:53:56 -04:00
parent 9678eab43f
commit 15cda95c64
7 changed files with 131 additions and 2 deletions

View File

@ -22,6 +22,9 @@
</ItemGroup>
<ItemGroup>
<Compile Update="Pages\Accounts\HintPage.xaml.cs">
<DependentUpon>HintPage.xaml</DependentUpon>
</Compile>
<Compile Update="Pages\Accounts\LoginPage.xaml.cs">
<DependentUpon>LoginPage.xaml</DependentUpon>
</Compile>

View 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>

View 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();
}
}
}

View 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);
}
}
}
}

View File

@ -33,6 +33,7 @@
<Entry
x:Name="_email"
Text="{Binding Email}"
Keyboard="Email"
StyleClass="box-value" />
</StackLayout>
<Grid StyleClass="box-row">
@ -66,7 +67,7 @@
</Grid>
</StackLayout>
<StackLayout Padding="10, 0">
<Button Text="{u:I18n GetPasswordHint}"></Button>
<Button Text="{u:I18n GetPasswordHint}" Clicked="Hint_Clicked"></Button>
</StackLayout>
</StackLayout>
</ScrollView>

View File

@ -35,5 +35,10 @@ namespace Bit.App.Pages
{
await _vm.LogInAsync();
}
private void Hint_Clicked(object sender, EventArgs e)
{
Navigation.PushModalAsync(new NavigationPage(new HintPage()));
}
}
}

View File

@ -345,7 +345,7 @@ namespace Bit.Core.Services
var responseJsonString = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<TResponse>(responseJsonString);
}
else if(response.IsSuccessStatusCode)
else if(!response.IsSuccessStatusCode)
{
var error = await HandleErrorAsync(response, false);
throw new ApiException(error);