示例#1
0
        /// <summary>
        /// 移除用户 Session
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static MResult RemoveUserCache(string uid, string token)
        {
            var result = new MResult();

            var memberObj = Factory.DALFactory.Member();

            if (memberObj != null)
            {
                var userInfo = new UserEntity();

                if (MCacheManager.GetCacheObj(MCaching.Provider.Redis).RemoveByKey(token, MCaching.CacheGroup.Member))
                {
                    result.status = MResultStatus.Success;
                }
                else
                {
                    result.status = MResultStatus.ExecutionError;
                    result.msg    = "[" + uid + "]移除用户缓存失败!";
                }
            }
            else
            {
                result.status = MResultStatus.ParamsError;
                result.msg    = "[" + uid + "]用户不存在!";
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// 初始化
        /// </summary>
        public static void Init()
        {
            var methodPermisstionList = ManageBLL.GetSystemPermissionList();

            if (methodPermisstionList.Any())
            {
                MCacheManager.GetCacheObj().Set("SystemPermission",
                                                MCaching.CacheGroup.Pemissions, methodPermisstionList);
            }
        }
示例#3
0
        /// <summary>
        /// 验证token
        /// </summary>
        /// <param name="uid"> </param>
        /// <param name="token"></param>
        /// <returns></returns>
        public MResult VerifyToKen(string uid, string token)
        {
            var result = new MResult();
            var cache  = MCacheManager.GetCacheObj(MCaching.Provider.Redis);

            if (cache.Contains(token, MCaching.CacheGroup.Member))
            {
                MemberBLL.UpdateUserCache(uid, token);
                result.status = MResultStatus.Success;
            }
            else
            {
                result.msg   += "请登录系统!";
                result.status = MResultStatus.LogicError;
            }
            return(result);
        }
示例#4
0
        /// <summary>
        /// 重新登录
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="uid"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static MResult ReLoginMember(string sid, string uid, string token)
        {
            var result = new MResult();

            try
            {
                var memberObj  = Factory.DALFactory.Member();
                var memberInfo = memberObj.GetMemberInfo(uid);
                var cache      = MCacheManager.GetCacheObj(MCaching.Provider.Redis);
                if (memberInfo != null && memberInfo.valid == 1)
                {
                    var uId = cache.GetValByKey <string>(token, MCaching.CacheGroup.Member);
                    if (uId != null && !string.IsNullOrEmpty(uId))
                    {
                        result = UpdateUserCache(uid, token);
                        if (result.status == MResultStatus.Success)
                        {
                            result.msg = "登录成功!";
                        }
                        else
                        {
                            result.data   = token;
                            result.status = MResultStatus.Success;
                            result.msg    = "用户名密码正确,缓存失败" + result.msg;
                        }
                    }
                    else
                    {
                        result.msg = "token 不存在,请重新登录";
                    }
                }
                else
                {
                    result.status = MResultStatus.ExecutionError;
                    result.msg    = "用户不存在!";
                }
            }
            catch (Exception ex)
            {
                MLogManager.Error(MLogGroup.Member.登陆, sid, "获取数据错误");
            }
            return(result);
        }
示例#5
0
        /// <summary>
        /// 更新用户 Session
        /// </summary>
        /// <param name="uid">用户 字符串id(此处邮箱) 如果是更新用户状态可以为空,如果是登录则必填</param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static MResult <int> UpdateUserCache(string uid, string token)
        {
            var result = new MResult <int>();

            try
            {
                var cache = MCacheManager.GetCacheObj(MCaching.Provider.Redis);
                if (cache.Contains(token, MCaching.CacheGroup.Member))
                {
                    uid = cache.GetValByKey <string>(token, MCaching.CacheGroup.Member);
                    cache.RemoveByKey(token, MCaching.CacheGroup.Member);
                }

                if (!string.IsNullOrEmpty(uid))
                {
                    if (cache.Set <string>(token, MCaching.CacheGroup.Member, uid, DateTime.Now.AddMinutes(30)))
                    {
                        result.status = MResultStatus.Success;
                        result.data   = token;
                    }
                    else
                    {
                        result.status = MResultStatus.ExecutionError;
                        result.msg    = "[" + uid + "]缓存用户状态失败!";
                    }
                }
                else
                {
                    result.status = MResultStatus.ExecutionError;
                    result.msg    = "缓存用户状态 uid 不能为空!";
                }
            }
            catch (Exception ex)
            {
                MLogManager.Error(MLogGroup.Member.登陆, null, "更新用户状态缓存失败!", ex);
            }
            return(result);
        }
示例#6
0
        /// <summary>
        /// 检查用户登录是否过期
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public static bool CheckUserState(string token)
        {
            var cache = MCacheManager.GetCacheObj(MCaching.Provider.Redis);

            return(cache.Contains(token, MCaching.CacheGroup.Member));
        }
示例#7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="invocation"></param>
        /// <returns></returns>
        public object Invoke(IMethodInvocation invocation)
        {
            var    shopWatch       = new Stopwatch();
            object result          = null;
            var    enableMethodLog = MConfigManager.GetAppSettingsValue <bool>("EnableMethodLog", false);

            try
            {
                shopWatch.Start();

                var resultType = invocation.Method.ReturnType;

                //{sid}/{token}/{guid}/{user_id}/{uid}
                var args = invocation.Arguments;
                for (var i = 0; i < args.Length; i++)
                {
                    args[i] = ValidateUtility.CheckNull(args[i]);
                }
                if (args.Length >= 5)
                {
                    var sid    = MCvHelper.To <string>(args[0]);
                    var token  = MCvHelper.To <string>(args[1]);
                    var guid   = MCvHelper.To <string>(args[2]);
                    var userID = MCvHelper.To <int>(args[3]);
                    var uid    = MCvHelper.To <string>(args[4]);

                    var methodName      = invocation.Method.Name;
                    var methodCacheList = MCacheManager.GetCacheObj().GetValByKey <List <ItemMethodVerify> >("SystemPermission", MCaching.CacheGroup.Pemissions);

                    if (methodCacheList != null && methodCacheList.Any())
                    {
                        var methodCacheInfo = methodCacheList.Find(item => item.MethodName.Equals(methodName, StringComparison.InvariantCultureIgnoreCase));

                        if (methodCacheInfo != null)
                        {
                            var isVerifySystemId    = methodCacheInfo.IsVerifySystemId;
                            var isVerifyToKen       = methodCacheInfo.IsVerifyToken;
                            var isVerifyPermissions = methodCacheInfo.IsVerfiyPemissions;

                            var secureAuth = new SecureAuth
                            {
                                IsVerifySystemId    = isVerifySystemId,
                                IsVerifyToKen       = isVerifyToKen,
                                IsVerifyPermissions = isVerifyPermissions,
                                Sid    = sid,
                                Token  = token,
                                Uid    = uid,
                                UserId = userID
                            };

                            if (secureAuth.Verify().status == MResultStatus.Success)
                            {
                                if (methodCacheInfo.IsEnableCache)
                                {
                                    var cacheKey = string.Format("{0}_{1}", methodName,
                                                                 string.Join("_", invocation.Arguments));



                                    result = MCacheManager.UseCached <dynamic>(cacheKey, MCaching.CacheGroup.Pemissions,
                                                                               () => invocation.Method.Invoke(invocation.This, args));
                                }
                                else
                                {
                                    result = invocation.Method.Invoke(invocation.This, args);
                                }
                            }
                            //result = invocation.Proceed();
                        }
                        else
                        {
                            result = invocation.Method.Invoke(invocation.This, args);
                        }
                    }
                    else
                    {
                        result = invocation.Method.Invoke(invocation.This, args);
                    }
                }
                if (result == null)
                {
                    result = Activator.CreateInstance(resultType);
                }
                return(result);
            }
            catch (Exception ex)
            {
                MLogManager.Error(MLogGroup.AopAdvice.方法拦截, "", "", ex);
            }
            finally
            {
                if (result == null)
                {
                    var resultType = invocation.Method.ReturnType;
                    result = Activator.CreateInstance(resultType);
                }
                if (enableMethodLog)
                {
                    shopWatch.Stop();
                    MLogManager.Info(MLogGroup.AopAdvice.方法拦截, "", "执行用时:{0}毫秒;请求信息:{1};返回信息:{2};",
                                     shopWatch.ElapsedMilliseconds,
                                     invocation.ToString(),
                                     JsonConvert.SerializeObject(result));
                }
            }
            return(result);
        }