Ejemplo n.º 1
0
        /// <summary>
        /// 验证码登录
        /// </summary>
        /// <param name="loginPara"></param>
        /// <returns></returns>
        public async Task <LoginRD> LoginByAuthCode(LoginPara loginPara)
        {
            string url  = "/member/loginByAuthCode";
            var    json = JsonConvert.SerializeObject(loginPara);

            LoginRD loginRD = await RestSharpHelper <LoginRD> .PostAsync(url, json);

            return(loginRD);
        }
Ejemplo n.º 2
0
        /// <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;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 登录 ok
        /// </summary>
        /// <param name="tel">手机号</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public async Task <LoginRD> Login(LoginPara loginPara)
        {
            string url = rootUrl3 + "/member/loginByTel";

            string httpContent = JsonConvert.SerializeObject(loginPara);

            string responseBody = await PostAsync(url, httpContent);

            LoginRD loginRD = JsonConvert.DeserializeObject <LoginRD>(responseBody);

            return(loginRD);
        }
        /// <summary>
        /// 上传新头像
        /// </summary>
        private async void UploadAvatar()
        {
            try
            {
                if (!Tools.IsNetConnective())
                {
                    CrossToastPopUp.Current.ShowToastError("无网络连接,请检查网络。", ToastLength.Long);
                    return;
                }

                if (string.IsNullOrWhiteSpace(base64))
                {
                    CrossToastPopUp.Current.ShowToastWarning("请选择新头像", ToastLength.Long);
                    return;
                }

                //RestSharpService _restSharpService = new RestSharpService();
                SimpleRD uploadImageRD = await RestSharpService.UploadImage(base64);

                if (uploadImageRD.success)
                {
                    LoginRD loginRD = await RestSharpService.GetUserInfo();

                    if (loginRD.result.message == null)
                    {
                        GlobalVariables.LoggedUser = loginRD.result;   //将登录用户的信息保存成全局静态变量
                        GlobalVariables.IsLogged   = true;

                        string  fileName = Path.Combine(FileSystem.CacheDirectory, "log.dat");
                        JObject log      = new JObject();
                        log.Add("LoginTime", DateTime.UtcNow);
                        log.Add("UserInfo", JsonConvert.SerializeObject(loginRD.result));
                        //string text = "State:Checked\n" + "Account:" + Tel + "\nPassword:"******"\nLoginTime:" + DateTime.UtcNow;
                        File.WriteAllText(fileName, log.ToString());
                    }

                    CrossToastPopUp.Current.ShowToastSuccess("修改成功!", ToastLength.Short);
                    await Application.Current.MainPage.Navigation.PopAsync();
                }
                else
                {
                    CrossToastPopUp.Current.ShowToastError("修改失败,请稍后再试。", ToastLength.Short);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <returns></returns>
        public static async Task <LoginRD> GetUserInfo()
        {
            try
            {
                string url = "/member/getMemberInfo?id=" + GlobalVariables.LoggedUser.id;

                LoginRD loginRD = await RestSharpHelper <LoginRD> .GetAsync(url);

                return(loginRD);
            }
            catch (ApplicationException ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// openid登录
        /// </summary>
        /// <returns></returns>
        public static async Task <LoginRD> LoginByOpenId(string openId)
        {
            try
            {
                string url = "/member/loginByOpenId?openId=" + openId;

                LoginRD loginRD = await RestSharpHelper <LoginRD> .GetAsync(url);

                return(loginRD);
            }
            catch (ApplicationException ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 验证码登录
        /// </summary>
        /// <param name="loginPara"></param>
        /// <returns></returns>
        public static async Task <LoginRD> LoginByAuthCode(LoginPara loginPara)
        {
            try
            {
                string url  = "/member/loginByAuthCode";
                var    json = JsonConvert.SerializeObject(loginPara);

                LoginRD loginRD = await RestSharpHelper <LoginRD> .PostAsync(url, json);

                return(loginRD);
            }
            catch (ApplicationException ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 登录
        /// </summary>
        private async void OnLogin()
        {
            try
            {
                if (!Tools.IsNetConnective())
                {
                    CrossToastPopUp.Current.ShowToastError("无网络连接,请检查网络。", ToastLength.Long);
                    return;
                }

                LoginPara loginPara = new LoginPara
                {
                    userPwd  = Pwd,
                    authCode = "",
                    tel      = Tel
                };

                //RestSharpService _restSharpService = new RestSharpService();
                LoginRD loginRD = await RestSharpService.Login(loginPara);

                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);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 9
0
        /// <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;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 初始化
        /// </summary>
        private async void InitUserInfo()
        {
            try
            {
                if (!Tools.IsNetConnective())
                {
                    CrossToastPopUp.Current.ShowToastError("无网络连接,请检查网络。", ToastLength.Long);
                    return;
                }

                LoginRD loginRD = await RestSharpService.GetUserInfo();

                if (loginRD.result != null)
                {
                    User = loginRD.result;
                }

                Avatar = User.pricture;
                switch (User.sex)
                {
                case "0": Gender = "女"; break;

                case "1": Gender = "男"; break;

                case "-1": Gender = "保密"; break;

                default:
                    break;
                }

                WeChatText = string.IsNullOrWhiteSpace(User.openId) ? "未绑定" : "已绑定";
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 响应登录事件
        /// </summary>
        private async void Login()
        {
            try
            {
                if (!Tools.IsNetConnective())
                {
                    CrossToastPopUp.Current.ShowToastError("无网络连接,请检查网络。", ToastLength.Short);
                    IsLoading = false;
                    return;
                }

                if (string.IsNullOrWhiteSpace(TelOrEmpNo))
                {
                    CrossToastPopUp.Current.ShowToastError("手机号或员工号不能为空", ToastLength.Short);
                    IsLoading = false;
                    return;
                }

                if (string.IsNullOrWhiteSpace(Password))
                {
                    CrossToastPopUp.Current.ShowToastError("密码不能为空", ToastLength.Short);
                    IsLoading = false;
                    return;
                }

                string result = await RestSharpService.Login(TelOrEmpNo, Password);

                if (string.IsNullOrWhiteSpace(result))
                {
                    CrossToastPopUp.Current.ShowToastError("服务器返回值为空", ToastLength.Short);
                    IsLoading = false;
                    return;
                }
                else
                {
                    BaseResponse baseResponse = JsonConvert.DeserializeObject <BaseResponse>(result);

                    if (baseResponse.Flag == "success")
                    {
                        //GlobalVariables.LoggedUser = JsonConvert.DeserializeObject<UserInfo>(result);
                        //CrossToastPopUp.Current.ShowToastSuccess(baseResponse.Msg, ToastLength.Short);

                        LoginRD loginRD = JsonConvert.DeserializeObject <LoginRD>(baseResponse.Result.ToString());
                        loginRD.DBName = loginRD.DBName.TrimStart('[');

                        GlobalVariables.LoggedUser       = loginRD;
                        GlobalVariables.IsLogged         = true;
                        GlobalVariables.LoggedUser.EmpNo = TelOrEmpNo;
                        //提供自动登录的信息  除非用户手动退出登录 LoginState变为False
                        string dateNow = DateTime.Now.ToString();
                        string text    = "";
                        if (IsRememberPwd)
                        {
                            text = "State:Checked\n" + "Account:" + TelOrEmpNo + "\n" + "Password:"******"\n" + "LoginDate:" + dateNow;
                            File.WriteAllText(autoLoginFileName, text);
                        }

                        //MainPage mainPage = new MainPage();
                        //await Application.Current.MainPage.Navigation.PushAsync(mainPage);
                        MyNavigationPage myNavigationPage = new MyNavigationPage(new MainPage());
                        Application.Current.MainPage = myNavigationPage;
                    }
                    else
                    {
                        CrossToastPopUp.Current.ShowToastError(baseResponse.Msg, ToastLength.Short);
                        IsLoading = false;
                        return;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 登录
        /// </summary>
        private async void OnLogin()
        {
            try
            {
                if (!Tools.IsNetConnective())
                {
                    CrossToastPopUp.Current.ShowToastError("无网络连接,请检查网络。", ToastLength.Long);
                    return;
                }

                if (AuthCode.Length != 6)
                {
                    CrossToastPopUp.Current.ShowToastError("请输入6位验证码", ToastLength.Long);
                    return;
                }

                LoginPara loginPara = new LoginPara
                {
                    authCode = AuthCode,
                    tel      = Tel
                };

                LoginRD loginRD = await _restSharpService.LoginByAuthCode(loginPara);

                /*
                 * if (loginRD.code == 200)
                 * {
                 *  CrossToastPopUp.Current.ShowToastSuccess(loginRD.message, ToastLength.Long);
                 *
                 *  MainPage mainPage = new MainPage();
                 *  await Navigation.PushModalAsync(mainPage);
                 * }
                 * else
                 * {
                 *  CrossToastPopUp.Current.ShowToastError(loginRD.message, ToastLength.Long);
                 * }*/
                if (loginRD.result.message == null)
                {
                    CrossToastPopUp.Current.ShowToastSuccess("欢迎您登录美而好家具!", ToastLength.Long);

                    GlobalVariables.LoggedUser = loginRD.result;   //将登录用户的信息保存成全局静态变量
                    GlobalVariables.IsLogged   = true;

                    string  fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "log.dat");
                    JObject log      = new JObject();
                    log.Add("LoginTime", DateTime.UtcNow);
                    log.Add("UserInfo", JsonConvert.SerializeObject(loginRD.result));
                    //string text = "State:Checked\n" + "Account:" + Tel + "\nPassword:"******"\nLoginTime:" + DateTime.UtcNow;
                    File.WriteAllText(fileName, log.ToString());

                    MainPage mainPage = new MainPage();
                    await Application.Current.MainPage.Navigation.PushModalAsync(mainPage);
                }
                else
                {
                    CrossToastPopUp.Current.ShowToastError(loginRD.result.message, ToastLength.Long);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 保存
        /// </summary>
        private async void SaveUserInfo()
        {
            try
            {
                if (!Tools.IsNetConnective())
                {
                    CrossToastPopUp.Current.ShowToastError("无网络连接,请检查网络。", ToastLength.Long);
                    return;
                }

                if (myTimer != null && myTimer.RemainTime.TotalSeconds > 0)
                {
                }
                else
                {
                    SimpleRD sendAuthCodeRD = await RestSharpService.SendAuthCode(GlobalVariables.LoggedUser.phone);

                    myTimer = new MyTimer {
                        EndDate = DateTime.Now.Add(new TimeSpan(900000000))
                    };
                    LoadAsync();

                    if (sendAuthCodeRD.success)
                    {
                        CrossToastPopUp.Current.ShowToastSuccess("请注意查收短信!", ToastLength.Short);
                    }
                    else
                    {
                        CrossToastPopUp.Current.ShowToastWarning("错误,请稍后再试。", ToastLength.Short);
                    }
                }

                string authCode = await Application.Current.MainPage.DisplayPromptAsync("修改用户信息", string.Format("请输入验证码:({0}s后重试)", RemainingTime), "确认", "取消", "6位验证码", 6, Keyboard.Numeric);

                if (authCode == null)
                {
                    //CrossToastPopUp.Current.ShowToastWarning("已取消", ToastLength.Long);
                    return;
                }
                else if (authCode == "")
                {
                    CrossToastPopUp.Current.ShowToastWarning("请输入验证码。", ToastLength.Long);
                    return;
                }

                SimpleRD checkAuthCodeRD = await RestSharpService.CheckAuthCode(GlobalVariables.LoggedUser.phone.ToString(), authCode);

                if (!checkAuthCodeRD.success)
                {
                    CrossToastPopUp.Current.ShowToastError("验证码错误。", ToastLength.Short);
                    return;
                }

                UpdateUserPara updateUserPara = new UpdateUserPara
                {
                    id              = User.id,
                    phone           = GlobalVariables.LoggedUser.phone,
                    password        = Password,
                    email           = User.email,
                    username        = User.username,
                    description     = User.description,
                    userType        = User.userType,
                    address         = User.address,
                    balance         = User.balance,
                    file            = "",
                    points          = User.points,
                    state           = User.state,
                    rebateTotal     = User.rebateTotal,
                    created         = User.created,
                    updated         = User.updated,
                    personName      = User.personName,
                    country         = User.country,
                    companyProvince = User.companyProvince,
                    companyName     = User.buyCompanyName,
                    invitePhone     = ""
                };

                switch (Gender)
                {
                case "男": updateUserPara.sex = "1"; break;

                case "女": updateUserPara.sex = "0"; break;

                case "保密": updateUserPara.sex = "-1"; break;

                default: updateUserPara.sex = "-1"; break;
                }

                SimpleRD updateUserInfoRD = await RestSharpService.UpdateUserInfo(updateUserPara);

                if (updateUserInfoRD.success)
                {
                    LoginRD loginRD = await RestSharpService.GetUserInfo();

                    if (loginRD.result.message == null)
                    {
                        GlobalVariables.LoggedUser = loginRD.result;   //将登录用户的信息保存成全局静态变量
                        GlobalVariables.IsLogged   = true;

                        string  fileName = Path.Combine(FileSystem.CacheDirectory, "log.dat");
                        JObject log      = new JObject();
                        log.Add("LoginTime", DateTime.UtcNow);
                        log.Add("UserInfo", JsonConvert.SerializeObject(loginRD.result));
                        //string text = "State:Checked\n" + "Account:" + Tel + "\nPassword:"******"\nLoginTime:" + DateTime.UtcNow;
                        File.WriteAllText(fileName, log.ToString());
                    }

                    CrossToastPopUp.Current.ShowToastSuccess("修改成功!", ToastLength.Short);
                    await Application.Current.MainPage.Navigation.PopAsync();
                }
                else
                {
                    CrossToastPopUp.Current.ShowToastError("修改失败,请稍后再试。", ToastLength.Short);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }