using System;
using Shared.Common;
using System.Text.RegularExpressions;
namespace Shared.Phone.UserCenter.User
{
///
/// 重置新密码
///
public class ForgotPasswordSetNewPasswordForm : UserCenterCommonForm
{
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
///
///
///
public void ShowForm(string account, string phoneOrEmail, string areaCode)
{
//设定标题
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.ResetPWD));
//初始化中部控件
this.InitMiddleFrame(account, phoneOrEmail, areaCode);
}
///
/// 初始化中部控件
///
///
///
///
private void InitMiddleFrame(string account, string phoneOrEmail, string areaCode)
{
this.Show(account, phoneOrEmail, areaCode);
}
#endregion
#region ■ 以下为复制郭雪城的代码_____________
///
/// 重置密码 areaCode在邮箱中不需要
///
/// Account.
/// Phone or email.
/// Area code.
private void Show(string account ,string phoneOrEmail, string areaCode = "")
{
ShowSetNewPWD(account,phoneOrEmail,areaCode);
}
void ShowSetNewPWD(string account, string phoneOrEmail,string areaCode="")
{
#region --midFL--
var passwordFL = new FrameLayout()
{
Y = Application.GetRealHeight(100),
Height = Application.GetRealHeight(100)
};
bodyFrameLayout.AddChidren(passwordFL);
var password = new EditText()
{
X = Application.GetRealWidth(CommonPage.XLeft),
Width = Application.GetRealWidth(700),
Height = Application.GetRealHeight(100)-1,
TextAlignment = TextAlignment.CenterLeft,
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
PlaceholderText = Language.StringByID(R.MyInternationalizationString.InputNewPWD),
PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
SecureTextEntry = true
};
passwordFL.AddChidren(password);
var hidenPWDbtn = new Button()
{
X = passwordFL.Width - Application.GetRealWidth(CommonPage.XLeft+100),
Width = Application.GetMinRealAverage(72),
Height = Application.GetMinRealAverage(72),
Gravity=Gravity.CenterVertical,
UnSelectedImagePath = "Account/HidenPWD.png",
SelectedImagePath = "Account/UnHidenPWD.png"
};
passwordFL.AddChidren(hidenPWDbtn);
var accountLine = new FrameLayout()
{
Y = Application.GetRealHeight(100)-1,
Height = 1,
BackgroundColor = ZigbeeColor.Current.GXCLineColor
};
passwordFL.AddChidren(accountLine);
var passwordConfirmFL = new FrameLayout()
{
Y = passwordFL.Bottom + Application.GetRealHeight(100),
Height = Application.GetRealHeight(100)
};
bodyFrameLayout.AddChidren(passwordConfirmFL);
var passwordConfirm = new EditText()
{
X = Application.GetRealWidth(CommonPage.XLeft),
Width = Application.GetRealWidth(700),
Height = Application.GetRealHeight(100) - 1,
TextAlignment = TextAlignment.CenterLeft,
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseConfirmNewPassword),
PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
SecureTextEntry = true
};
passwordConfirmFL.AddChidren(passwordConfirm);
var hidenPWDComfirmbtn = new Button()
{
X = passwordFL.Width - Application.GetRealWidth(CommonPage.XLeft+100),
Width = Application.GetMinRealAverage(72),
Height = Application.GetMinRealAverage(72),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "Account/HidenPWD.png",
SelectedImagePath = "Account/UnHidenPWD.png"
};
passwordConfirmFL.AddChidren(hidenPWDComfirmbtn);
var passwordConfirmLine = new FrameLayout()
{
Y = Application.GetRealHeight(100)-1,
Height = 1,
BackgroundColor = ZigbeeColor.Current.GXCLineColor
};
passwordConfirmFL.AddChidren(passwordConfirmLine);
var resetPWDBtn = new Button()
{
Width = Application.GetRealWidth(700),
Y = Application.GetRealHeight(1920 - 220 - 400),
Height = Application.GetRealHeight(110),
Radius = (uint)Application.GetRealHeight(55),
TextID = R.MyInternationalizationString.ResetPWD,
TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
TextAlignment = TextAlignment.Center,
TextSize = 15,
BackgroundColor = ZigbeeColor.Current.GXCButtonUnselectedColor,
SelectedBackgroundColor=ZigbeeColor.Current.GXCButtonBlueColor,
Gravity = Gravity.CenterHorizontal,
Enable = false,
IsSelected=false
};
bodyFrameLayout.AddChidren(resetPWDBtn);
//错误提示Btn
var loginErrorBtn = new Button()
{
Y = resetPWDBtn.Bottom + Application.GetRealHeight(50),
Width = Application.GetRealWidth(1080 - 100),
Height = Application.GetRealHeight(110),
TextColor = ZigbeeColor.Current.GXCRedColor,
Gravity = Gravity.CenterHorizontal
};
bodyFrameLayout.AddChidren(loginErrorBtn);
FrameLayout pwdStrengthFL = new FrameLayout()
{
Y = passwordFL.Bottom + Application.GetRealHeight(10),
Height = Application.GetRealHeight(60),
};
#endregion
#region event
FrameLayout addPWDStrengthFL()
{
passwordConfirmFL.Y = pwdStrengthFL.Bottom;
var pwdLength = new Button()
{
X = Application.GetRealWidth(100),
Height = Application.GetRealHeight(60),
TextID = R.MyInternationalizationString.YourPWDIsTooSample,
TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
TextAlignment = TextAlignment.CenterLeft,
SelectedTextColor = ZigbeeColor.Current.GXCTextBlackColor
};
pwdStrengthFL.AddChidren(pwdLength);
return pwdStrengthFL;
};
///
///密码为 数字递增
///
/// true, if number add was pwded, false otherwise.
/// Pwd.
bool pwdNumAdd(string pwd)
{
if (pwd.Length < 6) return true;
for (int i = 1; i < pwd.Length-1;i++)
{
if(pwd[i]!=pwd[i+1]-1) return false;
}
return true;
}
///
/// 密码为同一字符
///
/// true, if same was pwded, false otherwise.
/// Pwd.
bool pwdSame(string pwd)
{
if (pwd.Length < 6) return true;
for (int i = 1; i < pwd.Length - 1; i++)
{
if (pwd[i] != pwd[i + 1]) return false;
}
return true;
}
password.TextChangeEventHandler += (sender, e) =>
{
loginErrorBtn.Text = "";
if (pwdNumAdd(password.Text.Trim()) || pwdSame(password.Text.Trim()))
{
bodyFrameLayout.AddChidren(addPWDStrengthFL());
passwordConfirmFL.Y = addPWDStrengthFL().Bottom + Application.GetRealHeight(50);
}
else
{
addPWDStrengthFL().RemoveFromParent();
passwordConfirmFL.Y = passwordFL.Bottom + Application.GetRealHeight(100);
}
};
password.FoucsChanged += (sender, e) =>
{
addPWDStrengthFL().RemoveFromParent();
passwordConfirmFL.Y = passwordFL.Bottom + Application.GetRealHeight(100);
};
passwordConfirm.TextChangeEventHandler += (sender, e) =>
{
loginErrorBtn.Text = "";
if (passwordConfirm.Text.Trim().Length >= 6)
{
resetPWDBtn.Enable = resetPWDBtn.IsSelected = true;
}
else
{
resetPWDBtn.Enable = resetPWDBtn.IsSelected = false;
}
};
hidenPWDbtn.MouseUpEventHandler += (sender, e) =>
{
password.SecureTextEntry = !password.SecureTextEntry;
hidenPWDbtn.IsSelected = !hidenPWDbtn.IsSelected;
};
hidenPWDComfirmbtn.MouseUpEventHandler += (sender, e) =>
{
hidenPWDComfirmbtn.IsSelected = !hidenPWDComfirmbtn.IsSelected;
passwordConfirm.SecureTextEntry = !passwordConfirm.SecureTextEntry;
};
resetPWDBtn.MouseUpEventHandler += async (sender, e) =>
{
//先判断2次密码输入是否一致
if (password.Text.Trim() != passwordConfirm.Text.Trim())
{
var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.TwoPasswordInconsistency), Language.StringByID(R.MyInternationalizationString.Confrim));
alert.Show();
password.Text = "";
passwordConfirm.Text = "";
return;
}
CommonPage.Loading.Start();
string passwordText = password.Text.Trim();
try
{
string requestJson;
if (areaCode=="")
{
var reqDto = new SendDataToServer.ResetPasswordObj()
{
Account = account,
Password = password.Text,
AgainPassword = passwordConfirm.Text
};
requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(reqDto);
}
else
{
var reqDto = new SendDataToServer.ResetPasswordObj()
{
Account = account,
Password = password.Text.Trim(),
AreaCode=int.Parse(areaCode),
AgainPassword = passwordConfirm.Text.Trim()
};
requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(reqDto);
}
var revertObj =await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/ResetPassword", System.Text.Encoding.UTF8.GetBytes(requestJson));
if(revertObj==null)
{
CommonPage.Instance.FailureToServer();
return;
}
var stateCodeStr = revertObj.StateCode.ToUpper();
if (stateCodeStr == "SUCCESS")
{
var forgetWPDSuccessDialog = new Dialog();
forgetWPDSuccessDialog.Show();
var forgetSuccessView = new FrameLayout()
{
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
Gravity = Gravity.Center,
Width = Application.GetRealWidth(700),
Height = Application.GetRealHeight(550),
Radius =(uint)Application.GetRealHeight(30)
};
forgetWPDSuccessDialog.AddChidren(forgetSuccessView);
var forgetSuccessTip = new Button()
{
Y = Application.GetRealHeight(50),
Height = Application.GetRealHeight(100),
TextID = R.MyInternationalizationString.TIP,
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
TextAlignment = TextAlignment.Center,
TextSize = 18,
Gravity = Gravity.CenterHorizontal
};
forgetSuccessView.AddChidren(forgetSuccessTip);
var forgetSuccessContents = new Button()
{
Y = Application.GetRealHeight(50) + forgetSuccessTip.Bottom,
Height = Application.GetRealHeight(100),
TextID = R.MyInternationalizationString.ResetPWDSuccessPleaseLoginAgain,
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
TextAlignment = TextAlignment.Center,
Gravity = Gravity.CenterHorizontal
};
forgetSuccessView.AddChidren(forgetSuccessContents);
var confirmBtn = new Button()
{
Y = Application.GetRealHeight(100) + forgetSuccessContents.Bottom,
Width = Application.GetRealWidth(300),
Height = Application.GetRealHeight(100),
TextID = R.MyInternationalizationString.Confrim,
TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
TextAlignment = TextAlignment.Center,
TextSize = 18,
BackgroundColor = ZigbeeColor.Current.GXCButtonBlueColor,
Gravity = Gravity.CenterHorizontal,
Radius =(uint)Application.GetRealHeight(50)
};
forgetSuccessView.AddChidren(confirmBtn);
//重置密码成功回到登录界面
confirmBtn.MouseUpEventHandler += (sender1, e1) =>
{
forgetWPDSuccessDialog.Close();
this.RemoveFromParent();
UserCenterLogic.ReLoginAgain();
};
}
else if (stateCodeStr == "PARAMETEROREMPTY")
{
//提供的参数错误
loginErrorBtn.TextID = R.MyInternationalizationString.PARAMETEROREMPTY;
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.PARAMETEROREMPTY);
}
else if (stateCodeStr == "ACCOUNTNOEXISTS")
{
//账号不存在
loginErrorBtn.TextID = R.MyInternationalizationString.ACCOUNTNOEXISTS;
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ACCOUNTNOEXISTS);
}
else if(stateCodeStr == "FAIL")
{
//操作失败
loginErrorBtn.TextID = R.MyInternationalizationString.FAIL;
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FAIL);
}
else
{
loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed;
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.RequestServerFailed);
}
}
catch
{
loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed;
}
finally
{
CommonPage.Loading.Hide();
}
};
#endregion
}
#endregion
}
}