2016-07-21 03:57:00 +03:00
|
|
|
|
using System;
|
2016-07-20 05:38:12 +03:00
|
|
|
|
using Bit.iOS.Extension.Models;
|
|
|
|
|
using UIKit;
|
|
|
|
|
using XLabs.Ioc;
|
|
|
|
|
using Plugin.Settings.Abstractions;
|
2016-07-21 03:57:00 +03:00
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.iOS.Core.Utilities;
|
|
|
|
|
using Bit.App.Resources;
|
2016-07-22 03:59:55 +03:00
|
|
|
|
using System.Diagnostics;
|
2016-07-22 06:41:50 +03:00
|
|
|
|
using Bit.App;
|
2016-08-04 07:06:09 +03:00
|
|
|
|
using Bit.iOS.Core.Controllers;
|
2016-07-20 05:38:12 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.iOS.Extension
|
|
|
|
|
{
|
2016-08-04 07:06:09 +03:00
|
|
|
|
public partial class LockPinViewController : ExtendedUIViewController
|
2016-07-20 05:38:12 +03:00
|
|
|
|
{
|
2017-04-28 18:34:02 +03:00
|
|
|
|
private IAppSettingsService _appSettingsService;
|
2016-07-21 03:57:00 +03:00
|
|
|
|
private IAuthService _authService;
|
2016-07-20 05:38:12 +03:00
|
|
|
|
|
|
|
|
|
public LockPinViewController(IntPtr handle) : base(handle)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
public Context Context { get; set; }
|
2016-07-26 04:32:15 +03:00
|
|
|
|
public LoadingViewController LoadingController { get; set; }
|
2016-07-20 05:38:12 +03:00
|
|
|
|
|
|
|
|
|
public override void ViewWillAppear(bool animated)
|
|
|
|
|
{
|
|
|
|
|
UINavigationBar.Appearance.ShadowImage = new UIImage();
|
|
|
|
|
UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
|
|
|
|
|
base.ViewWillAppear(animated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ViewDidLoad()
|
|
|
|
|
{
|
2017-04-28 18:34:02 +03:00
|
|
|
|
_appSettingsService = Resolver.Resolve<IAppSettingsService>();
|
2016-07-21 03:57:00 +03:00
|
|
|
|
_authService = Resolver.Resolve<IAuthService>();
|
2016-07-20 05:38:12 +03:00
|
|
|
|
|
2016-12-27 05:22:55 +03:00
|
|
|
|
NavItem.Title = AppResources.VerifyPIN;
|
|
|
|
|
CancelButton.Title = AppResources.Cancel;
|
2016-07-20 05:38:12 +03:00
|
|
|
|
View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f);
|
|
|
|
|
|
|
|
|
|
var descriptor = UIFontDescriptor.PreferredBody;
|
2016-07-23 22:58:50 +03:00
|
|
|
|
PinLabel.Font = UIFont.FromName("Courier", 35);
|
|
|
|
|
|
2016-12-27 05:22:55 +03:00
|
|
|
|
InstructionLabel.Text = AppResources.EnterPIN;
|
2016-07-23 22:58:50 +03:00
|
|
|
|
InstructionLabel.LineBreakMode = UILineBreakMode.WordWrap;
|
|
|
|
|
InstructionLabel.Lines = 0;
|
|
|
|
|
InstructionLabel.Font = UIFont.FromDescriptor(descriptor, descriptor.PointSize * 0.8f);
|
|
|
|
|
InstructionLabel.TextColor = new UIColor(red: 0.47f, green: 0.47f, blue: 0.47f, alpha: 1.0f);
|
2016-07-21 03:57:00 +03:00
|
|
|
|
|
2016-07-21 05:48:53 +03:00
|
|
|
|
PinTextField.EditingChanged += PinTextField_EditingChanged;
|
2016-07-20 05:38:12 +03:00
|
|
|
|
|
|
|
|
|
base.ViewDidLoad();
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 03:57:00 +03:00
|
|
|
|
public override void ViewDidAppear(bool animated)
|
|
|
|
|
{
|
|
|
|
|
base.ViewDidAppear(animated);
|
|
|
|
|
PinTextField.BecomeFirstResponder();
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 05:48:53 +03:00
|
|
|
|
private void PinTextField_EditingChanged(object sender, EventArgs e)
|
2016-07-21 03:57:00 +03:00
|
|
|
|
{
|
2016-07-21 06:51:31 +03:00
|
|
|
|
SetLabelText();
|
2016-07-21 03:57:00 +03:00
|
|
|
|
|
|
|
|
|
if(PinTextField.Text.Length >= 4)
|
|
|
|
|
{
|
|
|
|
|
if(PinTextField.Text == _authService.PIN)
|
|
|
|
|
{
|
2016-07-22 03:59:55 +03:00
|
|
|
|
Debug.WriteLine("BW Log, Start Dismiss PIN controller.");
|
2017-04-28 18:34:02 +03:00
|
|
|
|
_appSettingsService.Locked = false;
|
2016-07-21 03:57:00 +03:00
|
|
|
|
PinTextField.ResignFirstResponder();
|
2016-07-26 04:32:15 +03:00
|
|
|
|
LoadingController.DismissLockAndContinue();
|
2016-07-21 03:57:00 +03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// TODO: keep track of invalid attempts and logout?
|
|
|
|
|
|
2016-11-26 01:05:14 +03:00
|
|
|
|
var alert = Dialogs.CreateAlert(null, AppResources.InvalidPIN, AppResources.Ok, (a) =>
|
2016-07-21 06:51:31 +03:00
|
|
|
|
{
|
|
|
|
|
PinTextField.Text = string.Empty;
|
|
|
|
|
SetLabelText();
|
|
|
|
|
PinTextField.BecomeFirstResponder();
|
|
|
|
|
});
|
2016-07-21 03:57:00 +03:00
|
|
|
|
PresentViewController(alert, true, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 06:51:31 +03:00
|
|
|
|
private void SetLabelText()
|
|
|
|
|
{
|
|
|
|
|
var newText = string.Empty;
|
|
|
|
|
for(int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
newText += PinTextField.Text.Length <= i ? "- " : "● ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PinLabel.Text = newText.TrimEnd();
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-20 05:38:12 +03:00
|
|
|
|
partial void CancelButton_Activated(UIBarButtonItem sender)
|
|
|
|
|
{
|
2016-07-26 04:32:15 +03:00
|
|
|
|
LoadingController.CompleteRequest(null);
|
2016-07-20 05:38:12 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|