mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 09:58:27 +03:00
Password hint page
This commit is contained in:
parent
aed04828e9
commit
2911af2c16
7 changed files with 204 additions and 7 deletions
|
@ -6,5 +6,6 @@ namespace Bit.App.Abstractions
|
||||||
public interface IAccountsApiRepository
|
public interface IAccountsApiRepository
|
||||||
{
|
{
|
||||||
Task<ApiResult> PostRegisterAsync(RegisterRequest requestObj);
|
Task<ApiResult> PostRegisterAsync(RegisterRequest requestObj);
|
||||||
|
Task<ApiResult> PostPasswordHintAsync(PasswordHintRequest requestObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -81,6 +81,7 @@
|
||||||
<Compile Include="Models\Api\Request\DeviceRequest.cs" />
|
<Compile Include="Models\Api\Request\DeviceRequest.cs" />
|
||||||
<Compile Include="Models\Api\Request\RegisterRequest.cs" />
|
<Compile Include="Models\Api\Request\RegisterRequest.cs" />
|
||||||
<Compile Include="Models\Api\Request\SiteRequest.cs" />
|
<Compile Include="Models\Api\Request\SiteRequest.cs" />
|
||||||
|
<Compile Include="Models\Api\Request\PasswordHintRequest.cs" />
|
||||||
<Compile Include="Models\Api\Request\TokenRequest.cs" />
|
<Compile Include="Models\Api\Request\TokenRequest.cs" />
|
||||||
<Compile Include="Models\Api\Request\TokenTwoFactorRequest.cs" />
|
<Compile Include="Models\Api\Request\TokenTwoFactorRequest.cs" />
|
||||||
<Compile Include="Models\Api\Response\CipherHistoryResponse.cs" />
|
<Compile Include="Models\Api\Response\CipherHistoryResponse.cs" />
|
||||||
|
@ -109,6 +110,7 @@
|
||||||
<Compile Include="Models\Page\VaultViewSitePageModel.cs" />
|
<Compile Include="Models\Page\VaultViewSitePageModel.cs" />
|
||||||
<Compile Include="Pages\HomePage.cs" />
|
<Compile Include="Pages\HomePage.cs" />
|
||||||
<Compile Include="Pages\Lock\LockPasswordPage.cs" />
|
<Compile Include="Pages\Lock\LockPasswordPage.cs" />
|
||||||
|
<Compile Include="Pages\PasswordHintPage.cs" />
|
||||||
<Compile Include="Pages\RegisterPage.cs" />
|
<Compile Include="Pages\RegisterPage.cs" />
|
||||||
<Compile Include="Pages\Settings\SettingsPinPage.cs" />
|
<Compile Include="Pages\Settings\SettingsPinPage.cs" />
|
||||||
<Compile Include="Pages\Lock\LockPinPage.cs" />
|
<Compile Include="Pages\Lock\LockPinPage.cs" />
|
||||||
|
|
7
src/App/Models/Api/Request/PasswordHintRequest.cs
Normal file
7
src/App/Models/Api/Request/PasswordHintRequest.cs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
namespace Bit.App.Models.Api
|
||||||
|
{
|
||||||
|
public class PasswordHintRequest
|
||||||
|
{
|
||||||
|
public string Email { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -52,9 +52,11 @@ namespace Bit.App.Pages
|
||||||
var table = new ExtendedTableView
|
var table = new ExtendedTableView
|
||||||
{
|
{
|
||||||
Intent = TableIntent.Settings,
|
Intent = TableIntent.Settings,
|
||||||
EnableScrolling = true,
|
EnableScrolling = false,
|
||||||
HasUnevenRows = true,
|
HasUnevenRows = true,
|
||||||
EnableSelection = false,
|
EnableSelection = true,
|
||||||
|
NoFooter = true,
|
||||||
|
VerticalOptions = LayoutOptions.Start,
|
||||||
Root = new TableRoot
|
Root = new TableRoot
|
||||||
{
|
{
|
||||||
new TableSection()
|
new TableSection()
|
||||||
|
@ -65,10 +67,21 @@ namespace Bit.App.Pages
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var loginToolbarItem = new ToolbarItem(AppResources.LogIn, null, async () =>
|
var forgotPasswordButton = new Button
|
||||||
{
|
{
|
||||||
await LogIn();
|
Text = "Get your master password hint",
|
||||||
}, ToolbarItemOrder.Default, 0);
|
Style = (Style)Application.Current.Resources["btn-primaryAccent"],
|
||||||
|
Margin = new Thickness(15, 0, 15, 25),
|
||||||
|
Command = new Command(async () => await ForgotPasswordAsync())
|
||||||
|
};
|
||||||
|
|
||||||
|
var layout = new StackLayout
|
||||||
|
{
|
||||||
|
Children = { table, forgotPasswordButton },
|
||||||
|
Spacing = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
var scrollView = new ScrollView { Content = layout };
|
||||||
|
|
||||||
if(Device.OS == TargetPlatform.iOS)
|
if(Device.OS == TargetPlatform.iOS)
|
||||||
{
|
{
|
||||||
|
@ -77,9 +90,15 @@ namespace Bit.App.Pages
|
||||||
ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel"));
|
ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var loginToolbarItem = new ToolbarItem(AppResources.LogIn, null, async () =>
|
||||||
|
{
|
||||||
|
await LogIn();
|
||||||
|
}, ToolbarItemOrder.Default, 0);
|
||||||
|
|
||||||
ToolbarItems.Add(loginToolbarItem);
|
ToolbarItems.Add(loginToolbarItem);
|
||||||
Title = AppResources.Bitwarden;
|
Title = AppResources.Bitwarden;
|
||||||
Content = table;
|
Content = scrollView;
|
||||||
|
NavigationPage.SetBackButtonTitle(this, "Log In");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnAppearing()
|
protected override void OnAppearing()
|
||||||
|
@ -92,6 +111,10 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
await LogIn();
|
await LogIn();
|
||||||
}
|
}
|
||||||
|
private async Task ForgotPasswordAsync()
|
||||||
|
{
|
||||||
|
await Navigation.PushAsync(new PasswordHintPage());
|
||||||
|
}
|
||||||
|
|
||||||
private async Task LogIn()
|
private async Task LogIn()
|
||||||
{
|
{
|
||||||
|
|
139
src/App/Pages/PasswordHintPage.cs
Normal file
139
src/App/Pages/PasswordHintPage.cs
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
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 ICryptoService _cryptoService;
|
||||||
|
private IAuthService _authService;
|
||||||
|
private IDeviceInfo _deviceInfo;
|
||||||
|
private IAppIdService _appIdService;
|
||||||
|
private IUserDialogs _userDialogs;
|
||||||
|
private ISyncService _syncService;
|
||||||
|
private IAccountsApiRepository _accountApiRepository;
|
||||||
|
|
||||||
|
public PasswordHintPage()
|
||||||
|
{
|
||||||
|
_cryptoService = Resolver.Resolve<ICryptoService>();
|
||||||
|
_authService = Resolver.Resolve<IAuthService>();
|
||||||
|
_deviceInfo = Resolver.Resolve<IDeviceInfo>();
|
||||||
|
_appIdService = Resolver.Resolve<IAppIdService>();
|
||||||
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
||||||
|
_syncService = Resolver.Resolve<ISyncService>();
|
||||||
|
_accountApiRepository = Resolver.Resolve<IAccountsApiRepository>();
|
||||||
|
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormEntryCell EmailCell { get; set; }
|
||||||
|
|
||||||
|
private void Init()
|
||||||
|
{
|
||||||
|
EmailCell = new FormEntryCell(AppResources.EmailAddress, entryKeyboard: Keyboard.Email,
|
||||||
|
useLabelAsPlaceholder: true, imageSource: "envelope", containerPadding: new Thickness(15, 20));
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -187,7 +187,7 @@ namespace Bit.App.Pages
|
||||||
Intent = TableIntent.Settings;
|
Intent = TableIntent.Settings;
|
||||||
EnableScrolling = false;
|
EnableScrolling = false;
|
||||||
HasUnevenRows = true;
|
HasUnevenRows = true;
|
||||||
EnableSelection = false;
|
EnableSelection = true;
|
||||||
VerticalOptions = LayoutOptions.Start;
|
VerticalOptions = LayoutOptions.Start;
|
||||||
NoFooter = true;
|
NoFooter = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,5 +39,30 @@ namespace Bit.App.Repositories
|
||||||
return ApiResult.Success(response.StatusCode);
|
return ApiResult.Success(response.StatusCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual async Task<ApiResult> PostPasswordHintAsync(PasswordHintRequest requestObj)
|
||||||
|
{
|
||||||
|
if(!Connectivity.IsConnected)
|
||||||
|
{
|
||||||
|
return HandledNotConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
using(var client = new ApiHttpClient())
|
||||||
|
{
|
||||||
|
var requestMessage = new TokenHttpRequestMessage(requestObj)
|
||||||
|
{
|
||||||
|
Method = HttpMethod.Post,
|
||||||
|
RequestUri = new Uri(client.BaseAddress, string.Concat(ApiRoute, "/password-hint")),
|
||||||
|
};
|
||||||
|
|
||||||
|
var response = await client.SendAsync(requestMessage);
|
||||||
|
if(!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
return await HandleErrorAsync(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ApiResult.Success(response.StatusCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue