Пример #1
0
        public LoginInfo Login(string userId, string password, bool quitOther = false)
        {
            LoginInfo     loginInfo  = new LoginInfo();
            SqlBuilder    builder    = new SqlBuilder("axp.User");
            string        sql        = builder.GetQuerySql(0, "A.PERSONID,A.PERSONNAME,A.ROLEID,A.WALLPAPER,A.WALLPAPERSTRETCH", string.Format("A.USERID={0} And A.USERPASSWORD={1} And A.ISUSE=1", LibStringBuilder.GetQuotString(userId), LibStringBuilder.GetQuotString(password)));
            LibDataAccess dataAccess = new LibDataAccess();
            string        roleId     = string.Empty;
            bool          exists     = false;

            using (IDataReader reader = dataAccess.ExecuteDataReader(sql))
            {
                if (reader.Read())
                {
                    loginInfo.PersonId   = LibSysUtils.ToString(reader[0]);
                    loginInfo.PersonName = LibSysUtils.ToString(reader[1]);
                    roleId = LibSysUtils.ToString(reader[2]);
                    loginInfo.Wallpaper = LibSysUtils.ToString(reader[3]);
                    loginInfo.Stretch   = LibSysUtils.ToBoolean(reader[4]);
                    exists = true;
                }
            }
            if (exists)
            {
                LibHandle handle = LibHandleCache.Default.IsExistsHandle(LibHandeleType.PC, userId);
                if (handle != null)
                {
                    if (quitOther)
                    {
                        LibHandleCache.Default.RemoveHandle(handle.Handle);
                    }
                    else
                    {
                        loginInfo.IsUsed = true;
                    }
                }
                if (!loginInfo.IsUsed)
                {
                    long currentCount = LibHandleCache.Default.GetCount();
                    long maxUserCount = (long)LibHandleCache.Default.MaxUserCount;
                    if (maxUserCount != -1 && maxUserCount < currentCount)
                    {
                        loginInfo.IsOverUser = true;
                    }
                    else
                    {
                        string loginIp = string.Empty;
                        //Zhangkj20161219 增加LoginIp
                        System.ServiceModel.OperationContext context = System.ServiceModel.OperationContext.Current;
                        //对于非WCF的访问context为null
                        if (context != null)
                        {
                            System.ServiceModel.Channels.MessageProperties             properties = context.IncomingMessageProperties;
                            System.ServiceModel.Channels.RemoteEndpointMessageProperty endpoint   = properties[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty;
                            loginIp = endpoint.Address + ":" + endpoint.Port.ToString();
                        }
                        //创建新的Handle
                        handle = LibHandleCache.Default.GetHandle(string.Empty, LibHandeleType.PC, userId, loginInfo.PersonId, loginInfo.PersonName, roleId, loginIp);
                        if (handle != null)
                        {
                            loginInfo.Handle = handle.Handle;
                        }
                    }
                }
            }
            return(loginInfo);
        }
Пример #2
0
        public LoginInfo AppLogin(string userId, string password, string clientId, int clientType, bool quitOther = false)
        {
            LoginInfo loginInfo = new LoginInfo();
            //检查是否具有 AXPUSERAPP数据表,用于判定是否支持移动端App登录
            LibSqlModel sqlModel      = LibSqlModelCache.Default.GetSqlModel("axp.User");
            bool        hasAXPUSERAPP = false;

            if (sqlModel != null && sqlModel.Tables.Count > 1 && sqlModel.Tables[1].TableName.Equals("AXPUSERAPP"))
            {
                hasAXPUSERAPP = true;
            }
            if (hasAXPUSERAPP == false)
            {
                return(loginInfo);//如果没有需要的相关字段则直接返回
            }

            SqlBuilder builder = new SqlBuilder("axp.User");
            string     sql     = string.Format(@"SELECT 
                                        A.PERSONID,
                                        A.ROLEID,
                                        A.WALLPAPER,A.WALLPAPERSTRETCH,B.PERSONNAME,B.PHONENO,B.CORNET,B.HEADPORTRAIT,B.MAIL   
                                        FROM AXPUSER A LEFT JOIN COMPERSON B ON B.PERSONID=A.PERSONID   
                                        WHERE A.USERID={0} and A.USERPASSWORD={1} AND A.ISUSE=1", LibStringBuilder.GetQuotString(userId), LibStringBuilder.GetQuotString(password));
            //builder.GetQuerySql(0, "A.PERSONID,A.PERSONNAME,A.PHONENO,A.CORNET,A.HEADPORTRAIT,A.MAIL,A.ROLEID,A.WALLPAPER,A.WALLPAPERSTRETCH", string.Format("A.USERID={0} And A.USERPASSWORD={1} And A.ISUSE=1", LibStringBuilder.GetQuotString(userId), LibStringBuilder.GetQuotString(password)));
            LibDataAccess dataAccess = new LibDataAccess();
            string        roleId     = string.Empty;
            bool          exists     = false;

            using (IDataReader reader = dataAccess.ExecuteDataReader(sql))
            {
                if (reader.Read())
                {
                    loginInfo.PersonId   = LibSysUtils.ToString(reader["PERSONID"]);
                    loginInfo.PersonName = LibSysUtils.ToString(reader["PERSONNAME"]);
                    roleId = LibSysUtils.ToString(reader["ROLEID"]);
                    loginInfo.Wallpaper = LibSysUtils.ToString(reader["WALLPAPER"]);
                    loginInfo.Stretch   = LibSysUtils.ToBoolean(reader["WALLPAPERSTRETCH"]);
                    //20170214 施卢威 增加头像 Email 短号信息
                    loginInfo.Headportrait = LibSysUtils.ToString(reader["HEADPORTRAIT"]);
                    loginInfo.UserEMail    = LibSysUtils.ToString(reader["MAIL"]);
                    loginInfo.Cornet       = LibSysUtils.ToString(reader["CORNET"]);
                    loginInfo.UserPhone    = LibSysUtils.ToString(reader["PHONENO"]);
                    exists = true;
                }
            }
            if (exists)
            {
                #region 帐号与登录设备关联
                string appSql = string.Empty;
                //查询帐号是否已有设备标识
                int isAPPClient = LibSysUtils.ToInt32(dataAccess.ExecuteScalar(string.Format("SELECT COUNT(*) from AXPUSERAPP WHERE USERID = '{0}' and CLIENTTYPE={1}", userId, clientType)));
                if (isAPPClient > 0)
                {
                    //更新设备标识信息
                    appSql = string.Format("UPDATE AXPUSERAPP SET  CLIENTID={1}    WHERE USERID={0} AND CLIENTTYPE={2}", LibStringBuilder.GetQuotString(userId), LibStringBuilder.GetQuotString(clientId), clientType);
                }
                else
                {
                    int curMaxRowId = LibSysUtils.ToInt32(dataAccess.ExecuteScalar(string.Format("SELECT Max(ROW_ID) from AXPUSERAPP WHERE USERID='{0}'", userId)));
                    //插入账户对应的App设备标识信息。
                    appSql = string.Format("insert into AXPUSERAPP(USERID,ROW_ID,ROWNO,CLIENTTYPE,CLIENTID) values('{0}',{1},{2},{3},'{4}')",
                                           userId, curMaxRowId + 1, curMaxRowId + 1, clientType, clientId, 1);
                }
                dataAccess.ExecuteNonQuery(appSql);

                #endregion

                LibHandle handle = LibHandleCache.Default.IsExistsHandle(LibHandeleType.PC, userId);
                if (handle != null)
                {
                    if (quitOther)
                    {
                        LibHandleCache.Default.RemoveHandle(handle.Handle);
                    }
                    else
                    {
                        loginInfo.IsUsed = true;
                    }
                }
                if (!loginInfo.IsUsed)
                {
                    long currentCount = LibHandleCache.Default.GetCount();
                    long maxUserCount = (long)LibHandleCache.Default.MaxUserCount;
                    if (maxUserCount != -1 && maxUserCount < currentCount)
                    {
                        loginInfo.IsOverUser = true;
                    }
                    else
                    {
                        string loginIp = string.Empty;
                        //Zhangkj20161219 增加LoginIp
                        System.ServiceModel.OperationContext context = System.ServiceModel.OperationContext.Current;
                        //对于非WCF的访问context为null
                        if (context != null)
                        {
                            System.ServiceModel.Channels.MessageProperties             properties = context.IncomingMessageProperties;
                            System.ServiceModel.Channels.RemoteEndpointMessageProperty endpoint   = properties[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty;
                            loginIp = endpoint.Address + ":" + endpoint.Port.ToString();
                            handle  = LibHandleCache.Default.GetHandle(string.Empty, LibHandeleType.PC, userId, loginInfo.PersonId, loginInfo.PersonName, roleId, loginIp);
                        }
                        else
                        {
                            handle = LibHandleCache.Default.GetHandle(string.Empty, LibHandeleType.PC, userId, loginInfo.PersonId, loginInfo.PersonName, roleId);
                        }
                        //创建新的Handle

                        if (handle != null)
                        {
                            loginInfo.Handle = handle.Handle;
                        }
                    }
                }
            }
            return(loginInfo);
        }