Esempio n. 1
0
        /// <summary>
        /// 保存用户登录认证信息
        /// </summary>
        /// <param name="auth"></param>
        /// <returns></returns>
        public static int SaveAuth(Auth auth)
        {
            string authXML=Factory.CreateXMLMsg(auth);
            string sql = string.Format ("update log set auth='{0}',updateTime='{2}' where userID='{1}'",authXML,auth.UserID,DateTime.Now.ToString());
            string constr = "data source=" + Application.StartupPath + "\\login" + ".db";

            SQLiteConnection con = new SQLiteConnection(constr);
            con.Open();
            SQLiteCommand cmd = new SQLiteCommand(sql);
            cmd.Connection = con;
            int affected=cmd.ExecuteNonQuery();
            if (affected == 0)
            {
                sql = string.Format("insert into log(auth,userID,updateTime) values( '{0}','{1}','{2}')", authXML, auth.UserID, DateTime.Now.ToString());
                cmd.CommandText = sql;
                affected = cmd.ExecuteNonQuery();
            }
            cmd.Dispose(); cmd = null;
            con.Close(); con.Dispose(); con = null;
            return affected;
        }
Esempio n. 2
0
        private void onLogin(Auth auth)
        {

            if (auth.type == type.error)//密码错误 
                LoginPasswordError();
            else if (auth.type == type.result)//登录成功
            {
                if (myPassword == "" && MyAuth.IsSavePassword)//如果是第一次成功登录并且需要保存登录密码 
                {
                    IMLibrary3.OpeRecordDB.SaveAuth(MyAuth);//保存成功登录用户的信息
                }
                else if (myPassword == "" && !MyAuth.IsSavePassword)
                {
                    myPassword = MyAuth.Password;//暂存登录成功后的密码
                    MyAuth.Password = "";
                    IMLibrary3.OpeRecordDB.SaveAuth(MyAuth);//保存成功登录用户的信息
                }

                if (myPassword == "")
                    myPassword = MyAuth.Password;//暂存登录成功后的密码

                MyAuth = auth;//暂存登录成功后的服务器返回的登录信息

                ///设置UDP文件传输服务器端口
                Global.FileTransmitServerEP = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(Global.ServerDomain), MyAuth.FileServerUDPPort);
                ///设置UDP音视频传输服务器端口
                Global.AVTransmitServerEP = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(Global.ServerDomain), MyAuth.AVServerUDPPort);
                ///设置TCP图片文件传输服务器端口
                Global.ImageServerEP=new System.Net.IPEndPoint(System.Net.IPAddress.Parse(Global.ServerDomain),MyAuth.FileServerTCPPort);


                this.LoginTimeCount = 0;//超时器清零
                this.timerLogin1.Enabled = false;//停止登录超时检测
                if (UserLoginSuccessful != null) //触发登录成功事件
                    UserLoginSuccessful(this, auth);
            }
            else if (auth.type == type.Else)//别处登录
                ElseLogin();
        }
Esempio n. 3
0
        /// <summary>
        /// 开始登录 
        /// </summary>
        /// <param name="auth">登录用户参数</param>
        /// <param name="IsOutTime">是否超时时钟重复的登录</param>
        public void Login(IMLibrary3.Protocol.Auth auth, bool IsOutTime)
        {
            if (myPassword!="")//如果已经登录成功过
                auth.Password = myPassword;//将正确的密码设置为登录密码

            MyAuth = auth;//暂存自己的登录信息于内存

            if (tcpClient == null || tcpClient.IsDisposed)
            {
                tcpClient = new TCPClient();
                tcpClient.PacketReceived += new TCP_Client.PacketReceivedEventHandler(tcpClient_PacketReceived);
                tcpClient.Disonnected += new EventHandler(tcpClient_Disonnected);
            }
            if (!tcpClient.IsConnected)
                tcpClient.Connect(Global.ServerDomain,Global.ServerMsgPort);

            if (!this.timerLogin1.Enabled)
                this.timerLogin1.Enabled = true;

            SendMessageToServer(auth);//向服务器登录
        }
Esempio n. 4
0
        /// <summary>
        /// 处理用户登录请求
        /// </summary>
        /// <param name="auth"></param>
        private void onLogin(Auth auth, TCPServerSession session)
        {
            UserVcard user = getUser(auth.UserID);
            if (user != null && !user.Disable && Hasher.GetMD5Hash(TextEncoder.textToBytes(auth.Password)) == user.Password) //如果用户存在未禁用且密码正确
            {
                #region 重复登录或异地登录
                if (user.Tag != null && user.Tag is TCPServerSession)
                {
                    ///通知用户此帐号异地登录
                    auth.type = type.Else;
                    auth.Password = session.ID;
                    TCPServerSession se = user.Tag as TCPServerSession;
                    if (se != null && !se.IsDisposed && se.IsConnected)
                    {
                        tcpMessageServer.SendMessageToSession(se, auth);
                        se.Disconnect();//断开连接,释放资源
                    }
                }
                #endregion

                session.Tag = user;
                session.IsAuthenticated = true;

                user.Tag = session;
                user.ShowType = auth.ShowType;
                user.Status = auth.Status;

                ///发送登录成功消息
                auth.UserName = user.UserName;//告之登录用户的姓名
                auth.type = type.result;//告之登录用户成功登录
                auth.Password = session.ID;//告之登录用户在服务器的SESSION
                auth.LastDateTime = user.LastDateTime;//告之登录用户上次登录时间
                auth.LastIP = user.LastIP;//告之登录用户上次登录IP
                auth.FileServerTCPPort = DBHelper.settings.TcpFilePort;//告之登录用户TCP文件传输服务端口
                auth.FileServerUDPPort = DBHelper.settings.UdpFilePort;//告之登录用户UDP文件传输服务端口
                auth.isAdmin = user.isAdmin;//告之登录用户是否管理员
                auth.isBroadcast = user.isBroadcast;//告之登录用户是否可以发送广播消息
                auth.isSendNotice = user.isSendNotice;//告之登录用户是否可以发送通知消息
                auth.isSendSMS = user.isSendSMS;//告之登录用户是否可以发送手机短信
                auth.isEditUserData = user.isEditUserData;//告之登录用户是否可以编辑用户资料

                user.LastDateTime = DateTime.Now.ToString();
                user.LastIP = session.RemoteEndPoint.Address.ToString();

                //通知用户登录成功
                tcpMessageServer.SendMessageToSession(session, auth);

                //发送企业组织机构版本信息给用户
                orgVersion.RoomsCount = user.Rooms.Count;//用户加入群的数量
                tcpMessageServer.SendMessageToSession(session, orgVersion);

            }
            else//如果用户不存在或密码错误
            {
                ///发送密码错误消息
                auth.type = type.error;
                auth.Password = session.ID;
                tcpMessageServer.SendMessageToSession(session, auth);
            }
        }