Exemple #1
0
 /// <summary>
 /// 注册成功
 /// </summary>
 /// <param name="sender">Client</param>
 /// <param name="e"></param>
 private void RegisterComplete(object sender, UploadDataCompletedEventArgs e)
 {
     Task.Run(() =>
     {
         if (e.Error == null)
         {
             string result = Encoding.UTF8.GetString(e.Result);
             var resuser   = JsonConvert.DeserializeObject <RegisterModel>(result);
             Task.Run(() =>
             {
                 var client = ShiKuManager.UploadAvator(resuser.Data.userId, UploadfilePath);
                 client.UploadDataCompleted += (sen, eve) =>
                 {
                     if (eve.Error == null)
                     {
                         string restxt = Encoding.UTF8.GetString(eve.Result);
                         var resavator = JsonConvert.DeserializeObject <JsonBase>(restxt);
                         if (resavator.resultCode == 1)
                         {
                             App.Current.Dispatcher.Invoke(() =>
                             {
                                 LoginPageIndex = 0;
                                 SnackBar.Enqueue("注册成功");
                                 UserId = PhoneNumber;
                                 InitialRegisterProperties();//重置注册页面
                                 EnabledRegister = true;
                             });
                         }
                         else
                         {
                             SnackBar.Enqueue(resuser.resultMsg, true);                        //提示错误信息
                             App.Current.Dispatcher.Invoke(() => { EnabledRegister = true; }); //启用注册
                         }
                     }
                     else
                     {
                         SnackBar.Enqueue(eve.Error.Message);
                         App.Current.Dispatcher.Invoke(() => { EnabledRegister = true; });//启用注册
                     }
                 };
             });
         }
         else
         {
             SnackBar.Enqueue("注册失败:" + e.Error.Message);
             App.Current.Dispatcher.Invoke(() =>
             {
                 EnabledRegister = true;
             });
             ConsoleLog.Output("注册失败:" + e.Error.Message);
         }
     });
 }
Exemple #2
0
        private void UserLogin(IHavePassword parameter)
        {
            Task.Run(() =>
            {
                if (IsVisitorLogin == true)//游客登录
                {
                    Applicate.URLDATA.data.apiUrl = ConfigurationUtil.GetValue("InitialServer") + "/";
                    VisitorKey = ConfigurationUtil.GetValue("InitialServer_key");

                    int index  = VisitorKey.LastIndexOf("?");
                    VisitorKey = VisitorKey.Substring(index + 1);

                    int index2 = VisitorKey.LastIndexOf("=");
                    VisitorKey = VisitorKey.Substring(index2 + 1);
                    VisitorLogin();
                    return;
                }

                //接收用户名和密码
                string password;
                if (IsRememberPwd &&
                    TruePasswordWhenRemembered != null &&
                    !IsCancelRememberPwdAndTextNewPwd)     //如果当前处于记住有效密码 且 不为加载密码后重新输入的密码
                {
                    password = TruePasswordWhenRemembered; //使用数据库密码
                    //parameter.LoginSecurePassword = TruePasswordWhenRemembered.ToSecureString();
                }
                else//没记住密码 或
                {
                    password = parameter.LoginSecurePassword.UnSecure();//使用文本框内密码
                }
                EnabledLogin = false;//暂时禁用登录
                //获取经纬度
                string Longitude = "0";
                string Latitude  = "0";
                if (Location.IsUnknown != true)
                {
                    Longitude = Location.Longitude.ToString();
                    Latitude  = Location.Latitude.ToString();
                }
                try
                {
                    var client = ShiKuManager.ShiKuLogin(UserId, password, Latitude, Longitude, GobalAreaList[SelectedCountryCode].prefix.ToString());
                    client.UploadDataCompleted += LoginComplete;
                }
                catch (Exception ex)
                {
                    SnackBar.Enqueue("登录失败:" + ex.Message, "重试", () => { LoginCommand.Execute(Applicate.GetWindow <IHavePassword>()); });
                    Console.WriteLine("登录失败:" + ex.Message);
                    EnabledLogin = true;//启用登录
                }
            });
        }
Exemple #3
0
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="parameter">包含密码的Login对象</param>
        private void UserRegisterAccount(IHavePassword parameter)
        {
            if (UploadfilePath == null)
            {
                SnackBar.Enqueue("请选择头像!");
                return;
            }
            if (rNickname == null || rNickname.Trim() == "")
            {
                SnackBar.Enqueue("昵称不能为空!");
                return;
            }
            if (parameter.FirstRegisterSecurePassword.UnSecure().Length < 6)
            {
                SnackBar.Enqueue("密码长度不能小于6位!");
                return;
            }
            if (parameter.FirstRegisterSecurePassword.UnSecure() != parameter.FinalRegisterSecurePassword.UnSecure())
            {
                SnackBar.Enqueue("两次输入密码不一致!");
                return;
            }

            /*
             * else if (string.IsNullOrEmpty(AvatorPath))
             * {
             *  SnackBar.Enqueue("请选择需要上传的头像!");
             *  return;
             * }
             */

            HttpClient client = APIHelper.RegisterAccountAsync(
                PhoneNumber, GobalAreaList[RSelectedCountryCode].prefix.ToString(),
                parameter.FinalRegisterSecurePassword.UnSecure(),
                RNickname,
                gender,
                Helpers.DatetimeToStamp(BornDate),
                SelectedCountry,
                SelectedProvince,
                SelectedCity,
                SelectedArea);

            EnabledRegister = false;//暂时禁用控件
            //指定注册成功事件
            client.UploadDataCompleted += RegisterComplete;
        }
Exemple #4
0
 private void LoginComplete(object sender, UploadDataCompletedEventArgs e)
 {
     if (e.Error == null)//网络正常
     {
         string res      = Encoding.UTF8.GetString(e.Result);
         var    curruser = JsonConvert.DeserializeObject <Jsonuser>(res); //获取登录用户详情
         var    client   = (HttpClient)sender;
         string pwd      = client.Tag3.ToString();                        //获取密码
         if (curruser != null && curruser.resultCode == 1)
         {
             Task.Run(() =>
             {
                 var dblocalUser           = new LocalUser();                       //保存最近消息
                 dblocalUser.LastLoginTime = Helpers.DatetimeToStamp(DateTime.Now); //记录登录时间
                 dblocalUser.Telephone     = UserId;                                //电话号码
                 dblocalUser.UserId        = curruser.data.userId;                  //UserId
                 if (IsRememberPwd)                                                 //如果选中记住密码(保存密文密码到数据库)
                 {
                     dblocalUser.Password       = pwd;                              //存储密码
                     dblocalUser.PasswordLength = pwd.Length;                       //密码长度
                 }
                 dblocalUser.InsertOrUpdatePassword();                              //写入数据库
                 //成功后关闭登录
                 Messenger.Default.Send(true, Login.CloseWindow);
             });
         }
         else
         {
             //如ResultCode不为1的话,就输出错误信息,,,,,,并在界面给予提示
             SnackBar.Enqueue(curruser.resultMsg, true);
             EnabledLogin = true;//失败后启用登录按-钮
         }
     }
     else//网络错误
     {
         var error = e.Error as WebException;
         SnackBar.Enqueue("登录失败!\n" + error.Message, false);
         EnabledLogin = true;//失败后启用登录按钮
     }
 }
Exemple #5
0
        /// <summary>
        /// 游客登录
        /// </summary>
        private void VisitorLogin()
        {
            //获取经纬度
            string Longitude = "0";
            string Latitude  = "0";

            if (Location.IsUnknown != true)
            {
                Longitude = Location.Longitude.ToString();
                Latitude  = Location.Latitude.ToString();
            }
            try
            {
                var client = ShiKuManager.ShiKuVisitorLogin(VisitorKey, Latitude, Longitude);
                client.UploadDataCompleted += VisitorLoginComplete;
            }
            catch (Exception ex)
            {
                SnackBar.Enqueue("登录失败:" + ex.Message, "重试", () => { LoginCommand.Execute(Applicate.GetWindow <IHavePassword>()); });
                Console.WriteLine("登录失败:" + ex.Message);
                EnabledLogin = true;//启用登录
            }
        }
Exemple #6
0
        /// <summary>
        /// 检查电话号码是否注册
        /// </summary>
        private void CheckPhoneNumber()
        {
            var client = APIHelper.TelephoneVerifyAsync(PhoneNumber);

            client.UploadDataCompleted += (sen, eve) =>
            {
                if (eve.Error == null)
                {
                    var res    = Encoding.UTF8.GetString(eve.Result);
                    var result = JsonConvert.DeserializeObject <JsonBase>(res);
                    if (result.resultCode != 1)
                    {
                        SnackBar.Enqueue(result.resultMsg);//电话验证出错
                    }
                    else
                    {
                    }
                }
                else
                {
                    SnackBar.Enqueue(eve.Error.Message);//显示网络错误
                }
            };
        }
        private void OnSearchComplete(object sender, UploadDataCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                JsonNerbyuser resusers = new JsonNerbyuser();
                var           str      = Encoding.UTF8.GetString(e.Result);    //转byte为字符串
                resusers = JsonConvert.DeserializeObject <JsonNerbyuser>(str); //反序列化
                if (resusers.resultCode == 1)
                {
                    List <DownLoadFile> files = new List <DownLoadFile>();
                    if (resusers.data.Count > 0)
                    {
                        for (int i = 0; i < resusers.data.Count; i++)
                        {
                            AccountList.Add(resusers.data[i]);

                            //这里需要把特殊账号 排除出来。
                            string localpath = Applicate.LocalConfigData.GetDisplayAvatorPath(resusers.data[i].userId);
                            if (!File.Exists(localpath))//添加需要下载的头像
                            {
                                files.Add(new DownLoadFile
                                {
                                    Jid   = resusers.data[i].userId,
                                    Name  = resusers.data[i].nickname,
                                    Token = resusers.data[i].userId,
                                    ShouldDeleteWhileFileExists = true,
                                    LocalUrl = localpath,
                                    Type     = DownLoadFileType.Image
                                });
                            }
                        }
                        HttpDownloader.Download(files, (item) =>
                        {
                            switch (item.State)
                            {
                            case DownloadState.Successed:
                                var tmp = AccountList.FirstOrDefault(a => a.userId == item.Jid);
                                if (tmp != null)
                                {
                                    App.Current.Dispatcher.Invoke(() =>
                                    {
                                        tmp.userId = item.Jid;    //下载完成后刷新头像
                                    });
                                }
                                break;

                            case DownloadState.Error:
                                break;

                            default:
                                break;
                            }
                        });
                    }
                    else
                    {
                        pageNum--;
                    }
                }
            }
            else
            {
                SnackBar.Enqueue("错误:" + e.Error.Message);
            }
            ShowLoadingProgressBar(false);//禁用按钮并显示
        }
        /// <summary>
        /// 消息回执
        /// </summary>
        /// <param name="msg"></param>
        public void MsgReceipt(Messageobject msg)
        {
            if (msg.type >= kWCMessageType.FriendRequest && msg.type <= kWCMessageType.CancelBlackFriend)
            {
                InVerifingWaiting = false;
                var mControl   = ServiceLocator.Current.GetInstance <MainViewModel>();
                var verifyItem = VerifyUserList.FirstOrDefault(v => v.toUserId == msg.toUserId);
                if (verifyItem == null)
                {
                    verifyItem = new VerifingFriend()
                    {
                        toNickname = msg.toUserName,
                        toUserId   = msg.ToId
                    };
                }

                switch (msg.type)
                {
                case kWCMessageType.FriendRequest:    //打招呼回执
                    verifyItem.VerifyStatus = -3;
                    verifyItem.Content      = "等待验证中...";
                    break;

                case kWCMessageType.RequestAgree:    //通过验证回执
                    verifyItem.VerifyStatus = 1;
                    verifyItem.Content      = "我已通过对" + msg.toUserName /*((verifyItem.sex == 0) ? ("他") : ("她")) */ + "的验证";
                    var tmp = mControl.FriendList.FirstOrDefault(m => m.Jid == msg.toUserId);
                    //mControl.MsgItemMouseDown(tmp);
                    mControl.StartNewChatFromItem(tmp.Clone());
                    mControl.Snackbar.Enqueue(verifyItem.Content);    //
                    //ServiceLocator.Current.GetInstance<MainViewModel>().LoadAllFriendsByApi();
                    break;

                case kWCMessageType.RequestRefuse: //回话回执
                    InProgress   = false;          //不处于发送状态
                    DialogShow   = false;          //关闭对话框
                    AnswerContnt = "";             //清空文本
                    SnackBar.Enqueue("回话给" + msg.toUserName + "成功");
                    break;

                case kWCMessageType.DeleteFriend:
                    verifyItem.Content      = "已删除好友 " + msg.toUserName;
                    verifyItem.toNickname   = msg.toUserName;  //此处为接收者Name
                    verifyItem.VerifyStatus = -1;
                    break;

                case kWCMessageType.BlackFriend:
                    verifyItem.Content    = "已将好友 " + msg.toUserName + " 拉黑";
                    verifyItem.toNickname = msg.toUserName;    //此处为接收者Name
                    break;

                case kWCMessageType.RequestFriendDirectly:    //直接添加好友
                    verifyItem.VerifyStatus = 1;
                    verifyItem.Content      = "已添加好友" + msg.toUserName /*((verifyItem.sex == 0) ? ("他") : ("她"))*/;
                    if (new DataOfFriends().ExistsLocal(msg.ToId))    //本地数据库有用户
                    {
                        var dbFri = new DataOfFriends().GetByUserId(msg.ToId);
                        dbFri.UpdateFriendState(msg.ToId, 2);    //互为好友
                    }
                    else
                    {
                    }
                    Messenger.Default.Send(verifyItem.Content, MainViewNotifactions.SnacbarMessage);    //提示
                    break;

                case kWCMessageType.CancelBlackFriend:
                    var tuser = new DataOfFriends().GetByUserId(msg.toUserId);
                    verifyItem.Content      = "已将 " + tuser.toNickname + " 移出黑名单";
                    verifyItem.VerifyStatus = 1;    //互为好友
                    break;

                default:
                    break;
                }
                //更新最近用户中的内容
                Messenger.Default.Send(new MessageListItem
                {
                    Jid = "10001",
                    MessageItemContent = verifyItem.Content,
                    Avator             = Applicate.LocalConfigData.GetDisplayAvatorPath("10001")
                }, MainViewNotifactions.UpdateRecentItemContent);
                AddOrUpdateToList(verifyItem); //更新UI
                verifyItem.InsertOrUpdate();   //存入数据库
                verifyItem.Update();           //更新至数据库
            }
        }