using System; using System.Text.RegularExpressions; namespace Shared.SimpleControl.Phone { public class AccountRegistration_Crabtree : Dialog { /// /// /// PageLayout bodyPageView; public AccountRegistration_Crabtree () { BackgroundColor = SkinStyle.Current.MainColor; ShowRegisterView (); } public void ShowRegisterView () { FrameLayout topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.MainColor, }; AddChidren (topView); Button title = new Button () { TextAlignment = TextAlignment.Center, Text = "Sign up", TextSize = 19, TextColor = SkinStyle.Current.TextColor1 }; topView.AddChidren (title); //Button logo = new Button () { // Width = Application.GetRealWidth (154), // Height = Application.GetRealHeight (90), // X = Application.GetRealWidth (486), // UnSelectedImagePath = MainPage.LogoString, // Gravity = Gravity.CenterVertical, //}; //topView.AddChidren (logo); Button 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) => { this.Close (); new AccountLogin ().Show (); }; bodyPageView = new PageLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (Application.DesignHeight - 126), Y = topView.Bottom, BackgroundColor = SkinStyle.Current.ViewColor, }; AddChidren (bodyPageView); bodyPageView.PageChange += (sender, e) => { //2020-09-04 修复安卓右滑闪退问题 if (e < bodyPageView.ChildrenCount - 1) { bodyPageView.GetChildren (bodyPageView.ChildrenCount - 1).RemoveFromParent (); } }; bodyPageView.MouseDownEventHandler += (sender, e) => { Application.HideSoftInput (); }; FrameLayout bodyView = new FrameLayout (); bodyPageView.AddChidren (bodyView); bodyPageView.IsShowPoint = false; EmailRegistrationView (bodyView); } /// /// 邮箱注册页面 /// /// void EmailRegistrationView (FrameLayout registrationView) { registrationView.RemoveAll (); Button btnEmail = new Button () { Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), Gravity = Gravity.CenterHorizontal, Y = Application.GetRealWidth (20), TextID = R.MyInternationalizationString.EmailAddress, TextAlignment = TextAlignment.CenterLeft, TextSize = 12, TextColor = SkinStyle.Current.TextColor1, }; registrationView.AddChidren (btnEmail); FrameLayout EmailView = new FrameLayout () { Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), Gravity = Gravity.CenterHorizontal, Y = btnEmail.Bottom, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, //Text = "1270166900@qq.com" }; registrationView.AddChidren (EmailView); EditText etEmailAddress = new EditText () { TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1, PlaceholderText = Language.StringByID (R.MyInternationalizationString.EmailAddress), PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor, }; EmailView.AddChidren (etEmailAddress); Button btnNext = new Button () { Y = EmailView.Bottom + Application.GetRealWidth (20), Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), Gravity = Gravity.CenterHorizontal, BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.Send, TextColor = SkinStyle.Current.TextColor1, Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, TextSize = 18, TextAlignment = TextAlignment.Center, }; registrationView.AddChidren (btnNext); btnNext.MouseDownEventHandler += (sender, e) => { btnNext.IsSelected = true; }; btnNext.MouseUpEventHandler += (sender, e) => { btnNext.IsSelected = false; string account = etEmailAddress.Text.Trim (); if (!CommonUtlis.Current.CheckEmail (account)) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseCheckEmailAddressCorrectly), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } SendVerificationCode (account, false); }; } /// /// 手机或者邮箱发送验证码并加载对应的注册页面 /// /// 账号 邮箱或者手机号 /// 是否是手机 void SendVerificationCode (string account, bool isPhone = true) { MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { try { var requestRevertObj = HttpServerRequest.Current.VerificationCodeSend (VerifyType.REGISTER_USER, account); if (requestRevertObj.Code == StateCode.SUCCESS) { Application.RunOnMainThread (() => { // isPhone 是否是手机 InitSMSView (account, false); bodyPageView.PageIndex = bodyPageView.ChildrenCount - 1; }); } else { //提示错误 IMessageCommon.Current.ShowErrorInfoAlter (requestRevertObj.Code); } } catch { MainPage.FailureToServer (); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); } /// /// 验证验证码并提交注册 /// /// /// void InitSMSView (string mAccount, bool bPhone = true) { FrameLayout mobileChencView = new FrameLayout (); bodyPageView.AddChidren (mobileChencView); Button btnAccount = new Button () { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealWidth (20), Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (50), Text = mAccount, TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.Center, }; mobileChencView.AddChidren (btnAccount); Button btnName = new Button () { Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), X = Application.GetRealWidth (70), Y = Application.GetRealWidth (70), TextID = R.MyInternationalizationString.Name, TextAlignment = TextAlignment.CenterLeft, TextSize = 12, TextColor = SkinStyle.Current.TextColor1, }; mobileChencView.AddChidren (btnName); EditText etName = new EditText () { Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), X = Application.GetRealWidth (70), Y = btnName.Bottom, TextAlignment = TextAlignment.Center, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, TextColor = SkinStyle.Current.TextColor1, }; mobileChencView.AddChidren (etName); Button btnPassword = new Button () { Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), X = Application.GetRealWidth (70), Y = etName.Bottom, TextID = R.MyInternationalizationString.Password, TextAlignment = TextAlignment.CenterLeft, TextSize = 12, TextColor = SkinStyle.Current.TextColor1, }; mobileChencView.AddChidren (btnPassword); EditText etPasswrod = new EditText () { Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), X = Application.GetRealWidth (70), Y = btnPassword.Bottom, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1, SecureTextEntry = true, //Text = "hdltest1985" }; mobileChencView.AddChidren (etPasswrod); Button btnShowPassword = new Button () { X = etPasswrod.Right - Application.GetRealWidth (80), Y = etPasswrod.Y + Application.GetRealWidth (12), Width = Application.GetRealWidth (73), Height = Application.GetRealWidth (60), SelectedImagePath = "CrabtreeAdd/ShowPW.png", UnSelectedImagePath = "CrabtreeAdd/HidePW.png", BorderColor = SkinStyle.Current.Transparent, BorderWidth = 1, Radius = 1 }; mobileChencView.AddChidren (btnShowPassword); btnShowPassword.MouseUpEventHandler += (dd, ff) => { btnShowPassword.IsSelected = !btnShowPassword.IsSelected; etPasswrod.SecureTextEntry = !btnShowPassword.IsSelected; }; Button btnConfirmpassword = new Button () { Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), X = Application.GetRealWidth (70), Y = etPasswrod.Bottom, TextID = R.MyInternationalizationString.RepeatPassword, TextAlignment = TextAlignment.CenterLeft, TextSize = 12, TextColor = SkinStyle.Current.TextColor1, }; mobileChencView.AddChidren (btnConfirmpassword); EditText etConfirmPassword = new EditText () { Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), X = Application.GetRealWidth (70), Y = btnConfirmpassword.Bottom, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1, SecureTextEntry = true, //Text = "hdltest1985" }; mobileChencView.AddChidren (etConfirmPassword); Button btnShowPassword2 = new Button () { X = etPasswrod.Right - Application.GetRealWidth (80), Y = etConfirmPassword.Y + Application.GetRealWidth (12), Width = Application.GetRealWidth (73), Height = Application.GetRealWidth (60), SelectedImagePath = "CrabtreeAdd/ShowPW.png", UnSelectedImagePath = "CrabtreeAdd/HidePW.png", BorderColor = SkinStyle.Current.Transparent, BorderWidth = 1, Radius = 1 }; mobileChencView.AddChidren (btnShowPassword2); btnShowPassword2.MouseUpEventHandler += (dd, ff) => { btnShowPassword2.IsSelected = !btnShowPassword2.IsSelected; etConfirmPassword.SecureTextEntry = !btnShowPassword2.IsSelected; }; Button btnTitle = new Button () { Gravity = Gravity.CenterHorizontal, Y = etConfirmPassword.Bottom, Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), TextID = R.MyInternationalizationString.MobileVerificationCode, TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.CenterLeft, }; mobileChencView.AddChidren (btnTitle); EditText etCode = new EditText () { Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), Gravity = Gravity.CenterHorizontal, Y = btnTitle.Bottom, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1 }; mobileChencView.AddChidren (etCode); Button btnConfirem = new Button () { Gravity = Gravity.CenterHorizontal, Y = etCode.Bottom + Application.GetRealWidth (50), Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), Text = "Sign up", //TextID = R.MyInternationalizationString.Confrim, TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.Center, BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, }; mobileChencView.AddChidren (btnConfirem); etCode.TextChangeEventHandler += (sender, e) => { if (e.Length > 6) { etCode.Text = e.Remove (6); } else if (e.Length == 6) { //btnConfirem.IsSelected = btnConfirem.Enable = true; } else { //btnConfirem.IsSelected = btnConfirem.Enable = false; } }; btnConfirem.MouseDownEventHandler += (sender, e) => { btnConfirem.IsSelected = true; }; //点击注册事件 btnConfirem.MouseUpEventHandler += (sender, e) => { btnConfirem.IsSelected = false; string passwordText = etPasswrod.Text.Trim (); string confrimPasswordText = etConfirmPassword.Text.Trim (); string userName = etName.Text.Trim (); var regName = new Regex (@"^[~!0-9@#$%^&=*\x22]+"); if (string.IsNullOrEmpty (userName)) { new Alert ("", "Please fill in the Name.", Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } else if (regName.Match (userName).Success) { new Alert ("", "Protect Your Illegal Characters in Name", Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } //检测密码 if (passwordText == "" && confrimPasswordText == "") { new Alert ("", Language.StringByID (R.MyInternationalizationString.PleaseWriteTheCompleteContent), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } else if (passwordText.Contains (userName)) { //密码不能包含用户名 new Alert ("", ErrorCode.PasswordNotUsername, Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } else if (!CommonUtlis.Current.CheckPassword (passwordText)) { new Alert ("", ErrorCode.PasswordStrengthNotMatch, Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } else if (passwordText != confrimPasswordText) { new Alert ("", Language.StringByID (R.MyInternationalizationString.RepeatPasswordsDidNotmatch), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } //检测验证码 string verCode = etCode.Text.Trim (); if (string.IsNullOrEmpty (verCode)) { Utlis.ShowTip (Language.StringByID (R.MyInternationalizationString.PlsEntryVerificationCode)); return; } MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { try { var isPhone = false; var revertObj = HttpServerRequest.Current.ValidataCodeAndRegister (userName, mAccount, passwordText, verCode, isPhone); if (revertObj.Code == StateCode.SUCCESS) { Application.RunOnMainThread (() => { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TheAccountTegistrationIsSuccessful), Language.StringByID (R.MyInternationalizationString.Close)).Show (); Close (); new AccountLogin (mAccount, passwordText).Show (); }); } else { //提示错误 IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code); } } catch { MainPage.FailureToServer (); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; } } }