public BindingWechatPage(RegisterByOpenIdPara registerByOpenIdPara) { InitializeComponent(); bindingWechatViewModel = new BindingWechatViewModel(registerByOpenIdPara); BindingContext = bindingWechatViewModel; }
public RegisterPage(RegisterByOpenIdPara registerByOpenIdPara) { InitializeComponent(); registerViewModel = new RegisterViewModel(registerByOpenIdPara); BindingContext = registerViewModel; }
/// <summary> /// openid注册 /// </summary> private async void OnRegister(RegisterByOpenIdPara registerByOpenIdPara) { try { if (!Tools.IsNetConnective()) { CrossToastPopUp.Current.ShowToastError("无网络连接,请检查网络。", ToastLength.Long); return; } registerByOpenIdPara.authCode = AuthCode; registerByOpenIdPara.tel = Tel; registerByOpenIdPara.userPwd = Pwd; registerByOpenIdPara.invitePhone = InvitePhone; registerByOpenIdPara.userType = SelectedIdentityIndex.ToString(); SimpleRD simpleRD = await RestSharpService.RegisterByOpenId(registerByOpenIdPara); if (simpleRD.code == 200) { LoginRD loginRD = await RestSharpService.LoginByOpenId(registerByOpenIdPara.openId); if (loginRD.result.message == null) { CrossToastPopUp.Current.ShowToastSuccess("欢迎您登录美而好家具!", ToastLength.Long); GlobalVariables.LoggedUser = loginRD.result; //将登录用户的信息保存成全局静态变量 GlobalVariables.IsLogged = true; JObject log = new JObject(); log.Add("LoginTime", DateTime.UtcNow); log.Add("UserInfo", JsonConvert.SerializeObject(loginRD.result)); string fileName = Path.Combine(FileSystem.CacheDirectory, "log.dat"); File.WriteAllText(fileName, log.ToString()); Application.Current.MainPage.Navigation.RemovePage(Application.Current.MainPage.Navigation.NavigationStack[0]); MainPage mainPage = new MainPage(); await Application.Current.MainPage.Navigation.PushAsync(mainPage); } else { CrossToastPopUp.Current.ShowToastError(loginRD.result.message, ToastLength.Long); } } else { CrossToastPopUp.Current.ShowToastError("注册失败!请联系管理员!", ToastLength.Long); } } catch (Exception) { throw; } }
public BindingWechatViewModel(RegisterByOpenIdPara registerByOpenIdPara) { Avatar = registerByOpenIdPara.headimgurl; NickName = registerByOpenIdPara.nikename; BindingWechatCommand = new Command(async() => { try { string result = await Application.Current.MainPage.DisplayPromptAsync("已注册手机号", "请输入11位手机号", "确定绑定", "取消", "请输入11位手机号", 11, null); if (result == null) { CrossToastPopUp.Current.ShowToastWarning("已取消", ToastLength.Long); } else if (string.IsNullOrWhiteSpace(result)) { CrossToastPopUp.Current.ShowToastWarning("手机号不能为空,请输入!", ToastLength.Long); } else if (!Tools.IsPhoneNumber(result)) { CrossToastPopUp.Current.ShowToastWarning("手机号格式不标准,请检查。", ToastLength.Long); } else { registerByOpenIdPara.tel = result; AuthCodePage authCodePage = new AuthCodePage(registerByOpenIdPara); await Application.Current.MainPage.Navigation.PushAsync(authCodePage); } } catch (Exception) { throw; } }, () => { return(true); }); ToRegisterCommand = new Command(async() => { RegisterPage registerPage = new RegisterPage(registerByOpenIdPara); await Application.Current.MainPage.Navigation.PushAsync(registerPage); }, () => { return(true); }); LoginCommand = new Command(() => { Login(registerByOpenIdPara); }, () => { return(true); }); }
/// <summary> /// openid注册 /// </summary> /// <param name="registerPara"></param> /// <returns></returns> public static async Task <SimpleRD> RegisterByOpenId(RegisterByOpenIdPara registerByOpenIdPara) { try { string url = "/member/registerByOpenId"; var json = JsonConvert.SerializeObject(registerByOpenIdPara); SimpleRD simpleRD = await RestSharpHelper <SimpleRD> .PostAsync(url, json); return(simpleRD); } catch (ApplicationException ex) { throw ex; } }
public RegisterViewModel(RegisterByOpenIdPara registerByOpenIdPara) { AuthCodeButtonText = "发送验证码"; IsEnable = true; ButtonColor = Color.FromHex("01ACF2"); IdentityList = new List <string> { "客户", "设计师" }; SelectedIdentityIndex = 0; SendAuthCodeCommand = new Command(() => { OnACButtonClicked(); myTimer = new MyTimer { EndDate = DateTime.Now.Add(new TimeSpan(900000000)) }; LoadAsync(); }, () => { return(true); }); RegisterCommand = new Command(() => { if (CheckInput()) { OnRegister(registerByOpenIdPara); } }, () => { return(true); }); SelectedIdentityCommand = new Command <bool>((bool isChecked) => { IsDesignerChecked = isChecked; if (IsDesignerChecked) { CrossToastPopUp.Current.ShowToastWarning("您将要注册成为设计师!", ToastLength.Long); } else { CrossToastPopUp.Current.ShowToastWarning("您将要注册成为客户!", ToastLength.Long); } }, (bool f**k) => { return(true); }); }
private async void Login(RegisterByOpenIdPara registerByOpenIdPara) { try { if (!Tools.IsNetConnective()) { CrossToastPopUp.Current.ShowToastError("无网络连接,请检查网络。", ToastLength.Long); return; } LoginRD loginRD = await RestSharpService.LoginByOpenId(registerByOpenIdPara.openId); if (loginRD.result.message == "未被注册") { CrossToastPopUp.Current.ShowToastError("未注册或未绑定", ToastLength.Long); } else { CrossToastPopUp.Current.ShowToastSuccess("欢迎您登录美而好家具!", ToastLength.Long); GlobalVariables.LoggedUser = loginRD.result; //将登录用户的信息保存成全局静态变量 GlobalVariables.IsLogged = true; JObject log = new JObject(); log.Add("LoginTime", DateTime.UtcNow); log.Add("UserInfo", JsonConvert.SerializeObject(loginRD.result)); string fileName = Path.Combine(FileSystem.CacheDirectory, "log.dat"); File.WriteAllText(fileName, log.ToString()); MainPage mainPage = new MainPage(); await Application.Current.MainPage.Navigation.PushAsync(mainPage); Application.Current.MainPage.Navigation.RemovePage(Application.Current.MainPage.Navigation.NavigationStack[0]); } } catch (Exception) { throw; } }
/// <summary> /// 绑定微信 /// </summary> /// <param name="registerByOpenIdPara"></param> private async void RebindingWechat(RegisterByOpenIdPara registerByOpenIdPara) { try { registerByOpenIdPara.authCode = AuthCode; SimpleRD simpleRD = await RestSharpService.UpdateWechat(registerByOpenIdPara); if (simpleRD.success) { CrossToastPopUp.Current.ShowToastSuccess("绑定成功!", ToastLength.Long); LoginRD loginRD = await RestSharpService.LoginByOpenId(registerByOpenIdPara.openId); CrossToastPopUp.Current.ShowToastSuccess("欢迎您登录美而好家具!", ToastLength.Long); GlobalVariables.LoggedUser = loginRD.result; //将登录用户的信息保存成全局静态变量 GlobalVariables.IsLogged = true; JObject log = new JObject(); log.Add("LoginTime", DateTime.UtcNow); log.Add("UserInfo", JsonConvert.SerializeObject(loginRD.result)); string fileName = Path.Combine(FileSystem.CacheDirectory, "log.dat"); File.WriteAllText(fileName, log.ToString()); MainPage mainPage = new MainPage(); await Application.Current.MainPage.Navigation.PushAsync(mainPage); Application.Current.MainPage.Navigation.RemovePage(Application.Current.MainPage.Navigation.NavigationStack[0]); } else { CrossToastPopUp.Current.ShowToastError("绑定失败,请稍后再试!", ToastLength.Long); } } catch (Exception) { throw; } }
public AuthCodeViewModel(RegisterByOpenIdPara registerByOpenIdPara) { Tel = registerByOpenIdPara.tel; AuthCode = string.Empty; SecretTel = Tel.Substring(0, 3) + "****" + Tel.Substring(7, 4); AuthCodeButtonEnable = false; AuthLoginButtonColor = "#83d7f9"; SendAuthCode(); LoginCommand = new Command(() => { RebindingWechat(registerByOpenIdPara); }, () => { return(true); }); CheckInputCommand = new Command(() => { if (AuthCode.Length == 6) { AuthCodeButtonEnable = true; AuthLoginButtonColor = "#01acf2"; } }, () => { return(true); }); }
public LoginViewModel() { IsPassword = true; EyeSource = "Resource/drawable/closed_eye.png"; AuthLoginButtonColor = "#83d7f9"; AuthVisible = true; PasswordVisible = false; ToRegisterPageCommand = new Command(() => { Application.Current.MainPage.Navigation.PushAsync(new RegisterPage()); }, () => { return(true); }); LoginCommand = new Command(() => { if (CheckInput()) { OnLogin(); } }, () => { return(true); }); FindPwdCommand = new Command(() => { Application.Current.MainPage.Navigation.PushAsync(new ResetPwdPage()); }, () => { return(true); }); OpenEyeCommand = new Command(() => { if (IsPassword) { IsPassword = false; EyeSource = "Resource/drawable/open_eye.png"; } else { IsPassword = true; EyeSource = "Resource/drawable/closed_eye.png"; } }, () => { return(true); }); ToAuthPageCommand = new Command(() => { if (Tools.IsPhoneNumber(Tel)) { AuthCodePage authCodePage = new AuthCodePage(Tel); Application.Current.MainPage.Navigation.PushAsync(authCodePage); } else { CrossToastPopUp.Current.ShowToastWarning("手机号格式不标准,请检查。", ToastLength.Long); } }, () => { return(true); }); PasswordLoginPartCommand = new Command(() => { AuthVisible = false; PasswordVisible = true; }, () => { return(true); }); AuthLoginPartCommand = new Command(() => { AuthVisible = true; PasswordVisible = false; }, () => { return(true); }); WechatLoginCommand = new Command(() => { MessagingCenter.Send(new object(), "Register");//首先进行注册,然后订阅注册的结果。 MessagingCenter.Send(new object(), "Login"); MessagingCenter.Subscribe <object, string>(this, "LoginSuccess", async(sender, result) => { try { JObject jObject = JObject.Parse(result); RegisterByOpenIdPara registerByOpenIdPara = new RegisterByOpenIdPara { openId = jObject["openid"].ToString(), nikename = jObject["nickname"].ToString(), headimgurl = jObject["headimgurl"].ToString(), }; BindingWechatPage bindingWechatPage = new BindingWechatPage(registerByOpenIdPara); await Application.Current.MainPage.Navigation.PushAsync(bindingWechatPage); MessagingCenter.Unsubscribe <object, string>(this, "LoginSuccess"); MessagingCenter.Unsubscribe <object, string>(this, "Login"); } catch (Exception ex) { Console.WriteLine("错误:" + ex); } }); }, () => { return(true); }); }
public AuthCodePage(RegisterByOpenIdPara registerByOpenIdPara) { InitializeComponent(); BindingContext = new AuthCodeViewModel(registerByOpenIdPara); }