private void btnSignup_Click(object sender, RoutedEventArgs e)
 {
     if (Pwd.Password == Pwd2.Password)
     {
         SignupContract signup = new SignupContract(txtName.Text.Trim(), Pwd.Password.Trim());
         //tcpHelper.SendMessage(string.Format("SIGNUP@user:{0},pwd:{1}", txtName.Text.Trim(), Pwd.Password.Trim()));
     }
     else
     {
         ShowMsg(null, "密码不符合");
     }
 }
Beispiel #2
0
 private void btnSignUp_Click(object sender, RoutedEventArgs e)
 {
     Connect();
     if (Pwd.Password == Pwd2.Password && Pwd.Password != "" & txtName.Text != null)
     {
         SignupContract signupContract = new SignupContract(txtName.Text.Trim(), Pwd.Password.Trim());
         //helper.SendMessage(string.Format("SIGNUP@user:{0},pwd:{1}", txtName.Text.Trim(), Pwd.Password.Trim()));
         helper.SendMessage(string.Format("SIGNUP@{0}", DataHelpers.XMLSer <SignupContract>(signupContract)));
     }
     else
     {
         ShowMsg(null, "密码不符合");
     }
 }
Beispiel #3
0
        //用户注册
        public SignUpCallBack Signup(SignupContract contract)
        {
            SignUpCallBack call = new SignUpCallBack();
            string         Id   = string.Empty;

            using (var model = new Data.DataModel())
            {
                //获取全局唯一的用户Id
                while (true)
                {
                    Id = GetARandomId();
                    var cf = model.users.Where(p => p.UserId.Equals(Id)).Count();
                    if (cf <= 0)
                    {
                        break;
                    }
                }
                //将用户ID插入数据库
                try
                {
                    model.users.Add(new user {
                        UserId = Id, UserName = contract.UserName, Password = contract.UserPwd
                    });
                    model.SaveChanges();
                    call.status  = Status.Yes;
                    call.UserId  = Id;
                    call.MoreMsg = "注册成功!";
                }
                catch (Exception e)
                {
                    call.status  = Status.No;
                    call.UserId  = null;
                    call.MoreMsg = "注册失败:" + e.Message;
                }
                return(call);
            }
        }
Beispiel #4
0
        public static void Handle(object sender, string data)
        {
            ServerHandle  server = new ServerHandle();
            IServerHandle ish    = (IServerHandle)server;
            TCPHelper     helper = (TCPHelper)sender;

            string[] d = Data_Init(data);
            switch (d[0])
            {
            case "LOGIN":
                LoginContract login = null;
                try
                {
                    login = WTalk.Helpers.DataHelpers.DeXMLSer <LoginContract>(d[1]);
                }
                catch { }
                LoginCallBack callBack = ish.Login(helper.tcpClient, login);
                if (ShowOnServerWindow != null)
                {
                    if (callBack.LoginStatus == Status.Yes)
                    {
                        UserArgs args = new UserArgs
                        {
                            IP = helper.tcpClient.Client.RemoteEndPoint.ToString(),
                            Id = login.UserId
                        };
                        string log = string.Format("{0}-->Login Success", helper.tcpClient.Client.RemoteEndPoint.ToString());
                        ShowOnServerWindow(null, log);
                        if (LoginHandler != null)
                        {
                            LoginHandler(null, args);
                        }
                    }
                    else
                    {
                        string log = string.Format("{0}-->Login Fail", helper.tcpClient.Client.RemoteEndPoint.ToString());
                        ShowOnServerWindow(null, log);
                    }
                }
                string msg = string.Format("LOGINCALLBACK@{0}", WTalk.Helpers.DataHelpers.XMLSer <LoginCallBack>(callBack));
                helper.SendMessage(msg);
                break;

            case "SIGNUP":
                SignupContract signup = null;
                try
                {
                    signup = DataHelpers.DeXMLSer <SignupContract>(d[1]);
                }
                catch { }
                SignUpCallBack signUpCallBack = ish.Signup(signup);
                if (ShowOnServerWindow != null)
                {
                    string log = string.Format("{0}-->Signup:{1}", helper.tcpClient.Client.RemoteEndPoint.ToString(), signUpCallBack.MoreMsg);
                    //if (callBack.LoginStatus == Status.Yes)
                    //{
                    //    string log = string.Format("{0}-->Signup", helper.tcpClient.Client.RemoteEndPoint.ToString());
                    //    ShowOnServerWindow(null, log);
                    //}
                    //else
                    //{
                    //    string log = string.Format("{0}-->Login Fail", helper.tcpClient.Client.RemoteEndPoint.ToString());
                    //    ShowOnServerWindow(null, log);
                    //}
                    ShowOnServerWindow(null, log);
                }
                helper.SendMessage(string.Format("SIGNUPCALLBACK@{0}", DataHelpers.XMLSer <SignUpCallBack>(signUpCallBack)));
                break;

            case "LOGOUT":
                //string logoutlog = string.Format("{0}-->登出", helper.tcpClient.Client.RemoteEndPoint.ToString());
                //if(ShowOnServerWindow != null)
                //{
                //    ShowOnServerWindow(null, logoutlog);
                //}
                break;

            case "SEARCH":
                SearchContract search = null;
                try
                {
                    search = DataHelpers.DeXMLSer <SearchContract>(d[1]);
                    SearchCallBack back = ish.Search(search);
                    helper.SendMessage(string.Format("SEARCHCALLBACK@{0}", DataHelpers.XMLSer <SearchCallBack>(back)));
                }
                catch
                {
                }
                break;

            case "ADD":
                AddContract add = null;
                try
                {
                    add = DataHelpers.DeXMLSer <AddContract>(d[1]);
                    AddComfirmArgs args = ish.Add(add);
                    if (args.IP != "Offline")
                    {
                        AddHandler(null, args);
                    }
                }
                catch
                {
                    break;
                }
                break;

            case "REMOVE":
                RemoveContract remove = null;
                try
                {
                    remove = DataHelpers.DeXMLSer <RemoveContract>(d[1]);
                    ish.RemoveFriends(remove);
                    if (RemoveFriendHandler != null)
                    {
                        RemoveFriendHandler(null, remove);
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
                break;

            case "TALK":
                TalkContract talk = new TalkContract();
                try
                {
                    talk = DataHelpers.DeXMLSer <TalkContract>(d[1]);
                    if (TalkHandler != null)
                    {
                        TalkHandler(null, talk);
                    }
                }
                catch
                {
                }
                break;

            case "ADDCONFIRMCALLBACK":
                AddConfirmCallBack accb        = null;
                AddCallBack        addCallBack = null;
                try
                {
                    accb        = DataHelpers.DeXMLSer <AddConfirmCallBack>(d[1]);
                    addCallBack = ish.AddComfirm(accb);
                    if (UpdateFriendListHandler != null)
                    {
                        UpdateFriendListHandler(null, addCallBack);
                    }
                }
                catch
                {
                    break;
                }
                break;

            default:
                break;
            }
        }