コード例 #1
0
        /// <summary>
        /// 当前用户
        /// </summary>
        /// <returns></returns>
        public virtual OperatorEntity Current()
        {
            try
            {
                OperatorEntity user = new OperatorEntity();
                if (_loginProvider == "Cookie")
                {
                    user = DESEncryptHelper.Decrypt(CookieHelper.GetCookie(LoginUserKey).ToString()).JsonToEntity <OperatorEntity>();

                    #region 解决cookie时,设置数据权限较多时无法登陆的bug
                    AuthorizeDataModel dataAuthorize = CacheFactory.CacheFactory.GetCacheInstance().GetCache <AuthorizeDataModel>(LoginUserKey);
                    user.DataAuthorize = dataAuthorize;
                    #endregion
                }
                else
                {
                    user = DESEncryptHelper.Decrypt(SessionHelper.GetSession <string>(LoginUserKey).ToString()).JsonToEntity <OperatorEntity>();
                }
                return(user);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #2
0
        /// <summary>
        /// 是否已登录
        /// </summary>
        /// <returns></returns>
        public virtual int IsOnLine()
        {
            OperatorEntity user = new OperatorEntity();

            if (_loginProvider == "Cookie")
            {
                user = DESEncryptHelper.Decrypt(CookieHelper.GetCookie(LoginUserKey).ToString()).JsonToEntity <OperatorEntity>();

                #region 解决cookie时,设置数据权限较多时无法登陆的bug
                AuthorizeDataModel dataAuthorize = CacheFactory.CacheFactory.GetCacheInstance().GetCache <AuthorizeDataModel>(LoginUserKey);
                user.DataAuthorize = dataAuthorize;
                #endregion
            }
            else
            {
                user = DESEncryptHelper.Decrypt(SessionHelper.GetSession <string>(LoginUserKey).ToString()).JsonToEntity <OperatorEntity>();
            }
            object token = CacheFactory.CacheFactory.GetCacheInstance().GetCache <string>(user.UserId);
            if (token == null)
            {
                return(-1);//过期
            }
            if (user.Token == token.ToString())
            {
                return(1);//正常
            }
            else
            {
                return(0);//已登录
            }
        }
コード例 #3
0
        /// <summary>
        /// 写入登录信息
        /// </summary>
        /// <param name="user">成员信息</param>
        public virtual void AddCurrent(OperatorEntity user)
        {
            try
            {
                if (_loginProvider == "Cookie")
                {
                    #region 解决cookie时,设置数据权限较多时无法登陆的bug
                    CacheFactory.CacheFactory.GetCacheInstance().WriteCache(user.DataAuthorize, LoginUserKey, user.LoginTime.AddHours(12));
                    user.DataAuthorize = null;
                    #endregion

                    CookieHelper.WriteCookie(LoginUserKey, DESEncryptHelper.Encrypt(user.TryToJson()));
                }
                else
                {
                    SessionHelper.AddSession(LoginUserKey, DESEncryptHelper.Encrypt(user.TryToJson()));
                }
                CacheFactory.CacheFactory.GetCacheInstance().WriteCache(user.Token, user.UserId, user.LoginTime.AddHours(12));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }