Example #1
0
 /// <summary>
 /// 取用户的名字
 /// </summary>
 /// <param name="id"></param>
 internal static string GetUserName(int id)
 {
     using (var proxy = new RedisProxy(RedisProxy.DbSystem))
     {
         return(proxy.Get(DataKeyBuilder.ToKey("user", "name", id))?.Trim('"'));
     }
 }
Example #2
0
 /// <summary>
 /// 取用户的名字
 /// </summary>
 /// <param name="uid"></param>
 static int GetDepartmentId(int uid)
 {
     using (var proxy = new RedisProxy(RedisProxy.DbSystem))
     {
         return(proxy.GetValue <int>(DataKeyBuilder.ToKey("user", "depid", uid)));
     }
 }
Example #3
0
 /// <summary>
 ///     载入角色菜单
 /// </summary>
 public static List <EasyUiTreeNode> LoadRoleMenu()
 {
     using (var proxy = new RedisProxy(RedisProxy.DbSystem))
     {
         return(proxy.Get <List <EasyUiTreeNode> >(DataKeyBuilder.ToKey("auth", "menu", 0)) ?? CreateMenu(proxy));
     }
 }
Example #4
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userHostAddress"></param>
        /// <param name="userName">用户名</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public static Guid WebLogin(string userHostAddress, string userName, string pwd)
        {
            Guid token;

            using (var proxy = new RedisProxy(RedisProxy.DbAuthority))
            {
                var tk = DataKeyBuilder.ToKey("login", userName, "token");
                token = proxy.GetValue <Guid>(tk);
                if (token == Guid.Empty)
                {
                    token = Guid.NewGuid();
                    proxy.SetValue(tk, token);
                }
                proxy.Set(DataKeyBuilder.ToKey("login", token), new LoginToken
                {
                    UserId        = 1,
                    Address       = userHostAddress == "::1" ? "127.0.0.1" : userHostAddress,
                    Token         = token,
                    LoginDateTime = DateTime.Now,
                    LastDateTime  = DateTime.Now,
                    TimeOut       = DateTime.Now.AddMinutes(30)
                });
            }
            BusinessContext.Current.Tooken = token;
            BusinessContext.Current.PowerChecker.ReloadLoginUserInfo(token);
            return(token);
        }
 /// <summary>
 ///     保存用户的查询历史
 /// </summary>
 /// <param name="userId">用户</param>
 /// <param name="pageId">关联页面</param>
 /// <param name="args">查询参数</param>
 public static void SaveQueryHistory(long userId, long pageId, Dictionary <string, string> args)
 {
     if (userId == 0 || pageId == 0)
     {
         return;
     }
     using (var proxy = new RedisProxy(RedisProxy.DbSystem))
     {
         var key = DataKeyBuilder.ToKey("qh", pageId, userId);
         proxy.Set(key, JsonConvert.SerializeObject(args));
     }
     //PageDataDataAccess pdAccess = new PageDataDataAccess();
     //if (pdAccess.Any(p => p.UserId == loginUser.Id && p.PageId == page.Id))
     //{
     //    pdAccess.SetValue(p => p.PageData, JsonConvert.SerializeObject(args),
     //        p => p.UserId == loginUser.Id && p.PageId == page.Id);
     //}
     //else
     //{
     //    pdAccess.Insert(new PageDataData
     //    {
     //        PageId = page.Id,
     //        UserId = loginUser.Id,
     //        PageData = JsonConvert.SerializeObject(args)
     //    });
     //}
 }
 /// <summary>
 ///     读取用户的查询历史
 /// </summary>
 /// <param name="userId">用户</param>
 /// <param name="pageId">关联页面</param>
 /// <returns>返回的是参数字典的JSON格式的文本</returns>
 public static string LoadQueryHistory(long userId, long pageId)
 {
     if (userId == 0 || pageId == 0)
     {
         return("{'page': 0,'order':'asc','size':20}");
     }
     using (var proxy = new RedisProxy(RedisProxy.DbSystem))
     {
         var key = DataKeyBuilder.ToKey("qh", pageId, userId);
         return(proxy.Get(key) ?? "{'page': 0,'order':'asc','size':20}");
     }
     //PageDataDataAccess pdAccess = new PageDataDataAccess();
     //return pdAccess.LoadValue(p => p.PageData, p => p.PageId == page.ID && p.UserId == loginUser.Id);
 }
Example #7
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userHostAddress"></param>
        /// <param name="userName">用户名</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public static Guid WebLogin(string userHostAddress, string userName, string pwd)
        {
            if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(pwd))
            {
                LogRecorder.RecordLoginLog($@"用户名({userName})或密码{pwd}为空,来自{userHostAddress}");
                return(Guid.Empty);
            }
            Guid token;
            int  uid;

            using (var proxy = new RedisProxy(RedisProxy.DbSystem))
            {
                var pwd2 = proxy.Get(DataKeyBuilder.ToKey("user", userName, "pwd"));
                if (pwd2 == null || !string.Equals(pwd, pwd2))
                {
                    LogRecorder.RecordLoginLog($@"{userName}密码不对{pwd2}-[测试]{pwd},来自{userHostAddress}");
                    return(Guid.Empty);
                }
                uid = proxy.GetValue <int>(DataKeyBuilder.ToKey("user", userName, "id"));
                if (uid == 0)
                {
                    LogRecorder.RecordLoginLog($@"{userName}用户不存在,来自{userHostAddress}");
                    return(Guid.Empty);
                }
            }
            using (var proxy = new RedisProxy(RedisProxy.DbAuthority))
            {
                var tk = DataKeyBuilder.ToKey("login", userName, "token");
                token = proxy.GetValue <Guid>(tk);
                if (token == Guid.Empty)
                {
                    token = Guid.NewGuid();
                    proxy.SetValue(tk, token);
                }
                proxy.Set(DataKeyBuilder.ToKey("login", token), new LoginToken
                {
                    UserId        = uid,
                    Address       = userHostAddress == "::1" ? "127.0.0.1" : userHostAddress,
                    Token         = token,
                    LoginDateTime = DateTime.Now,
                    LastDateTime  = DateTime.Now,
                    TimeOut       = DateTime.Now.AddMinutes(30)
                });
            }
            BusinessContext.Current.Tooken = token;
            BusinessContext.Current.PowerChecker.ReloadLoginUserInfo(token);
            return(token);
        }
Example #8
0
 /// <summary>
 ///     载入用户
 /// </summary>
 /// <returns></returns>
 public static bool Logout(string userHostAddress, Guid token)
 {
     using (var proxy = new RedisProxy(RedisProxy.DbAuthority))
     {
         var ik   = DataKeyBuilder.ToKey("login", token);
         var info = proxy.Get(ik);
         if (info == null)
         {
             return(true);
         }
         var strs = info.Split(',');
         var ip   = strs[1];
         if (ip != userHostAddress)
         {
             return(false);
         }
         proxy.Client.Remove(ik);
     }
     return(true);
 }
Example #9
0
 private static int CheckToken(string userHostAddress, Guid token)
 {
     using (var proxy = new RedisProxy(RedisProxy.DbAuthority))
     {
         var ik   = DataKeyBuilder.ToKey("login", token);
         var info = proxy.TryGet <LoginToken>(ik);
         if (info == null || info.TimeOut <= DateTime.Now)
         {
             LogRecorder.RecordLoginLog("令牌{0}过期", token);
             return(0);
         }
         if (info.Address != userHostAddress)
         {
             LogRecorder.RecordLoginLog("IP【{0}】-【{1}】不相同", userHostAddress, info.Address);
         }
         info.TimeOut      = DateTime.Now.AddMinutes(30);
         info.LastDateTime = DateTime.Now;
         proxy.Set(ik, info);
         return(info.UserId);
     }
 }
Example #10
0
        /// <summary>
        ///     生成角色菜单
        /// </summary>
        static List <EasyUiTreeNode> CreateMenu(RedisProxy proxy)
        {
            var root = new EasyUiTreeNode
            {
                ID       = 0,
                IsOpen   = true,
                Text     = ConfigurationManager.AppSettings["ProjectName"],
                IsFolder = true
            };
            var access = new PageItemDataAccess();
            var pages  = access.All(p => p.ItemType <= PageItemType.Page);

            foreach (var folder in pages.Where(p => p.ItemType == PageItemType.Root).OrderBy(p => p.Index))
            {
                var node = new EasyUiTreeNode
                {
                    IsOpen     = true,
                    Text       = folder.Caption,
                    Icon       = "icon-item",
                    Attributes = "home.aspx",
                    Tag        = folder.ExtendValue,
                    IsFolder   = true
                };
                foreach (var page in pages.Where(p => p.ParentId == folder.Id && p.ItemType <= PageItemType.Page).OrderBy(p => p.Index))
                {
                    CreateRoleMenu(node, pages, page);
                }
                if (node.HaseChildren)
                {
                    root.Children.Add(node);
                }
            }
            var result = root.Children.OrderByDescending(p => p.ID).ToList( );

            proxy.Set(DataKeyBuilder.ToKey("auth", "menu", 0), result);
            return(result);
        }
Example #11
0
 /// <summary>
 /// 生成用户相关的数据键
 /// </summary>
 /// <param name="args"></param>
 /// <returns></returns>
 public static string BuildDataKey(params object[] args)
 {
     return(DataKeyBuilder.ToKey("user", args));
 }