using System; using Shared.Common; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Timers; namespace Shared.Phone.Device.Account { public class RegistrationByEmail:FrameLayout { /// /// 邮箱输入是否符合规则 /// public bool IsRightAccount = false; public RegistrationByEmail() { BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor; } public void Show() { ShowRegisterView(); } public void ShowRegisterView() { #region topview var topBGView = new FrameLayout() { Height = Application.GetRealHeight(220), BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor }; AddChidren(topBGView); var topView = new FrameLayout() { Y = Application.GetRealHeight(CommonPage.NavigationTitle_Y), Height = Application.GetRealHeight(220 - CommonPage.NavigationTitle_Y), BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor, }; AddChidren(topView); var titleName = new Button() { TextAlignment = TextAlignment.Center, TextID = R.MyInternationalizationString.RegisterByEmail, TextSize = 19, TextColor = Shared.Common.ZigbeeColor.Current.GXCTextBlackColor, Width = Application.GetRealWidth(600), Gravity = Gravity.CenterHorizontal }; topView.AddChidren(titleName); var loginBtn = new Button() { X = Application.GetRealWidth(1080 - 250), Width = Application.GetRealWidth(200), Height = Application.GetRealHeight(100), TextAlignment = TextAlignment.CenterRight, Gravity = Gravity.CenterVertical, TextColor = ZigbeeColor.Current.GXCTextBlueColor, TextID = R.MyInternationalizationString.Login, TextSize=15 }; topView.AddChidren(loginBtn); var back = new Button() { X = Application.GetRealWidth(CommonPage.Navigation_X), Height = Application.GetMinRealAverage(110), Width = Application.GetMinRealAverage(110), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", Gravity = Gravity.CenterVertical }; topView.AddChidren(back); back.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent(); }; #endregion #region ---midFrameLayout var midFrameLayout = new FrameLayout() { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight(1920 - 220), Y = topView.Bottom, BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, }; this.AddChidren(midFrameLayout); var accountFL = new FrameLayout() { Y = Application.GetRealHeight(150), Width = Application.GetRealWidth(700), Height = Application.GetRealHeight(110), BorderColor = ZigbeeColor.Current.GXCBorderColor, BorderWidth = 1, Radius = (uint)Application.GetRealHeight(55), Gravity = Gravity.CenterHorizontal }; midFrameLayout.AddChidren(accountFL); var accountET = new EditText() { Width = Application.GetRealWidth(700 - 100), Gravity=Gravity.CenterHorizontal, TextColor = ZigbeeColor.Current.GXCTextBlackColor, PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputEmail), PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor, TextAlignment = TextAlignment.Center }; accountFL.AddChidren(accountET); var pwdFL = new FrameLayout() { Y = Application.GetRealHeight(80) + accountFL.Bottom, Width = Application.GetRealWidth(700), Height = Application.GetRealHeight(110), BorderColor = ZigbeeColor.Current.GXCBorderColor, BorderWidth = 1, Radius = (uint)Application.GetRealHeight(55), Gravity = Gravity.CenterHorizontal }; midFrameLayout.AddChidren(pwdFL); var pwdET = new EditText() { Width = Application.GetRealWidth(500), Gravity = Gravity.CenterHorizontal, TextColor = ZigbeeColor.Current.GXCTextBlackColor, PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputPWD), PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor, TextAlignment = TextAlignment.Center, SecureTextEntry = true }; pwdFL.AddChidren(pwdET); var hidenPWDbtn = new Button() { X = pwdET.Right + Application.GetRealWidth(20), Width = Application.GetMinReal(72), Height = Application.GetMinReal(72), UnSelectedImagePath = "Account/HidenPWD.png", SelectedImagePath = "Account/UnHidenPWD.png", Gravity = Gravity.CenterVertical }; pwdFL.AddChidren(hidenPWDbtn); var pwdComfirmFL = new FrameLayout() { Y = Application.GetRealHeight(80) + pwdFL.Bottom, Width = Application.GetRealWidth(700), Height = Application.GetRealHeight(110), BorderColor = ZigbeeColor.Current.GXCBorderColor, BorderWidth = 1, Gravity = Gravity.CenterHorizontal, Radius = (uint)Application.GetRealHeight(55) }; midFrameLayout.AddChidren(pwdComfirmFL); var pwdComfirmET = new EditText() { Width = Application.GetRealWidth(500), Gravity = Gravity.CenterHorizontal, TextColor = ZigbeeColor.Current.GXCTextBlackColor, PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseComfirePWD), PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor, TextAlignment = TextAlignment.Center, SecureTextEntry = true }; pwdComfirmFL.AddChidren(pwdComfirmET); var hidenPWDComfirmbtn = new Button() { X = pwdComfirmET.Right + Application.GetRealWidth(20), Width = Application.GetMinReal(72), Height = Application.GetMinReal(72), UnSelectedImagePath = "Account/HidenPWD.png", SelectedImagePath = "Account/UnHidenPWD.png", Gravity = Gravity.CenterVertical }; pwdComfirmFL.AddChidren(hidenPWDComfirmbtn); var verificationCodeFL = new FrameLayout() { Y = Application.GetRealHeight(80) + pwdComfirmFL.Bottom, Width = Application.GetRealWidth(700), Height = Application.GetRealHeight(110), BorderColor = ZigbeeColor.Current.GXCBorderColor, BorderWidth = 1, Gravity = Gravity.CenterHorizontal, Radius = (uint)Application.GetRealHeight(55) }; midFrameLayout.AddChidren(verificationCodeFL); var codeET = new EditText() { X = Application.GetRealWidth(20), Width = Application.GetRealWidth(350), TextColor = ZigbeeColor.Current.GXCTextBlackColor, PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputVerificationCode), PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor, TextAlignment = TextAlignment.Center }; verificationCodeFL.AddChidren(codeET); var codeLine = new Button() { X = Application.GetRealWidth(10) + codeET.Right, Width = 1, Height = Application.GetRealHeight(60), Gravity = Gravity.CenterVertical, BackgroundColor = ZigbeeColor.Current.GXCLineColor }; verificationCodeFL.AddChidren(codeLine); var sendCodeBtn = new Button() { X = codeET.Right + Application.GetRealWidth(20), Width = Application.GetRealWidth(250), TextColor = ZigbeeColor.Current.GXCTextUnselectedColor, SelectedTextColor=ZigbeeColor.Current.GXCTextBlueColor, TextID = R.MyInternationalizationString.SendVerificationCode, TextAlignment = TextAlignment.Center, Enable = false, IsSelected = false }; verificationCodeFL.AddChidren(sendCodeBtn); var comfirmBtn = new Button() { Y = midFrameLayout.Height - Application.GetRealHeight(400), Width = Application.GetRealWidth(700), Height = Application.GetRealHeight(110), TextColor = ZigbeeColor.Current.GXCTextWhiteColor, TextID = R.MyInternationalizationString.Confrim, BackgroundColor = ZigbeeColor.Current.GXCButtonUnselectedColor, SelectedBackgroundColor = ZigbeeColor.Current.GXCButtonBlueColor, Radius = (uint)Application.GetRealHeight(55), Gravity = Gravity.CenterHorizontal, TextAlignment = TextAlignment.Center, Enable = false, IsSelected = false }; midFrameLayout.AddChidren(comfirmBtn); //错误提示Btn var loginErrorBtn = new Button() { Y = comfirmBtn.Bottom + Application.GetRealHeight(50), Width = Application.GetRealWidth(1080 - 100), Height = Application.GetRealHeight(110), TextColor = ZigbeeColor.Current.GXCRedColor, Gravity = Gravity.CenterHorizontal }; midFrameLayout.AddChidren(loginErrorBtn); var t = new Timer(); var dateBegin = new DateTime(); #endregion #region --event-- void TimeBegin() { t.Interval = 1000; t.AutoReset = true; t.Enabled = true; t.Elapsed += 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(); }); } } hidenPWDbtn.MouseUpEventHandler += (sender, e) => { pwdET.SecureTextEntry = !pwdET.SecureTextEntry; hidenPWDbtn.IsSelected = !hidenPWDbtn.IsSelected; }; hidenPWDComfirmbtn.MouseUpEventHandler += (sender, e) => { hidenPWDComfirmbtn.IsSelected = !hidenPWDComfirmbtn.IsSelected; pwdComfirmET.SecureTextEntry = !pwdComfirmET.SecureTextEntry; }; accountET.TextChangeEventHandler += (sender, e) => { loginErrorBtn.Text = ""; var reg = new Regex(CommonPage.EmailRegexStr); if (reg.IsMatch(accountET.Text.Trim())) { IsRightAccount = true; } else { IsRightAccount = false; } if (IsRightAccount && accountET.Text.Trim().Length>0 && pwdET.Text.Trim().Length >= 6 && pwdET.Text.Trim().Length <= 16 && pwdComfirmET.Text.Trim().Length >= 6 && pwdComfirmET.Text.Trim().Length <= 16) { sendCodeBtn.Enable = sendCodeBtn.IsSelected = true; } else { sendCodeBtn.Enable = sendCodeBtn.IsSelected = false; } }; pwdET.TextChangeEventHandler += (sender, e) => { loginErrorBtn.Text = ""; if (IsRightAccount && accountET.Text.Trim().Length > 0 && pwdET.Text.Trim().Length >= 6 && pwdET.Text.Trim().Length <= 16 && pwdComfirmET.Text.Trim().Length >= 6 && pwdComfirmET.Text.Trim().Length <= 16) { sendCodeBtn.Enable = sendCodeBtn.IsSelected = true; } else if(pwdET.Text.Trim().Length>16) { pwdET.Text = e.Remove(16); } else { sendCodeBtn.Enable = sendCodeBtn.IsSelected = false; } }; pwdComfirmET.TextChangeEventHandler += (sender, e) => { loginErrorBtn.Text = ""; if (IsRightAccount && accountET.Text.Trim().Length > 0 && pwdET.Text.Trim().Length >= 6 && pwdET.Text.Trim().Length <= 16 && pwdComfirmET.Text.Trim().Length >= 6 && pwdComfirmET.Text.Trim().Length <= 16) { sendCodeBtn.Enable = sendCodeBtn.IsSelected = true; } else if(pwdComfirmET.Text.Trim().Length>16) { pwdComfirmET.Text = e.Remove(16); } else { sendCodeBtn.Enable = sendCodeBtn.IsSelected = false; } }; codeET.TextChangeEventHandler += (send, e) => { loginErrorBtn.Text = ""; if (e.Trim().Length > 0 && IsRightAccount && pwdET.Text.Trim().Length >= 6 && pwdET.Text.Trim().Length <= 16 && pwdComfirmET.Text.Trim().Length >= 6 && pwdComfirmET.Text.Trim().Length <= 16) { comfirmBtn.Enable = comfirmBtn.IsSelected = true; } else { comfirmBtn.Enable = comfirmBtn.IsSelected = false; } }; //发送验证码 sendCodeBtn.MouseUpEventHandler += async (sender, e) => { //先判断2次密码输入是否一致 if (pwdET.Text.Trim() != pwdComfirmET.Text.Trim()) { var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.TwoPasswordInconsistency), Language.StringByID(R.MyInternationalizationString.Confrim)); alert.Show(); pwdET.Text = ""; pwdComfirmET.Text = ""; sendCodeBtn.Enable = sendCodeBtn.IsSelected = false; return; } 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 = ""; IsRightAccount = false; sendCodeBtn.Enable = sendCodeBtn.IsSelected = false; } else { CommonPage.Loading.Start(); try { var reqDtoSignPhone = new SendDataToServer.RegisterSendVerCodeObj() { Account = accountET.Text.Trim(), Company = 0, AreaCode = 0, Language = CommonPage.ZigBeeLanguage }; var requesetJson = Newtonsoft.Json.JsonConvert.SerializeObject(reqDtoSignPhone); var requestRevertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/RegisterSendVerCode", 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 == "SENDFAIL") { //验证码发送失败 loginErrorBtn.TextID = R.MyInternationalizationString.SENDFAIL; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.SENDFAIL); } else if (stateCodeStr == "EXIST") { //账号存在 loginErrorBtn.TextID = R.MyInternationalizationString.AccountHasBeenRegistered; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.AccountHasBeenRegistered); //sendCodeBtn.Enable = sendCodeBtn.IsSelected = false; //accountET.Text = ""; //IsRightAccount = false; } else { loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.RequestServerFailed); } } catch { loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed; } finally { CommonPage.Loading.Hide(); } } }; //login loginBtn.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent(); Shared.Common.CommonPage.Instance.RemoveViewByTag("Register"); var accountLogin = new Device.Account.AccountLogin { }; Shared.Common.CommonPage.Instance.AddChidren(accountLogin); accountLogin.Show(); }; //注册-****不需要先验证验证码 comfirmBtn.MouseUpEventHandler += async (sender, e) => { CommonPage.Loading.Start(); try { var reqDto = new SendDataToServer.RegisterAccountObj() { Account = accountET.Text.Trim(), Password = pwdET.Text.Trim(), EnterPassword = pwdComfirmET.Text.Trim(), Language = CommonPage.ZigBeeLanguage, Code = codeET.Text.Trim(), RegisterSoruce = CommonPage.RegisterSoruceFromZIGBEE, AreaCode = 0 }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(reqDto); //验证验证码 var requestRevertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/ValidataCodeAndRegisterAccount", System.Text.Encoding.UTF8.GetBytes(requestJson)); if (requestRevertObj == null) { CommonPage.Instance.FailureToServer(); return; } var stateCodeStr = requestRevertObj.StateCode.ToUpper(); if (stateCodeStr == "SUCCESS") { var registerSuccess = new Account.RegisterSuccess(); this.AddChidren(registerSuccess); registerSuccess.Show(accountET.Text.Trim(),pwdET.Text.Trim()); } else if (stateCodeStr == "EXIST") { //已注册 loginErrorBtn.TextID = R.MyInternationalizationString.TheResidenceNameHasExist; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheResidenceNameHasExist); } else if (stateCodeStr == "PARAMETEROREMPTY") { //提供的参数错误 loginErrorBtn.TextID = R.MyInternationalizationString.PARAMETEROREMPTY; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.PARAMETEROREMPTY); } else if (stateCodeStr == "PWDNOCONFIRM") { //两次密码不一样 loginErrorBtn.TextID = R.MyInternationalizationString.TwoPasswordInconsistency; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TwoPasswordInconsistency); } else if (stateCodeStr == "VALIDCODEANDPHONENOEQUAL") { //验证码错误 loginErrorBtn.TextID = R.MyInternationalizationString.VALIDCODEANDPHONENOEQUAL; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.VALIDCODEANDPHONENOEQUAL); } else { loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.RequestServerFailed); } } catch { loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed; } finally { CommonPage.Loading.Hide(); } }; #endregion } } }