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 Plugin.DeviceInfo.Abstractions;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using XLabs.Ioc;
|
|
|
|
|
using Acr.UserDialogs;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
|
|
|
|
public class PasswordHintPage : ExtendedContentPage
|
|
|
|
|
{
|
|
|
|
|
private IUserDialogs _userDialogs;
|
|
|
|
|
private IAccountsApiRepository _accountApiRepository;
|
|
|
|
|
|
|
|
|
|
public PasswordHintPage()
|
2016-08-09 02:00:36 +03:00
|
|
|
|
: base(updateActivity: false)
|
2016-07-23 07:40:17 +03:00
|
|
|
|
{
|
|
|
|
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
|
|
|
|
_accountApiRepository = Resolver.Resolve<IAccountsApiRepository>();
|
|
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FormEntryCell EmailCell { get; set; }
|
|
|
|
|
|
|
|
|
|
private void Init()
|
|
|
|
|
{
|
2016-08-14 04:43:15 +03:00
|
|
|
|
var padding = Device.OnPlatform(
|
|
|
|
|
iOS: new Thickness(15, 20),
|
|
|
|
|
Android: new Thickness(15, 8),
|
|
|
|
|
WinPhone: new Thickness(15, 20));
|
|
|
|
|
|
2016-07-23 07:40:17 +03:00
|
|
|
|
EmailCell = new FormEntryCell(AppResources.EmailAddress, entryKeyboard: Keyboard.Email,
|
2016-08-14 04:43:15 +03:00
|
|
|
|
useLabelAsPlaceholder: true, imageSource: "envelope", containerPadding: padding);
|
2016-07-23 07:40:17 +03:00
|
|
|
|
|
|
|
|
|
EmailCell.Entry.ReturnType = Enums.ReturnType.Go;
|
|
|
|
|
EmailCell.Entry.Completed += Entry_Completed;
|
|
|
|
|
|
|
|
|
|
var table = new ExtendedTableView
|
|
|
|
|
{
|
|
|
|
|
Intent = TableIntent.Settings,
|
|
|
|
|
EnableScrolling = false,
|
|
|
|
|
HasUnevenRows = true,
|
|
|
|
|
EnableSelection = true,
|
|
|
|
|
NoFooter = true,
|
|
|
|
|
VerticalOptions = LayoutOptions.Start,
|
|
|
|
|
Root = new TableRoot
|
|
|
|
|
{
|
|
|
|
|
new TableSection()
|
|
|
|
|
{
|
|
|
|
|
EmailCell
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var hintLabel = new Label
|
|
|
|
|
{
|
|
|
|
|
Text = "Enter your account email address to receive your master password hint.",
|
|
|
|
|
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)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var layout = new StackLayout
|
|
|
|
|
{
|
|
|
|
|
Children = { table, hintLabel },
|
|
|
|
|
Spacing = 0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var scrollView = new ScrollView { Content = layout };
|
|
|
|
|
|
|
|
|
|
if(Device.OS == TargetPlatform.iOS)
|
|
|
|
|
{
|
|
|
|
|
table.RowHeight = -1;
|
|
|
|
|
table.EstimatedRowHeight = 70;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var submitToolbarItem = new ToolbarItem("Submit", null, async () =>
|
|
|
|
|
{
|
|
|
|
|
await SubmitAsync();
|
|
|
|
|
}, ToolbarItemOrder.Default, 0);
|
|
|
|
|
|
|
|
|
|
ToolbarItems.Add(submitToolbarItem);
|
|
|
|
|
Title = "Password Hint";
|
|
|
|
|
Content = scrollView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnAppearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnAppearing();
|
|
|
|
|
EmailCell.Entry.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void Entry_Completed(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
await SubmitAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task SubmitAsync()
|
|
|
|
|
{
|
|
|
|
|
if(string.IsNullOrWhiteSpace(EmailCell.Entry.Text))
|
|
|
|
|
{
|
|
|
|
|
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.EmailAddress), AppResources.Ok);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var request = new PasswordHintRequest
|
|
|
|
|
{
|
|
|
|
|
Email = EmailCell.Entry.Text
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var responseTask = _accountApiRepository.PostPasswordHintAsync(request);
|
|
|
|
|
_userDialogs.ShowLoading("Submitting...", MaskType.Black);
|
|
|
|
|
var response = await responseTask;
|
|
|
|
|
_userDialogs.HideLoading();
|
|
|
|
|
if(!response.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
await DisplayAlert(AppResources.AnErrorHasOccurred, response.Errors.FirstOrDefault()?.Message, AppResources.Ok);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await DisplayAlert(null, "We've sent you an email with your master password hint. ", AppResources.Ok);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await Navigation.PopAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|