using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone
{
///
/// 二次密码验证界面
///
public class PswSecondarySecurityForm : DialogCommonForm
{
#region ■ 变量声明___________________________
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// Touch ID验证的显示文本
/// 密码验证的显示文本
/// 手势验证的显示文本
/// 验证成功后的回调函数,如果不成功,不会调用这个东西
public void ShowForm(string i_TouchText, string i_PasswordText, string i_GestureText, Action SuccessAction)
{
//初始化中部信息
this.InitMiddleFrame(i_TouchText, i_PasswordText, i_GestureText, SuccessAction);
}
///
/// 初始化中部信息
///
/// Touch ID验证的显示文本
/// 密码验证的显示文本
/// 手势验证的显示文本
/// 验证成功后的回调函数,如果不成功,不会调用这个东西
private void InitMiddleFrame(string i_TouchText, string i_PasswordText, string i_GestureText, Action SuccessAction)
{
var frameBack = new FrameLayout();
frameBack.Y = Application.GetRealHeight(101);
frameBack.Gravity = Gravity.CenterHorizontal;
frameBack.Width = Application.GetRealWidth(965);
frameBack.Height = Application.GetRealHeight(1711);
frameBack.BackgroundColor = UserCenterColor.Current.White;
frameBack.Radius = (uint)Application.GetRealHeight(17);
bodyFrameLayout.AddChidren(frameBack);
//密码输入控件
var pswControl = new PswNumberInputControl(i_PasswordText, 4);
pswControl.Gravity = Gravity.CenterHorizontal;
pswControl.Y = Application.GetRealHeight(81);
frameBack.AddChidren(pswControl);
pswControl.InitControl();
//改变删除按钮的坐标
pswControl.ChangedDeleteButtonPoint(-1, pswControl.Height, false);
//添加关闭按钮
var btnClose = pswControl.AddCloseButton();
btnClose.ButtonClickEvent += (sender, e) =>
{
this.CloseForm();
};
pswControl.FinishInputEvent += (strPsw) =>
{
if (HdlUserCenterResourse.AccountOption.PswAuthentication != strPsw)
{
HdlUserCenterResourse.AccountOption.PasswordInputCount--;
if (HdlUserCenterResourse.AccountOption.PasswordInputCount <= 0)
{
//管理员身份验证失败,请重新登录
string msg2 = Language.StringByID(R.MyInternationalizationString.uCheckAdministratorFailAndReload);
this.ShowMassage(ShowMsgType.Tip, msg2);
HdlAccountLogic.Current.ReLoginAgain(Common.Config.Instance.Account);
return;
}
//密码错误,请重新输入
pswControl.SetErrorMsg(Language.StringByID(R.MyInternationalizationString.uOldPsswordIsError));
return;
}
//重置剩余密码次数
HdlUserCenterResourse.AccountOption.ResetPasswordCount();
//界面关闭
this.CloseForm();
SuccessAction?.Invoke();
SuccessAction = null;
};
//手势开锁
var btnGesture = new BottomLeftClickButton(frameBack.Width / 2, Application.GetRealHeight(127));
frameBack.AddChidren(btnGesture);
btnGesture.InitControl(i_GestureText);
if (string.IsNullOrEmpty(HdlUserCenterResourse.AccountOption.GestureAuthentication) == true)
{
//没有启用手势开锁
btnGesture.CanClick = false;
}
btnGesture.ButtonClickEvent += (sender, e) =>
{
var form = new PswGestureSecirityForm();
this.AddFormAndCloseNowForm(form, i_TouchText, i_PasswordText, i_GestureText, SuccessAction);
};
//Touch ID开锁
var btnTouch = new BottomRightClickButton(frameBack.Width - btnGesture.Width, btnGesture.Height);
frameBack.AddChidren(btnTouch);
btnTouch.InitControl(i_TouchText);
if (HdlUserCenterResourse.AccountOption.FingerprintAuthentication == false)
{
//没有启用Touch ID
btnTouch.CanClick = false;
}
btnTouch.ButtonClickEvent += (sender, e) =>
{
//二次检测
TouchIDUtils.TouchIDSupperType type = TouchIDUtils.getTouchIDSupperType();
if (type != TouchIDUtils.TouchIDSupperType.TouchID)
{
return;
}
//界面关闭
this.CloseForm();
TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent += (sender2, e2) =>
{
if (e2 == TouchIDUtils.TouchIDState.Success)
{
TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent = null;
//TouchID验证成功
SuccessAction?.Invoke();
SuccessAction = null;
}
else if (e2 == TouchIDUtils.TouchIDState.InputPassword)
{
TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent = null;
//密码验证
if (string.IsNullOrEmpty(HdlUserCenterResourse.AccountOption.PswAuthentication) == false)
{
var form = new PswSecondarySecurityForm();
this.AddFormAndCloseNowForm(form, i_TouchText, i_PasswordText, i_GestureText, SuccessAction);
}
//手势验证
else if (string.IsNullOrEmpty(HdlUserCenterResourse.AccountOption.GestureAuthentication) == false)
{
var form = new PswGestureSecirityForm();
this.AddFormAndCloseNowForm(form, i_TouchText, i_PasswordText, i_GestureText, SuccessAction);
}
else
{
//没有设置密码验证
this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uPasswordAuthenticationNotSettion));
}
}
};
TouchIDUtils.Instance.showTouchIDWithDescribe(null, null);
};
}
#endregion
#region ■ 界面关闭___________________________
public override void CloseFormBefore()
{
//取消事件
TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent = null;
base.CloseFormBefore();
}
#endregion
}
}