Esempio n. 1
0
        internal static bool SelectAuthToSession(string sessionId, LogicSession lgcSession)
        {
            Auth auth = AuthUtils.SelectAuth(sessionId);
            bool flag = auth == null;
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                lgcSession.UserId          = auth.UserId;
                lgcSession.UserName        = auth.UserName;
                lgcSession.LoginTime       = auth.LoginTime;
                lgcSession.LoginType       = auth.LoginType;
                lgcSession.ClientIp        = auth.ClientIp;
                lgcSession.ClientName      = auth.ClientName;
                lgcSession.DbId            = auth.DbId;
                lgcSession.LastRefreshTime = auth.LastRefresh;
                lgcSession.LastRequestTime = auth.LastRequest;
                lgcSession.UpdateTime      = auth.UpdateTime;
                lgcSession.ExInfo          = auth.ExInfo;
                lgcSession.AuthSession     = auth;
                result = true;
            }
            return(result);
        }
Esempio n. 2
0
        internal static void LogicSessionUpdateFromAuthSessionTask()
        {
            bool flag = !AuthUtils.IsCheckAuthSession();

            if (!flag)
            {
                DateTime dateTime = AppRuntime.ServerDateTime.AddMinutes(-480.0);
                Database database = LogicContext.GetDatabase();
                HSQL     sql      = new HSQL(database);
                sql.Clear();
                sql.Raw = true;
                sql.Add("select AUTH_SESSIONID,AUTH_USERID,AUTH_LASTREFRESH,AUTH_LASTREQUEST");
                sql.Add("from AUTH");
                sql.Add("where AUTH_SESSIONID <> :AUTH_SESSIONID");
                sql.ParamByName("AUTH_SESSIONID").Value = "876978727978717673657871";
                DataSet dataSet = database.OpenDataSet(sql);
                for (int index = 0; index < dataSet.Tables[0].Rows.Count; index++)
                {
                    string sessionId = dataSet.Tables[0].Rows[index]["AUTH_SESSIONID"].ToString().Trim();
                    dataSet.Tables[0].Rows[index]["AUTH_USERID"].ToString().Trim();
                    bool flag2 = dataSet.Tables[0].Rows[index]["AUTH_LASTREQUEST"].ToString().ToDateTime() < dateTime;
                    if (flag2)
                    {
                        AuthUtils.DeleteAuth(sessionId);
                    }
                    else
                    {
                        AuthUtils.UpdateAuthLastRefresh(sessionId);
                    }
                    Thread.Sleep(100);
                }
            }
        }
Esempio n. 3
0
        private static bool IsCheckAuthSession()
        {
            DateTime lastRefreshTime;
            DateTime dbTime;
            bool     flag = !AuthUtils.GetUltIdLastRefreshTimeAndDbTime(out lastRefreshTime, out dbTime);

            if (flag)
            {
                AuthUtils.InsertUltSessionId();
            }
            return(lastRefreshTime.AddMinutes(55.0) < dbTime && AuthUtils.UpdateUltSessionIdLastRefreshTime());
        }
Esempio n. 4
0
        public static Auth GetAuth(string sessionId)
        {
            Auth      auth      = null;
            AuthCache authCache = (AuthCache) new AuthCache().GetData();
            int       index     = authCache.dvAuthBy_SessionId.Find(sessionId);
            bool      flag      = index >= 0;

            if (flag)
            {
                Auth auth2 = new Auth();
                auth = AuthUtils.GetObject(authCache.dvAuthBy_SessionId[index].Row);
            }
            return(auth);
        }
Esempio n. 5
0
        internal static void LogicSessionUpdateFromMemorySessionTask()
        {
            object lockObj = AuthUtils._lockObj;
            Dictionary <string, LogicSession> dictionary;

            lock (lockObj)
            {
                try
                {
                    dictionary = new Dictionary <string, LogicSession>(AuthUtils.GlobalLogicSession);
                }
                catch
                {
                    return;
                }
            }
            DateTime dateTime  = AppRuntime.ServerDateTime.AddMinutes(-480.0);
            DateTime dateTime2 = AppRuntime.ServerDateTime.AddMinutes(-5.0);

            foreach (KeyValuePair <string, LogicSession> keyValuePair in dictionary)
            {
                LogicSession logicSession = keyValuePair.Value;
                bool         ignore       = logicSession.Ignore;
                if (ignore)
                {
                    LogicSession obj = logicSession;
                    lock (obj)
                    {
                        bool flag3 = logicSession.LastRequestTime < dateTime2;
                        if (flag3)
                        {
                            AuthUtils.RemoveSession(logicSession.SessionId);
                        }
                    }
                }
                else
                {
                    LogicSession obj2 = logicSession;
                    lock (obj2)
                    {
                        bool flag5 = logicSession.LastRequestTime < dateTime;
                        if (flag5)
                        {
                            AuthUtils.RemoveSession(logicSession.SessionId);
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        public static bool Login(string userId, string password, string clientIp)
        {
            bool flag = string.IsNullOrEmpty(userId);
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                userId = userId.ToUpper();
                User user  = UserUtils.GetUser(userId);
                bool flag2 = user == null;
                if (flag2)
                {
                    throw new Exception("用户名或密码错误!");
                }
                bool disabled = user.Disabled;
                if (disabled)
                {
                    throw new Exception("当前用户名已被停用!");
                }
                bool flag3 = user.Password != PasswordSec.Encode(userId, password);
                if (flag3)
                {
                    throw new Exception("用户名或密码错误!");
                }
                LogicSession logicSession = AuthUtils.SignIn(userId, clientIp);
                bool         flag4        = logicSession != null;
                if (flag4)
                {
                    logicSession.UserName = user.UserName;
                    LogicContext current = LogicContext.Current;
                    bool         flag5   = current != null;
                    if (flag5)
                    {
                        current.SetLogicSession(logicSession);
                    }
                }
                result = true;
            }
            return(result);
        }
Esempio n. 7
0
        internal static LogicSession SignIn(string userId, string clientIp)
        {
            HttpContext  current      = HttpContext.Current;
            LogicSession logicSession = new LogicSession(userId, LogicSessionType.C);

            logicSession.DbId     = AppConfig.DefaultDbId;
            logicSession.ClientIp = clientIp;
            object lockObj = AuthUtils._lockObj;

            lock (lockObj)
            {
                bool flag2 = AuthUtils.GlobalLogicSession.ContainsKey(logicSession.SessionId);
                if (flag2)
                {
                    logicSession = null;
                }
                else
                {
                    AuthUtils.GlobalLogicSession.Add(logicSession.SessionId, logicSession);
                    AuthUtils.InsertAuth(new Auth
                    {
                        SessionId   = logicSession.SessionId,
                        UserId      = logicSession.UserId,
                        LoginTime   = logicSession.LastRequestTime,
                        LoginType   = logicSession.LoginType,
                        ClientIp    = logicSession.ClientIp,
                        ClientName  = logicSession.ClientIp,
                        DbId        = logicSession.DbId,
                        LastRefresh = logicSession.LastRefreshTime,
                        LastRequest = logicSession.LastRequestTime,
                        UpdateTime  = logicSession.UpdateTime,
                        ExInfo      = logicSession.ExInfo
                    });
                    current.Response.SetCookie(new HttpCookie("USERID", logicSession.UserId)
                    {
                        HttpOnly = false,
                        Path     = AppRuntime.AppVirtualPath
                    });
                }
            }
            return(logicSession);
        }
Esempio n. 8
0
        internal static void SignOut()
        {
            LogicContext current = LogicContext.Current;
            bool         flag    = current == null;

            if (!flag)
            {
                LogicSession userSession = current.UserSession;
                bool         flag2       = userSession != null;
                if (flag2)
                {
                    object lockObj = AuthUtils._lockObj;
                    lock (lockObj)
                    {
                        AuthUtils.GlobalLogicSession.Remove(userSession.SessionId);
                        userSession.Ignore = true;
                        AuthUtils.DeleteAuth(userSession.SessionId);
                    }
                }
            }
        }
Esempio n. 9
0
        internal static Auth SelectAuth(string sessionId)
        {
            Database database = LogicContext.GetDatabase();
            HSQL     sql      = new HSQL(database);

            sql.Add("select AUTH_SESSIONID,AUTH_USERID,USERS_USERNAME,AUTH_LOGINTIME,AUTH_LOGINTYPE,AUTH_CLIENTIP,AUTH_CLIENTNAME,AUTH_DBID");
            sql.Add(",AUTH_LASTREFRESH,AUTH_LASTREQUEST,AUTH_UPDATETIME,AUTH_EXINFO");
            sql.Add("from AUTH,USERS");
            sql.Add("where AUTH_SESSIONID=:AUTH_SESSIONID AND AUTH_USERID = USERS_USERID");
            sql.ParamByName("AUTH_SESSIONID").Value = sessionId;
            DataTable dataTable = database.OpenDataSet(sql).Tables[0];
            bool      flag      = dataTable.Rows.Count > 0;
            Auth      result;

            if (flag)
            {
                result = AuthUtils.GetObject(dataTable.Rows[0]);
            }
            else
            {
                result = null;
            }
            return(result);
        }
Esempio n. 10
0
 public static bool Logout()
 {
     AuthUtils.SignOut();
     return(true);
 }
Esempio n. 11
0
        public static LogicSession GetLogicSession(CookieMemory cookie)
        {
            string       sessionId    = cookie.SessionId;
            DateTime     updateTime   = cookie.UpdateTime;
            LogicSession logicSession = null;
            LogicSession lgcSession   = null;
            object       lockObj      = AuthUtils._lockObj;
            LogicSession result;

            lock (lockObj)
            {
                bool local_5_;
                do
                {
                    bool flag2 = !AuthUtils.GlobalLogicSession.TryGetValue(sessionId, out lgcSession);
                    if (flag2)
                    {
                        lgcSession = new LogicSession(sessionId);
                        AuthUtils.GlobalLogicSession[sessionId] = lgcSession;
                    }
                    local_5_ = Monitor.TryEnter(lgcSession);
                    bool flag3 = !local_5_;
                    if (flag3)
                    {
                        Thread.Sleep(0);
                    }
                }while (!local_5_);
                try
                {
                    DateTime local_6 = AppRuntime.ServerDateTime;
                    bool     flag4   = lgcSession.LoginType == LogicSessionType.N && !AuthUtils.SelectAuthToSession(sessionId, lgcSession);
                    if (flag4)
                    {
                        lgcSession.Ignore = true;
                        result            = null;
                        return(result);
                    }
                    bool flag5 = lgcSession.LastRequestTime < AppRuntime.ServerDateTime.AddMinutes(-480.0) && !AuthUtils.UpdateAuthLastRequest(sessionId, local_6);
                    if (flag5)
                    {
                        lgcSession.Ignore = true;
                        result            = null;
                        return(result);
                    }
                    bool flag6 = updateTime > lgcSession.UpdateTime && !AuthUtils.SelectAuthToSession(sessionId, lgcSession);
                    if (flag6)
                    {
                        lgcSession.Ignore = true;
                        result            = null;
                        return(result);
                    }
                    lgcSession.LastRequestTime = local_6;
                    logicSession = lgcSession;
                }
                finally
                {
                    Monitor.Exit(lgcSession);
                }
            }
            result = logicSession;
            return(result);
        }