2016-07-23 07:40:17 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Controls;
|
|
|
|
|
using Bit.App.Models.Api;
|
|
|
|
|
using Bit.App.Resources;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using XLabs.Ioc;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-05-30 21:13:53 +03:00
|
|
|
|
using Bit.App.Utilities;
|
2016-07-23 07:40:17 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
|
|
|
|
public class PasswordHintPage : ExtendedContentPage
|
|
|
|
|
{
|
|
|
|
|
private IAccountsApiRepository _accountApiRepository;
|
2017-12-23 07:56:45 +03:00
|
|
|
|
private IDeviceActionService _deviceActionService;
|
2016-07-23 07:40:17 +03:00
|
|
|
|
|
|
|
|
|
public PasswordHintPage()
|
2018-01-18 21:18:08 +03:00
|
|
|
|
: base(updateActivity: false, requireAuth: false)
|
2016-07-23 07:40:17 +03:00
|
|
|
|
{
|
|
|
|
|
_accountApiRepository = Resolver.Resolve<IAccountsApiRepository>();
|
2017-12-23 07:56:45 +03:00
|
|
|
|
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
|
2016-07-23 07:40:17 +03:00
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FormEntryCell EmailCell { get; set; }
|
|
|
|
|
|
|
|
|
|
private void Init()
|
|
|
|
|
{
|
2017-05-30 21:13:53 +03:00
|
|
|
|
var padding = Helpers.OnPlatform(
|
2016-08-14 04:43:15 +03:00
|
|
|
|
iOS: new Thickness(15, 20),
|
|
|
|
|
Android: new Thickness(15, 8),
|
2017-12-11 07:26:58 +03:00
|
|
|
|
Windows: new Thickness(10, 8));
|
2016-08-14 04:43:15 +03:00
|
|
|
|
|
2016-07-23 07:40:17 +03:00
|
|
|
|
EmailCell = new FormEntryCell(AppResources.EmailAddress, entryKeyboard: Keyboard.Email,
|
2017-10-03 05:15:13 +03:00
|
|
|
|
useLabelAsPlaceholder: true, imageSource: "envelope.png", containerPadding: padding);
|
2016-07-23 07:40:17 +03:00
|
|
|
|
|
2018-06-29 19:45:10 +03:00
|
|
|
|
EmailCell.Entry.TargetReturnType = Enums.ReturnType.Go;
|
2016-07-23 07:40:17 +03:00
|
|
|
|
|
|
|
|
|
var table = new ExtendedTableView
|
|
|
|
|
{
|
|
|
|
|
Intent = TableIntent.Settings,
|
|
|
|
|
EnableScrolling = false,
|
|
|
|
|
HasUnevenRows = true,
|
|
|
|
|
EnableSelection = true,
|
|
|
|
|
NoFooter = true,
|
|
|
|
|
VerticalOptions = LayoutOptions.Start,
|
|
|
|
|
Root = new TableRoot
|
|
|
|
|
{
|
2017-11-21 06:39:49 +03:00
|
|
|
|
new TableSection(Helpers.GetEmptyTableSectionTitle())
|
2016-07-23 07:40:17 +03:00
|
|
|
|
{
|
|
|
|
|
EmailCell
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var hintLabel = new Label
|
|
|
|
|
{
|
2016-11-26 00:54:33 +03:00
|
|
|
|
Text = AppResources.EnterEmailForHint,
|
2016-07-23 07:40:17 +03:00
|
|
|
|
LineBreakMode = LineBreakMode.WordWrap,
|
|
|
|
|
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
|
|
|
|
|
Style = (Style)Application.Current.Resources["text-muted"],
|
|
|
|
|
Margin = new Thickness(15, (this.IsLandscape() ? 5 : 0), 15, 25)
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-03 20:18:15 +03:00
|
|
|
|
var layout = new RedrawableStackLayout
|
2016-07-23 07:40:17 +03:00
|
|
|
|
{
|
|
|
|
|
Children = { table, hintLabel },
|
|
|
|
|
Spacing = 0
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-03 20:18:15 +03:00
|
|
|
|
table.WrappingStackLayout = () => layout;
|
2016-07-23 07:40:17 +03:00
|
|
|
|
var scrollView = new ScrollView { Content = layout };
|
|
|
|
|
|
2017-05-30 21:13:53 +03:00
|
|
|
|
if(Device.RuntimePlatform == Device.iOS)
|
2016-07-23 07:40:17 +03:00
|
|
|
|
{
|
|
|
|
|
table.RowHeight = -1;
|
|
|
|
|
table.EstimatedRowHeight = 70;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-11 23:51:16 +03:00
|
|
|
|
var submitToolbarItem = new ToolbarItem(AppResources.Submit, Helpers.ToolbarImage("ion_chevron_right.png"), async () =>
|
2016-07-23 07:40:17 +03:00
|
|
|
|
{
|
|
|
|
|
await SubmitAsync();
|
|
|
|
|
}, ToolbarItemOrder.Default, 0);
|
|
|
|
|
|
|
|
|
|
ToolbarItems.Add(submitToolbarItem);
|
2016-11-26 00:54:33 +03:00
|
|
|
|
Title = AppResources.PasswordHint;
|
2016-07-23 07:40:17 +03:00
|
|
|
|
Content = scrollView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnAppearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnAppearing();
|
2017-02-15 08:28:05 +03:00
|
|
|
|
EmailCell.InitEvents();
|
|
|
|
|
EmailCell.Entry.Completed += Entry_Completed;
|
2016-08-19 07:27:37 +03:00
|
|
|
|
EmailCell.Entry.FocusWithDelay();
|
2016-07-23 07:40:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-15 08:28:05 +03:00
|
|
|
|
protected override void OnDisappearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnDisappearing();
|
|
|
|
|
EmailCell.Dispose();
|
|
|
|
|
EmailCell.Entry.Completed -= Entry_Completed;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-23 07:40:17 +03:00
|
|
|
|
private async void Entry_Completed(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
await SubmitAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task SubmitAsync()
|
|
|
|
|
{
|
|
|
|
|
if(string.IsNullOrWhiteSpace(EmailCell.Entry.Text))
|
|
|
|
|
{
|
2016-08-17 02:20:41 +03:00
|
|
|
|
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
|
|
|
|
|
AppResources.EmailAddress), AppResources.Ok);
|
2016-07-23 07:40:17 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var request = new PasswordHintRequest
|
|
|
|
|
{
|
|
|
|
|
Email = EmailCell.Entry.Text
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-22 18:07:41 +03:00
|
|
|
|
await _deviceActionService.ShowLoadingAsync(AppResources.Submitting);
|
2016-08-17 02:20:41 +03:00
|
|
|
|
var response = await _accountApiRepository.PostPasswordHintAsync(request);
|
2018-03-22 18:07:41 +03:00
|
|
|
|
await _deviceActionService.HideLoadingAsync();
|
2017-12-23 06:41:48 +03:00
|
|
|
|
|
2016-07-23 07:40:17 +03:00
|
|
|
|
if(!response.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
await DisplayAlert(AppResources.AnErrorHasOccurred, response.Errors.FirstOrDefault()?.Message, AppResources.Ok);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-11-26 00:54:33 +03:00
|
|
|
|
await DisplayAlert(null, AppResources.PasswordHintAlert, AppResources.Ok);
|
2016-07-23 07:40:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await Navigation.PopAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|