using System;
using System.Text.RegularExpressions;
namespace Shared.SimpleControl.Phone
{
public class ForgotPassword : Dialog
{
PageLayout bodyPageView;
///
/// 构造函数
///
public ForgotPassword ()
{
BackgroundColor = SkinStyle.Current.MainColor;
ForgotPasswordShow ();
}
void ForgotPasswordShow ()
{
#region 标题
var topView = new FrameLayout () {
Y = Application.GetRealHeight (36),
Height = Application.GetRealHeight (90),
};
AddChidren (topView);
var title = new Button () {
TextAlignment = TextAlignment.Center,
Text = "Forgot password?",
TextSize = 19,
TextColor = SkinStyle.Current.TextColor1
};
topView.AddChidren (title);
//var logo = new Button () {
// Width = Application.GetRealWidth (154),
// Height = Application.GetRealHeight (90),
// X = Application.GetRealWidth (486),
// UnSelectedImagePath = MainPage.LogoString,
// Gravity = Gravity.CenterVertical,
//};
//topView.AddChidren (logo);
var back = new Button () {
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (85),
UnSelectedImagePath = "Item/Back.png",
//SelectedImagePath = "Item/BackSelected.png",
Gravity = Gravity.CenterVertical,
};
topView.AddChidren (back);
back.MouseUpEventHandler += (sender, e) => {
new AccountLogin ().Show ();
Close ();
};
#endregion
bodyPageView = new PageLayout () {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (1136 - 126),
Y = topView.Bottom,
BackgroundColor = SkinStyle.Current.ViewColor,
};
AddChidren (bodyPageView);
bodyPageView.PageChange += ( sender, e) => {
if (bodyPageView.ChildrenCount - 2 == e) {
bodyPageView.RemoveAt (bodyPageView.ChildrenCount - 1);
}
Utlis.WriteLine ("D" + e.ToString ());
};
FrameLayout bodyView = new FrameLayout ();
bodyPageView.AddChidren (bodyView);
bodyPageView.IsShowPoint = false;
FrameLayout languageView = new FrameLayout () {
Gravity = Gravity.CenterHorizontal,
Y = Application.GetRealHeight (20),
Width = Application.GetRealWidth (500),
Height = Application.GetRealHeight (85),
Radius = 5,
BorderColor = SkinStyle.Current.Transparent,
BorderWidth = 0,
};
bodyView.AddChidren (languageView);
Button btnEmailRegistration = new Button () {
Width = Application.GetRealWidth (250),
BackgroundColor = SkinStyle.Current.SubtitleView,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
TextID = R.MyInternationalizationString.MailboxAccount,
TextAlignment = TextAlignment.Center,
IsSelected = true,
TextColor = SkinStyle.Current.TextColor2,
};
languageView.AddChidren (btnEmailRegistration);
Button btnPhoneRegistration = new Button () {
X = btnEmailRegistration.Right,
Width = Application.GetRealWidth (250),
BackgroundColor = SkinStyle.Current.SubtitleView,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
TextID = R.MyInternationalizationString.MobileAccount,
TextAlignment = TextAlignment.Center,
TextColor = SkinStyle.Current.TextColor2,
};
languageView.AddChidren (btnPhoneRegistration);
FrameLayout FrameLayoutView = new FrameLayout () {
Y = languageView.Bottom,
Height = Application.GetRealHeight (1136 - 126 - 105),
};
bodyView.AddChidren (FrameLayoutView);
btnEmailRegistration.MouseUpEventHandler += (sender, e) => {
btnEmailRegistration.IsSelected = true;
btnPhoneRegistration.IsSelected = false;
EmailForgot (FrameLayoutView);
};
btnPhoneRegistration.MouseUpEventHandler += (sender, e) => {
btnEmailRegistration.IsSelected = false;
btnPhoneRegistration.IsSelected = true;
PhoneReagistrationView (FrameLayoutView);
};
EmailForgot (FrameLayoutView);
btnPhoneRegistration.RemoveFromParent ();
btnEmailRegistration.IsSelected = false;
btnEmailRegistration.BackgroundColor = SkinStyle.Current.Transparent;
btnEmailRegistration.X = Application.GetRealWidth (125);
}
void EmailForgot (FrameLayout FrameLayoutView)
{
FrameLayoutView.RemoveAll ();
var viewX = (Application.GetRealWidth (640) - Application.GetMinRealAverage (500)) / 2;
EditText Register_Email_Address = new EditText () {
Width = Application.GetMinRealAverage (500),
Height = Application.GetMinRealAverage (85),
X = viewX,
Y = Application.GetRealHeight (100),
UnSelectedImagePath = "Register/Register_Email_Address.png",
PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor,
PlaceholderText = Language.StringByID (R.MyInternationalizationString.EmailAddress),
TextAlignment = TextAlignment.Center,
Radius = (uint)Application.GetRealHeight (0),
TextColor = SkinStyle.Current.TextColor1,
};
FrameLayoutView.AddChidren (Register_Email_Address);
Register_Email_Address.EditorEnterAction += (obj) => {
Register_Email_Address.Foucs = false;
Application.HideSoftInput ();
};
Button Register_Send = new Button () {
Width = Application.GetRealWidth (247),
Height = Application.GetRealHeight (89),
X = Application.GetRealWidth ((640 - 247) / 2),
Y = Register_Email_Address.Bottom + Application.GetRealHeight (120),
BackgroundColor = SkinStyle.Current.ButtonColor1,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
TextID = R.MyInternationalizationString.Send,
TextColor = SkinStyle.Current.TextColor2,
TextAlignment = TextAlignment.Center,
Radius = 5,
BorderColor = SkinStyle.Current.Transparent,
BorderWidth = 0,
};
FrameLayoutView.AddChidren (Register_Send);
Register_Send.MouseDownEventHandler += (sender, e) => {
Register_Send.IsSelected = true;
};
Register_Send.MouseUpEventHandler += (sender, e) => {
MainPage.Loading.Start ("Please wait...");
string emailAccount = Register_Email_Address.Text.Trim ();
Register_Send.Enable = false;
new System.Threading.Thread (() => {
System.Threading.Thread.Sleep (10000);
Application.RunOnMainThread (() => {
try {
if (Register_Send != null)
Register_Send.Enable = true;
} catch { }
});
}) { IsBackground = true}.Start();
System.Threading.Tasks.Task.Run (() => {
try {
Register_Send.IsSelected = false;
//var reg = new Regex ("^\\s*([A-Za-z0-9_-]+(\\.\\w+)*@(\\w+\\.)+\\w{2,5})\\s*$");
//var ss = reg.Match (emailAccount);
if (!CommonUtlis.Current.CheckEmail (emailAccount)) {
Application.RunOnMainThread (() => {
new Alert ("", Language.StringByID (R.MyInternationalizationString.PleaseCheckEmailAddressCorrectly),
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
});
} else {
var requestObj = new YdForgetPasswordObj () { Account = emailAccount, Company = MainPage.SoftSmsType };
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
var requestRevertObj = MainPage.RequestHttps (API.YdForgetPassword, requestJson);
if (requestRevertObj.StateCode.ToUpper() == "SUCCESS") {
Application.RunOnMainThread (() => {
this.Close ();
new Alert ("", "A reset link has been sent to you email ID, Please check.", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
new AccountLogin (emailAccount, "").Show ();
});
} else {
ShowYdForgetPasswordErrorInfo (requestRevertObj.StateCode);
}
}
} catch {
Application.RunOnMainThread (() => {
new Alert ("", Language.StringByID (R.MyInternationalizationString.CheckInternet), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
});
} finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
});
}
});
};
}
///
///* (1)Success 则 [调用此接口操作成功], ResponseData则为null
///* (2)ParameterOrEmpty,则响应字段中 [ErrorInfo] 为错误信息, ResponseData则为null
///* (3)AccountNoExists,则响应字段中 [ErrorInfo] 为错误信息 [帐号不存在!], ResponseData则为null
///* (4)SendEmailFail,则响应字段中 [ErrorInfo] 为错误信息 [发送邮件失败!], ResponseData则为null
///
///
void ShowYdForgetPasswordErrorInfo (string stateCodeStr)
{
string mes = "";
//2020-01-06 待补充
if (stateCodeStr == "AccountNoExists") {
mes = ErrorCode.ACCOUNTNOEXISTS;
} else if (stateCodeStr == "SendEmailFail") {
mes = ErrorCode.SendEmailFail;
} else if (stateCodeStr == ErrorCode.NetworkError) {
mes = ErrorCode.NetworkError;
} else {
mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr;
}
if (!string.IsNullOrEmpty (mes)) {
Application.RunOnMainThread (() => {
new Alert ("", mes, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
});
}
}
void PhoneReagistrationView (FrameLayout registrationView)
{
registrationView.RemoveAll ();
Button btnPhone = new Button () {
Width = Application.GetRealWidth (500),
Height = Application.GetRealHeight (85),
Gravity = Gravity.CenterHorizontal,
Y = Application.GetRealHeight (20),
TextID = R.MyInternationalizationString.PhoneNumber,
TextAlignment = TextAlignment.CenterLeft,
TextSize = 12,
TextColor = SkinStyle.Current.TextColor1,
};
registrationView.AddChidren (btnPhone);
FrameLayout phoneNumView = new FrameLayout () {
Width = Application.GetRealWidth (500),
Height = Application.GetRealHeight (85),
Gravity = Gravity.CenterHorizontal,
Y = btnPhone.Bottom,
BorderWidth = 1,
Radius = 5,
BorderColor = SkinStyle.Current.BorderColor,
//Text = "1270166900@qq.com"
};
registrationView.AddChidren (phoneNumView);
EditText etPhoneNumber = new EditText () {
TextAlignment = TextAlignment.Center,
TextColor = SkinStyle.Current.TextColor1,
};
phoneNumView.AddChidren (etPhoneNumber);
Button btnNext = new Button () {
Y = phoneNumView.Bottom + Application.GetRealHeight (20),
Width = Application.GetRealWidth (500),
Height = Application.GetRealHeight (85),
Gravity = Gravity.CenterHorizontal,
Radius = 5,
BorderColor = SkinStyle.Current.Transparent,
BorderWidth = 0,
BackgroundColor = SkinStyle.Current.SubtitleView,
SelectedBackgroundColor = SkinStyle.Current.MainColor,
TextID = R.MyInternationalizationString.Next,
TextAlignment = TextAlignment.Center,
Enable = false,
TextColor = SkinStyle.Current.TextColor2,
};
registrationView.AddChidren (btnNext);
btnNext.MouseUpEventHandler += (sender, e) => {
string phoneNum = etPhoneNumber.Text.Trim ();
MainPage.Loading.Start ("Please wait...");
System.Threading.Tasks.Task.Run (() => {
try {
var requestObj = new SignPhoneObj () { Phone = phoneNum, Company = MainPage.SoftSmsType };
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
var requestRevertObj = MainPage.RequestHttps ("SignPhone", requestJson);
if (requestRevertObj.StateCode.ToUpper() == "SUCCESS") {
Application.RunOnMainThread (() => {
InitSMSView (phoneNum);
bodyPageView.PageIndex = bodyPageView.ChildrenCount - 1;
});
}
} catch {
MainPage.FailureToServer ();
} finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
});
}
});
};
etPhoneNumber.TextChangeEventHandler += (sender, e) => {
if (e.Length > 11) {
etPhoneNumber.Text = e.Remove (11);
return;
}
if (e.Length > 6) {
btnNext.IsSelected = btnNext.Enable = true;
Regex reg = new Regex ("^\\d+$");
var mFalg = reg.Match (etPhoneNumber.Text.Trim ());
if (mFalg.Success) {
btnNext.IsSelected = btnNext.Enable = true;
} else {
new Tip () { CloseTime = 3, Text = Language.StringByID (R.MyInternationalizationString.PhoneNumberErorr), Direction = AMPopTipDirection.Down }.Show (etPhoneNumber);
}
} else if (e.Length < 6) {
btnNext.IsSelected = btnNext.Enable = false;
}
};
}
void InitSMSView (string mobileNumber)
{
FrameLayout smsChencView = new FrameLayout ();
bodyPageView.AddChidren (smsChencView);
Button btnTitle = new Button () {
Gravity = Gravity.CenterHorizontal,
Y = Application.GetRealHeight (50),
Width = Application.GetRealWidth (500),
Height = Application.GetRealHeight (85),
TextID = R.MyInternationalizationString.MobileVerificationCode,
TextColor = SkinStyle.Current.TextColor1,
TextAlignment = TextAlignment.CenterLeft,
};
smsChencView.AddChidren (btnTitle);
EditText etCode = new EditText () {
Width = Application.GetRealWidth (500),
Height = Application.GetRealHeight (85),
Gravity = Gravity.CenterHorizontal,
Y = btnTitle.Bottom,
BorderWidth = 1,
Radius = 5,
BorderColor = SkinStyle.Current.BorderColor,
TextAlignment = TextAlignment.Center
//Text = "1270166900@qq.com"
};
smsChencView.AddChidren (etCode);
Button btnNext = new Button () {
Y = etCode.Bottom + Application.GetRealHeight (20),
Width = Application.GetRealWidth (500),
Height = Application.GetRealHeight (85),
Gravity = Gravity.CenterHorizontal,
Radius = 5,
BorderColor = SkinStyle.Current.Transparent,
BorderWidth = 0,
BackgroundColor = SkinStyle.Current.SubtitleView,
SelectedBackgroundColor = SkinStyle.Current.MainColor,
TextID = R.MyInternationalizationString.Next,
TextAlignment = TextAlignment.Center,
Enable = false,
TextColor = SkinStyle.Current.TextColor1,
};
smsChencView.AddChidren (btnNext);
etCode.TextChangeEventHandler += (sender, e) => {
if (e.Length > 6) {
etCode.Text = e.Remove (6);
} else if (e.Length == 6) {
btnNext.IsSelected = btnNext.Enable = true;
} else {
btnNext.IsSelected = btnNext.Enable = false;
}
};
btnNext.MouseUpEventHandler += (sender, e) => {
string vCode = etCode.Text.Trim ();
MainPage.Loading.Start ("Please wait...");
System.Threading.Tasks.Task.Run (() => {
try {
var requestObj = new ValidateSmsCodeObj () { Phone = mobileNumber, Code = vCode };
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
var requestRevertObj = MainPage.RequestHttps ("ValidateSmsCode", requestJson);
if (requestRevertObj.StateCode.ToUpper() == "SUCCESS") {
Application.RunOnMainThread (() => {
InitMobilePasswrod (mobileNumber);
bodyPageView.PageIndex = bodyPageView.ChildrenCount - 1;
});
}
} catch {
MainPage.FailureToServer ();
} finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
});
}
});
};
}
void InitMobilePasswrod (string mobileNumber)
{
FrameLayout mobileChencView = new FrameLayout ();
bodyPageView.AddChidren (mobileChencView);
Button btnPassword = new Button () {
Gravity = Gravity.CenterHorizontal,
Y = Application.GetRealHeight (50),
Width = Application.GetRealWidth (500),
Height = Application.GetRealHeight (85),
TextID = R.MyInternationalizationString.Password,
TextColor = SkinStyle.Current.TextColor1,
TextAlignment = TextAlignment.CenterLeft,
};
mobileChencView.AddChidren (btnPassword);
EditText etPassword = new EditText () {
Width = Application.GetRealWidth (500),
Height = Application.GetRealHeight (85),
Gravity = Gravity.CenterHorizontal,
Y = btnPassword.Bottom,
BorderWidth = 1,
Radius = 5,
BorderColor = SkinStyle.Current.BorderColor,
SecureTextEntry = true,
TextAlignment = TextAlignment.Center
//Text = "1270166900@qq.com"
};
mobileChencView.AddChidren (etPassword);
Button btnConfrimPassword = new Button () {
Gravity = Gravity.CenterHorizontal,
Y = etPassword.Bottom + Application.GetRealHeight (20),
Width = Application.GetRealWidth (500),
Height = Application.GetRealHeight (85),
TextID = R.MyInternationalizationString.ConfirmPassword,
TextColor = SkinStyle.Current.TextColor1,
TextAlignment = TextAlignment.CenterLeft,
};
mobileChencView.AddChidren (btnConfrimPassword);
EditText etConfrimPassword = new EditText () {
Width = Application.GetRealWidth (500),
Height = Application.GetRealHeight (85),
Gravity = Gravity.CenterHorizontal,
Y = btnConfrimPassword.Bottom,
BorderWidth = 1,
Radius = 5,
BorderColor = SkinStyle.Current.BorderColor,
SecureTextEntry = true,
TextAlignment = TextAlignment.Center
};
mobileChencView.AddChidren (etConfrimPassword);
Button btnConfirem = new Button () {
Gravity = Gravity.CenterHorizontal,
Y = etConfrimPassword.Bottom + Application.GetRealHeight (50),
Width = Application.GetRealWidth (500),
Height = Application.GetRealHeight (85),
TextID = R.MyInternationalizationString.Confrim,
TextColor = SkinStyle.Current.TextColor1,
TextAlignment = TextAlignment.Center,
BackgroundColor = SkinStyle.Current.MainColor
};
mobileChencView.AddChidren (btnConfirem);
btnConfirem.MouseUpEventHandler += (sender, e) => {
if (etPassword.Text.Trim ().Length < 6) {
new Alert ("", Language.StringByID (R.MyInternationalizationString.PasswordLenghtTip),
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
return;
}
if (etPassword.Text.Trim () != etConfrimPassword.Text.Trim ()) {
new Alert ("", Language.StringByID (R.MyInternationalizationString.RepeatPasswordsDidNotmatch),
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
return;
}
string newpw = etConfrimPassword.Text.Trim ();
MainPage.Loading.Start ("Lading...");
string passwordText = etPassword.Text.Trim ();
System.Threading.Tasks.Task.Run (() => {
try {
var requestObj = new ForgetPasswordActionObj () { Account = mobileNumber, Password = newpw };
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
var revertObj = MainPage.RequestHttps ("ForgetPasswordAction", requestJson);
if (revertObj.StateCode.ToUpper() == "SUCCESS") {
Application.RunOnMainThread (() => {
new Alert ("", Language.StringByID (R.MyInternationalizationString.ThePerationWasSuccessful),
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
Close ();
new AccountLogin (mobileNumber, passwordText).Show ();
});
}
} catch {
Application.RunOnMainThread (() => {
new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToServer),
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
});
} finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
});
}
});
};
}
}
}