JLChen
2020-12-09 e87985ec1dcb69beedaf9f95e8e7aba14b7c08d6
HDL_ON/UI/UI1-Login/ForgetPasswordPageBLL.cs
@@ -30,6 +30,12 @@
            //选择手机方式
            btnPhoneLogin.MouseUpEventHandler += (sender, e) =>
            {
                if (registerType == 0)
                    return;
                etAccount.IsNumberKeyboardType = true;
                etAccount.Text = registerPhone;
                etPassword.Text = "";
                etRepeatPassword.Text = "";
                #region 切换选中按钮
                btnGetVerificationCode_Phone.Visible = true;
                btnGetVerificationCode_Mail.Visible = false;
@@ -37,7 +43,7 @@
                btnEmailLogin.TextSize = CSS_FontSize.TextFontSize;
                btnPhoneLogin.TextColor = CSS_Color.MainColor;
                btnPhoneLogin.TextSize = CSS_FontSize.EmphasisFontSize_Secondary;
                etAccount.PlaceholderText = Language.StringByID(StringId.PlsEntryCorrectMobilNeumber);
                etAccount.PlaceholderText = Language.StringByID(StringId.PlsEntryPhoneNumber);
                #endregion
                #region 切换方式方式及图标
@@ -53,6 +59,12 @@
            //选择邮箱方式
            btnEmailLogin.MouseUpEventHandler += (sender, e) =>
            {
                if (registerType == 1)
                    return;
                etAccount.IsNumberKeyboardType = false;
                etAccount.Text = registerEmail;
                etPassword.Text = "";
                etRepeatPassword.Text = "";
                #region 切换选中按钮
                btnGetVerificationCode_Phone.Visible = false;
                btnGetVerificationCode_Mail.Visible = true;
@@ -82,11 +94,11 @@
        {
            etAccount.TextChangeEventHandler += (sender, e) =>
            {
                Regex reg = new Regex(@"^[1]+\d{10}");
                var mFalg = reg.Match(etAccount.Text.Trim());
                //Regex reg = new Regex(@"^[1]+\d{10}");
                //var mFalg = reg.Match(etAccount.Text.Trim());
                if (registerType == 0)//手机获取验证码按钮生效条件
                {
                    if (btnGlobalRoaming.Text == "+86" && etAccount.Text.Trim().Length != 11)
                    if (!Utlis.CheckPhoneNumber(etAccount.Text.Trim(), phoneZoneCode))
                    {
                        btnGetVerificationCode_Phone.IsSelected = false;
                    }
@@ -98,7 +110,7 @@
                }
                else//邮箱获取验证码按钮生效条件
                {
                    if (!mFalg.Success)
                    if (!Utlis.CheckEmail(etAccount.Text.Trim()))
                    {
                        btnGetVerificationCode_Mail.IsSelected = false;
                    }
@@ -132,16 +144,14 @@
                    //手机方式-验证手机号码是否正确
                    if (registerType == 0)
                    {
                    btnGetVerificationCode_Phone.IsSelected = false;
                        Regex reg = new Regex(@"^[1]+\d{9}");
                        var mFalg = reg.Match(etAccount.Text.Trim());
                        if (!mFalg.Success || (btnGlobalRoaming.Text == "+86" && etAccount.Text.Trim().Length != 11))
                        btnGetVerificationCode_Phone.IsSelected = false;
                        if (!Utlis.CheckPhoneNumber(etAccount.Text.Trim(), phoneZoneCode))
                        {
                            btnAccountViewBottomLine.BackgroundColor = CSS_Color.AuxiliaryColor2;
                            btnAccountViewBottomLine.Height = Application.GetRealHeight(2);
                            new Tip()
                            {
                                CloseTime = 3,
                                CloseTime = 1,
                                Text = Language.StringByID(StringId.PlsEntryCorrectMobilNeumber),
                                Direction = AMPopTipDirection.None,
                            }.Show(bodyView);
@@ -159,15 +169,13 @@
                    {
                        btnGetVerificationCode_Mail.IsSelected = false;
                        //邮箱方式-验证邮箱是否正确
                        var reg = new Regex("^\\s*([A-Za-z0-9_-]+(\\.\\w+)*@(\\w+\\.)+\\w{2,5})\\s*$");
                        var mFalg = reg.Match(etAccount.Text.Trim());
                        if (!mFalg.Success )
                        if (!Utlis.CheckEmail(etAccount.Text.Trim()))
                        {
                            btnAccountViewBottomLine.BackgroundColor = CSS_Color.AuxiliaryColor2;
                            btnAccountViewBottomLine.Height = Application.GetRealHeight(2);
                            new Tip()
                            {
                                CloseTime = 3,
                                CloseTime = 1,
                                Text = Language.StringByID(StringId.PlsEntryCorrectEmailAddress),
                                Direction = AMPopTipDirection.None,
                            }.Show(bodyView);
@@ -201,7 +209,7 @@
                    {
                        new Tip()
                        {
                            CloseTime = 3,
                            CloseTime = 1,
                            Direction = AMPopTipDirection.None,
                            Text = Language.StringByID(StringId.PasswordIsUnqualified)
                        }.Show(bodyView);
@@ -228,7 +236,7 @@
                        btnRepeatPasswordViewBottomLine.Height = Application.GetRealHeight(2);
                        new Tip()
                        {
                            CloseTime = 3,
                            CloseTime = 1,
                            Direction = AMPopTipDirection.None,
                            Text = Language.StringByID(StringId.IncorrectRepeatPassword)
                        }.Show(bodyView);
@@ -281,6 +289,25 @@
        }
        /// <summary>
        /// 检测当前配置域名是否一致,不一致则替换
        /// </summary>
        /// <param name="result"></param>
        void CheckAndSetUserRequestHost(ResponsePackNew result) {
            try
            {
                var mGlobalRegionListObj = Newtonsoft.Json.JsonConvert.DeserializeObject<GlobalRegionListRes>(result.Data.ToString());
                if (UserInfo.Current.RequestHttpsHost != mGlobalRegionListObj.regionUrl)
                {
                    UserInfo.Current.RequestHttpsHost = mGlobalRegionListObj.regionUrl;
                    UserInfo.Current.GlobalRegion = mGlobalRegionListObj;
                    UserInfo.Current.SaveUserInfo();
                }
            }
            catch { }
        }
        /// <summary>
        /// 获取验证码
        /// </summary>
        void LoadEvent_GetVerificationCode()
@@ -290,61 +317,88 @@
                var account = etAccount.Text.Trim();
                if ((sender as Button).IsSelected)
                {
                    //短信发送间隔60s
                    (sender as Button).IsSelected = false;
                    etVerificationCode.Foucs = true;
                    //获取验证码
                        int time = 60;
                    new Thread(() => {
                        while (time > 0)
                        {
                            time--;
                            Application.RunOnMainThread(() =>
                            {
                                (sender as Button).Text = time.ToString() + "s";
                            });
                            Thread.Sleep(1000);
                        }
                        Application.RunOnMainThread(() =>
                        {
                            //回复获取短信按钮事件
                            (sender as Button).IsSelected = true;
                            (sender as Button).TextID = StringId.GetVerificationCode;
                        });
                    }){ IsBackground = true}.Start();
                    //加载Loading效果
                    var waitPage = new Loading();
                    bodyView.AddChidren(waitPage);
                    waitPage.Start(Language.StringByID(StringId.PleaseWait));
                    int time = 60;
                    new Thread(() =>
                    {
                        var result = pm.SendSms(account);
                        if (result.StateCode.ToUpper() == "SUCCESS")
                        try
                        {
                        }
                        else
                        {
                            string tipString = "Server error";
                            switch (result.StateCode)
                            //1.先检查账号是否注册过
                            var result = pm.GetRegionByAccount(account);
                            if (result.Code != StateCode.SUCCESS)
                            {
                                case "Exist":
                                    tipString = Language.StringByID(StringId.AccountAlreadyExists);
                                    break;
                                case "SendFail":
                                    tipString = Language.StringByID(StringId.FailedToSendVerificationCode);
                                    break;
                                case "AccountNoExists":
                                    tipString = Language.StringByID(StringId.AccountNotExist);
                                    break;
                                case "Self:Net_Error":
                                    tipString = Language.StringByID(StringId.NetworkAnomaly);
                                    break;
                                IMessageCommon.Current.ShowErrorInfoAlter(result.Code);
                                return;
                            }
                            else
                            {
                                //2.1检测当前配置域名是否一致,不一致则替换
                                CheckAndSetUserRequestHost(result);
                                //2.2已经注册过,发送验证码找回密码
                                ResponsePackNew resultObj;
                                //2.3请求获取验证码
                                if (registerType == 1)//邮箱
                                {
                                    resultObj = pm.VerificationCodeSend(VerifyType.FIND_PASSWORD, account);
                                }
                                else
                                {
                                    resultObj = pm.VerificationCodeSend(VerifyType.FIND_PASSWORD, account, true, phoneZoneCode);
                                }
                                if (resultObj.Code != StateCode.SUCCESS)
                                {
                                    // 提示错误
                                    IMessageCommon.Current.ShowErrorInfoAlter(resultObj.Code);
                                }
                                else
                                {
                                    //3.发送验证码成功,开始计时
                                    Application.RunOnMainThread(() =>
                                    {
                                    //短信发送间隔60s
                                    (sender as Button).IsSelected = false;
                                        etVerificationCode.Foucs = true;
                                    });
                                    //2.1获取验证码倒计时
                                    new Thread(() =>
                                    {
                                        while (time > 0)
                                        {
                                            time--;
                                            Application.RunOnMainThread(() =>
                                            {
                                                (sender as Button).Text = time.ToString() + "s";
                                            });
                                            Thread.Sleep(1000);
                                        }
                                        Application.RunOnMainThread(() =>
                                        {
                                        //回复获取短信按钮事件
                                        (sender as Button).IsSelected = true;
                                            (sender as Button).TextID = StringId.GetVerificationCode;
                                        });
                                    })
                                    { IsBackground = true }.Start();
                                }
                            }
                        }
                        catch { }
                        finally
                        {
                            Application.RunOnMainThread(() =>
                            {
                                new Tip()
                                if (waitPage != null)
                                {
                                    CloseTime = 3,
                                    Direction = AMPopTipDirection.None,
                                    Text = tipString
                                }.Show(bodyView);
                                    waitPage.RemoveFromParent();
                                    waitPage = null;
                                }
                            });
                        }
                    })
@@ -391,81 +445,39 @@
            return new Thread(() =>
            {
                var verResult = pm.ValidatorCode(account, verCode, countryIndex);
                if (verResult.StateCode.ToUpper() == "SUCCESS")
                // 忘记密码
                var isPhone = registerType == 0;
                var resultObj = pm.ForgetPassword(account, password, verCode, isPhone);
                if (resultObj.Code == StateCode.SUCCESS)
                {
                    var resetResult = pm.ResetPassword(account, password, repeatPassword, countryIndex);
                    if (resetResult.StateCode.ToUpper() == "SUCCESS")
                    Application.RunOnMainThread(() =>
                    {
                        Application.RunOnMainThread(() =>
                        {
                            LoadEvent_AutoLogin();
                            callbackAction?.Invoke(account);
                        });
                    }
                    else
                    {
                        string erorrInfo = "";
                        switch (resetResult.StateCode)
                        {
                            case "PwdNoConfirm"://两次输入的密码不一致
                                erorrInfo = Language.StringByID(StringId.IncorrectRepeatPassword);
                                break;
                            case "AccountNoExists"://两次输入的密码不一致
                                erorrInfo = Language.StringByID(StringId.AccountNotExist);
                                break;
                            default:
                                erorrInfo = "Server error";
                                break;
                        }
                        Application.RunOnMainThread(() =>
                        if (waitPage != null)
                        {
                            waitPage.Hide();
                            new Tip()
                            {
                                CloseTime = 3,
                                Direction = AMPopTipDirection.None,
                                Text = erorrInfo,
                            }.Show(bodyView);
                        });
                    }
                        }
                        ShowAutoLoginDialog(account, password, isPhone);
                    });
                }
                else
                {
                    string erorrInfo = "";
                    switch (verResult.StateCode)
                    {
                        case "ValidCodeAndPhoneNoEqual"://验证码错误
                            erorrInfo = Language.StringByID(StringId.VerificationCodeWrong);
                            Application.RunOnMainThread(() =>
                            {
                                btnVerificationCodeViewBottomLine.BackgroundColor = CSS_Color.AuxiliaryColor2;
                                btnVerificationCodeViewBottomLine.Height = Application.GetRealHeight(2);
                            });
                            break;
                        case "NoRecord":
                            erorrInfo = Language.StringByID(StringId.PlsGetTheVerificationCode);
                            Application.RunOnMainThread(() =>
                            {
                                btnVerificationCodeViewBottomLine.BackgroundColor = CSS_Color.AuxiliaryColor2;
                                btnVerificationCodeViewBottomLine.Height = Application.GetRealHeight(2);
                            });
                            break;
                        default:
                            erorrInfo = "Server error";
                            break;
                    }
                    Application.RunOnMainThread(() =>
                    {
                        waitPage.Hide();
                        new Tip()
                        if (waitPage != null)
                        {
                            CloseTime = 3,
                            Direction = AMPopTipDirection.None,
                            Text = erorrInfo,
                        }.Show(bodyView);
                            waitPage.Hide();
                        }
                        // 验证码错误 警告提示
                        if (resultObj.Code == StateCode.VERIFICATION_CODE_WRONG)
                        {
                            btnVerificationCodeViewBottomLine.BackgroundColor = CSS_Color.AuxiliaryColor2;
                            btnVerificationCodeViewBottomLine.Height = Application.GetRealHeight(2);
                        }
                    });
                    // 提示错误
                    IMessageCommon.Current.ShowErrorInfoAlter(resultObj.Code);
                }
            });
        }
@@ -486,89 +498,99 @@
        }
        /// <summary>
        /// 住宅成功之后自动登录
        /// 显示自动自动登录事件
        /// </summary>
        void LoadEvent_AutoLogin()
        void ShowAutoLoginDialog(string account, string password, bool isPhone)
        {
            Dialog dialog = new Dialog();
            FrameLayout frame = new FrameLayout()
            FrameLayout dialogView = new FrameLayout();
            dialogView.MouseUpEventHandler = (sender, e) =>
            {
                dialog.Close();
            };
            dialog.AddChidren(dialogView);
            FrameLayout contentView = new FrameLayout()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(198),
                Y =  Application.GetRealWidth(200),
                Width = Application.GetRealWidth(288),
                Height = Application.GetRealHeight(206),
                Height = Application.GetRealWidth(270),
                Radius = (uint)Application.GetRealWidth(6),
                BackgroundColor = CSS_Color.MainBackgroundColor,
                Radius = (uint)Application.GetRealWidth(12),
                BorderWidth = 0,
                BorderColor = 0x00000000,
            };
            dialog.AddChidren(frame);
            dialogView.AddChidren(contentView);
            Button btnAccountText = new Button()
            contentView.Y = (dialogView.Height - contentView.Height) / 2;
            Button btnTitleIcon = new Button()
            {
                X = Application.GetRealWidth(108),
                Y = contentView.Y - Application.GetRealWidth(71),
                Width = Application.GetRealWidth(160),
                Height = Application.GetRealWidth(160),
                UnSelectedImagePath = "Public/Dialog/DialogTipTitleIcon_1.png"
            };
            dialogView.AddChidren(btnTitleIcon);
            btnTitleIcon.MouseUpEventHandler = (sender, e) =>
            {
                dialog.Close();
            };
            Button btnMsg = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(40),
                Height = Application.GetRealHeight(17 + 14 + 14),
                IsMoreLines = true,
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.TextFontSize,
                //Text = "s是生生世世",
            };
            frame.AddChidren(btnAccountText);
            Button btnTipRegisterSuccess = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(123),
                Height = Application.GetRealHeight(30),
                TextAlignment = TextAlignment.Center,
                Y = Application.GetRealWidth(88),
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealWidth(44),
                TextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextID = StringId.PasswordChangeSuccessfully,
                TextID = StringId.ModifySuccess
            };
            frame.AddChidren(btnTipRegisterSuccess);
            contentView.AddChidren(btnMsg);
            Button btnAutoLoginTip = new Button()
            Button btnMsg2 = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = btnTipRegisterSuccess.Bottom,
                Height = Application.GetRealHeight(17 + 8),
                TextAlignment = TextAlignment.Center,
                Y = btnMsg.Bottom + Application.GetRealWidth(8),
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealWidth(60),
                TextColor = CSS_Color.PromptingColor1,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextID = StringId.AutomaticallyLogin,
                TextID = StringId.YourPasswordHasBeenChanged,
                TextAlignment = TextAlignment.TopCenter,
                IsMoreLines = true
            };
            //frame.AddChidren(btnAutoLoginTip);
            contentView.AddChidren(btnMsg2);
            Button btnHeadImage = new Button()
            Button btnSkipBindPage = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(150),
                Width = Application.GetRealWidth(84),
                Height = Application.GetRealWidth(84),
                Radius = (uint)Application.GetRealWidth(42),
                BorderColor = 0x00000000,
                BorderWidth = 0,
                UnSelectedImagePath = "LoginIcon/2.png",
                Y = Application.GetRealWidth(194),
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealWidth(44),
                TextAlignment = TextAlignment.Center,
                Radius = (uint)Application.GetRealWidth(22),
                BackgroundColor = CSS_Color.MainColor,
                TextID = StringId.Login,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextColor = CSS_Color.MainBackgroundColor,
            };
            dialog.AddChidren(btnHeadImage);
            contentView.AddChidren(btnSkipBindPage);
            btnSkipBindPage.MouseUpEventHandler = (sender, e) =>
            {
                dialog.Close();
                this.Close();
                AutoLoginAction?.Invoke(account, password, isPhone);
            };
            dialog.Show();
            new Thread(() =>
            {
                Thread.Sleep(1500);
                Application.RunOnMainThread(() =>
                {
                    dialog.Close();
                    this.Close();
                });
            })
            { IsBackground = true }.Start();
        }
    }
}