using System;
|
using Shared.Common;
|
using System.Timers;
|
using System.Text.RegularExpressions;
|
|
namespace Shared.Phone.UserCenter.User
|
{
|
/// <summary>
|
/// 根据邮箱找回密码
|
/// </summary>
|
public class ForgotPasswordByEmailForm : UserCenterCommonForm
|
{
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
public void ShowForm()
|
{
|
//设定标题
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.ForgotPassword));
|
|
//初始化中部控件
|
this.InitMiddleFrame();
|
}
|
|
|
/// <summary>
|
/// 初始化中部控件
|
/// </summary>
|
private void InitMiddleFrame()
|
{
|
this.ShowForgotPWD();
|
}
|
|
#endregion
|
|
#region ■ 以下为复制郭雪城的代码_____________
|
|
/// <summary>
|
///
|
/// </summary>
|
void ShowForgotPWD()
|
{
|
var t = new Timer();
|
var dateBegin = new DateTime();
|
|
#region --midFL--
|
|
var accountTIPS = new Button()
|
{
|
Width = Application.GetRealWidth(1080 - CommonPage.XLeft * 2),
|
Height = Application.GetRealHeight(100),
|
TextAlignment = TextAlignment.CenterLeft,
|
Gravity = Gravity.CenterHorizontal,
|
TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
|
TextID = R.MyInternationalizationString.PleaseInputTheEmailAndYouWillHaveVerificatoinCode
|
};
|
bodyFrameLayout.AddChidren(accountTIPS);
|
|
var accountFL = new FrameLayout()
|
{
|
Y = accountTIPS.Bottom + Application.GetRealHeight(100),
|
Height = Application.GetRealHeight(100)
|
};
|
bodyFrameLayout.AddChidren(accountFL);
|
|
var accountET = new EditText()
|
{
|
X = Application.GetRealWidth(CommonPage.XLeft),
|
Width = Application.GetRealWidth(800),
|
Height = Application.GetRealHeight(100) - 1,
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputEmail),
|
PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor
|
};
|
accountFL.AddChidren(accountET);
|
|
var accountLine = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(100) - 1,
|
Height = 1,
|
BackgroundColor = ZigbeeColor.Current.GXCLineColor
|
};
|
accountFL.AddChidren(accountLine);
|
|
var verificationCodeFL = new FrameLayout()
|
{
|
Y = accountFL.Bottom + Application.GetRealHeight(100),
|
Height = Application.GetRealHeight(100)
|
};
|
bodyFrameLayout.AddChidren(verificationCodeFL);
|
|
var verificationCodeET = new EditText()
|
{
|
X = Application.GetRealWidth(CommonPage.XLeft),
|
Width = Application.GetRealWidth(500),
|
Height = Application.GetRealHeight(100) - 1,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputVerificationCode),
|
PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor
|
};
|
verificationCodeFL.AddChidren(verificationCodeET);
|
|
var verificationCodeLine = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(100) - 1,
|
Height = 1,
|
BackgroundColor = ZigbeeColor.Current.GXCLineColor
|
};
|
verificationCodeFL.AddChidren(verificationCodeLine);
|
|
var sendCodeBtn = new Button()
|
{
|
X = Application.GetRealWidth(1080 - 400 - CommonPage.XLeft),
|
Width = Application.GetRealWidth(400),
|
Y = Application.GetRealHeight(100) + verificationCodeFL.Bottom,
|
Height = Application.GetRealHeight(100),
|
TextID = R.MyInternationalizationString.SendVerificationCode,
|
TextColor = ZigbeeColor.Current.GXCButtonUnselectedColor,
|
SelectedTextColor = ZigbeeColor.Current.GXCTextBlueColor,
|
TextAlignment = TextAlignment.CenterRight,
|
Enable = false,
|
IsSelected = false,
|
};
|
bodyFrameLayout.AddChidren(sendCodeBtn);
|
|
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);
|
#endregion
|
|
#region --event--
|
accountET.TextChangeEventHandler += (sender, e) =>
|
{
|
loginErrorBtn.Text = "";
|
if (accountET.Text.Trim().Length > 0)
|
{
|
sendCodeBtn.Enable = sendCodeBtn.IsSelected = true;
|
}
|
else
|
{
|
sendCodeBtn.Enable = sendCodeBtn.IsSelected = false;
|
}
|
};
|
verificationCodeET.TextChangeEventHandler += (sender, e) =>
|
{
|
loginErrorBtn.Text = "";
|
if (verificationCodeET.Text.Trim().Length > 0)
|
{
|
resetPWDBtn.Enable = resetPWDBtn.IsSelected = true;
|
}
|
else
|
{
|
resetPWDBtn.Enable = resetPWDBtn.IsSelected = false;
|
}
|
};
|
|
sendCodeBtn.MouseUpEventHandler += async (sender, e) =>
|
{
|
var reg = new Regex(CommonPage.EmailRegexStr);
|
var ss = reg.Match(accountET.Text.Trim());
|
//校验邮箱
|
if (!ss.Success)
|
{
|
var aler = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.PleaseInputTheCorrectEmail), Language.StringByID(R.MyInternationalizationString.Confrim));
|
aler.Show();
|
accountET.Text = "";
|
}
|
else
|
{
|
string phoneNum = accountET.Text.Trim();
|
CommonPage.Loading.Start();
|
try
|
{
|
var reqDtoSignPhone = new SendDataToServer.LoginSendVerCodeObj()
|
{
|
Account = phoneNum,
|
Company = 0,
|
AreaCode = 0,
|
Language = CommonPage.ZigBeeLanguage
|
};
|
var requesetJson = Newtonsoft.Json.JsonConvert.SerializeObject(reqDtoSignPhone);
|
var requestRevertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/LoginSendVerCode", System.Text.Encoding.UTF8.GetBytes(requesetJson));
|
if (requestRevertObj == null)
|
{
|
CommonPage.Instance.FailureToServer();
|
return;
|
}
|
var stateCodeStr = requestRevertObj.StateCode.ToUpper();
|
if (stateCodeStr == "SUCCESS")
|
{
|
TimeBegin();
|
var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.SendVerificationCodeSuccess), Language.StringByID(R.MyInternationalizationString.Confrim));
|
alert.Show();
|
}
|
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
|
{
|
loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed;
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.RequestServerFailed);
|
}
|
}
|
catch
|
{
|
loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed;
|
}
|
finally
|
{
|
CommonPage.Loading.Hide();
|
}
|
}
|
};
|
|
resetPWDBtn.MouseUpEventHandler += async (sender, e) =>
|
{
|
var vCode = verificationCodeET.Text.Trim();
|
var vPhone = accountET.Text.Trim();
|
CommonPage.Loading.Start();
|
try
|
{
|
var reqDto = new SendDataToServer.ValidatorCodeObj()
|
{
|
Account = vPhone,
|
Code = int.Parse(vCode),
|
AreaCode = 0,
|
Language = CommonPage.ZigBeeLanguage
|
};
|
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(reqDto);
|
//验证验证码
|
var requestRevertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/ValidatorCode", System.Text.Encoding.UTF8.GetBytes(requestJson));
|
if (requestRevertObj == null)
|
{
|
CommonPage.Instance.FailureToServer();
|
return;
|
}
|
var stateCodeStr = requestRevertObj.StateCode.ToUpper();
|
if (stateCodeStr == "SUCCESS")
|
{
|
ModifyPWD(vPhone);
|
}
|
else if (stateCodeStr == "VALIDCODEANDPHONENOEQUAL")
|
{
|
//验证码错误
|
loginErrorBtn.TextID = R.MyInternationalizationString.VALIDCODEANDPHONENOEQUAL;
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.VALIDCODEANDPHONENOEQUAL);
|
}
|
else if (stateCodeStr == "SENDFAIL")
|
{
|
//验证码发送失败
|
loginErrorBtn.TextID = R.MyInternationalizationString.SENDFAIL;
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.SENDFAIL);
|
}
|
else if (stateCodeStr == "ACCOUNTNOEXISTS")
|
{
|
//账号不存在
|
loginErrorBtn.TextID = R.MyInternationalizationString.ACCOUNTNOEXISTS;
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ACCOUNTNOEXISTS);
|
}
|
else if (stateCodeStr == "PARAMETEROREMPTY")
|
{
|
//提供的参数错误
|
loginErrorBtn.TextID = R.MyInternationalizationString.PARAMETEROREMPTY;
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.PARAMETEROREMPTY);
|
}
|
else
|
{
|
loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed;
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.RequestServerFailed);
|
}
|
}
|
catch
|
{
|
loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed;
|
}
|
finally
|
{
|
CommonPage.Loading.Hide();
|
}
|
};
|
void ModifyPWD(string account)
|
{
|
var newPWD = new ForgotPasswordSetNewPasswordForm();
|
this.AddForm(newPWD, account, "email", string.Empty);
|
}
|
void TimeBegin()
|
{
|
t.Interval = 1000;
|
t.AutoReset = true;
|
t.Enabled = true;
|
t.Elapsed += new ElapsedEventHandler(TimeOut);
|
//启动计时器倒计时-60s
|
t.Start();
|
dateBegin = DateTime.Now;
|
}
|
void TimeOut(object source, System.Timers.ElapsedEventArgs e)
|
{
|
var span = DateTime.Now - dateBegin;
|
if (span.TotalSeconds <= 61)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
sendCodeBtn.Text = Convert.ToInt16((60 - span.TotalSeconds)) + "s" + Language.StringByID(R.MyInternationalizationString.SendVerificationCode);
|
sendCodeBtn.Enable = false;
|
});
|
}
|
else
|
{
|
Application.RunOnMainThread(() =>
|
{
|
sendCodeBtn.Enable = true;
|
sendCodeBtn.TextID = R.MyInternationalizationString.SendVerificationCode;
|
t.Stop();
|
t.Close();
|
});
|
}
|
}
|
#endregion
|
}
|
|
#endregion
|
}
|
}
|