Exemple #1
0
        /// <summary>
        /// 3:验证失效。4:没有权限
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public int CheckUserAuth(string token)
        {
            ISqlMapper mapper = Common.GetMapperFromSession();
            //验证有没有登录
            UserEntireInfo user = GetUserEntireInfoFromCache(token);

            if (user == null)
            {
                return(3);
            }
            LogonHistoryDao logonhistorydao = new LogonHistoryDao(mapper);
            var             logonList       = logonhistorydao.Query(new LogonHistoryQueryForm {
                Token = token
            });

            //登录超时
            if (logonList.Count == 0 || DateTime.Now - logonList[0].ActiveTime > new TimeSpan(0, 30, 0))
            {
                return(3);
            }
            logonhistorydao.Update(new LogonHistoryUpdateForm
            {
                Entity = new LogonHistory {
                    ActiveTime = DateTime.Now
                },
                LogonHistoryQueryForm = new LogonHistoryQueryForm {
                    Token = token
                },
            });
            if (ServiceSession.Current != null)
            {
                return(CheckAuth(user.Role));
            }
            return(-1);
        }
Exemple #2
0
        public void LogonTest()
        {
            LogonBLL bll     = new LogonBLL();
            var      result  = bll.Logon(initU.Name, initU.Password);
            var      history = historydao.Query(new LogonHistoryQueryForm {
                UserID = initU.ID
            });

            Assert.IsNotNull(result.token);
            Assert.IsTrue(history.Count > 0);
            Assert.IsTrue(result.Menu.Count == 4);
            try
            {
                bll.Logon(initU.Name, "wrongpassword");
            }
            catch (Exception ex)
            {
                Assert.AreEqual("用户名或者密码错误!请输入正确的用户名和密码!", ex.Message);
            }
        }
Exemple #3
0
        public UserEntireInfo GetCurrentUser(string token = null)
        {
            ISqlMapper mapper = Common.GetMapperFromSession();

            if (string.IsNullOrEmpty(token))
            {
                token = ServiceSession.Current.Context.Parameters["token"].ToString();
            }
            var u = GetUserEntireInfoFromCache(token);

            if (u == null)
            {
                MonitorCache.GetInstance().PushMessage(new CacheMessage {
                    Message = "user is null"
                }, SOAFramework.Library.CacheEnum.FormMonitor);
                UserDao         userdao      = new UserDao(mapper);
                RoleDao         roledao      = new RoleDao(mapper);
                UserInfoDao     uidao        = new UserInfoDao(mapper);
                LogonHistoryDao lhdao        = new LogonHistoryDao(mapper);
                var             logonhistory = lhdao.Query(new LogonHistoryQueryForm {
                    Token = token
                }).FirstOrDefault();
                string userid = logonhistory.UserID;
                var    user   = userdao.Query(new UserQueryForm {
                    ID = userid
                }).FirstOrDefault();
                var userinfo = uidao.Query(new UserInfoQueryForm {
                    ID = userid
                }).FirstOrDefault();
                var roles = roledao.QueryRoleByUserID(userid);
                u = new UserEntireInfo
                {
                    User     = user,
                    Role     = roles,
                    UserInfo = userinfo,
                };
            }
            return(u);
        }
Exemple #4
0
 public UserEntireInfo GetCurrentUser(string token = null)
 {
     ISqlMapper mapper = MapperHelper.GetMapper();
     if (string.IsNullOrEmpty(token)) token = ServiceSession.Current.Context.Parameters["token"].ToString();
     var u = GetUserEntireInfoFromCache(token);
     if (u == null)
     {
         MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "user is null" }, SOAFramework.Library.CacheEnum.FormMonitor);
         UserDao userdao = new UserDao(mapper);
         RoleDao roledao = new RoleDao(mapper);
         UserInfoDao uidao = new UserInfoDao(mapper);
         LogonHistoryDao lhdao = new LogonHistoryDao(mapper);
         var logonhistory = lhdao.Query(new LogonHistoryQueryForm { Token = token }).FirstOrDefault();
         if (logonhistory == null) throw new Exception("获取当前用户信息时发生错误,用户不存在");
         string userid = logonhistory.UserID;
         var user = userdao.Query(new UserQueryForm { ID = userid }).FirstOrDefault();
         var userinfo = uidao.Query(new UserInfoQueryForm { ID = userid }).FirstOrDefault();
         var roles = roledao.QueryRoleByUserID(userid);
         u = new UserEntireInfo
         {
             User = user,
             Role = roles,
             UserInfo = userinfo,
         };
     }
     return u;
 }
Exemple #5
0
        public int CheckUserAuth(string token)
        {
            ISqlMapper mapper = MapperHelper.GetMapper();
            //验证有没有登录
            UserEntireInfo user = GetUserEntireInfoFromCache(token);

            //MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "check token:" + token }, SOAFramework.Library.CacheEnum.FormMonitor);
            if (user == null) return 3;
            LogonHistoryDao logonhistorydao = new LogonHistoryDao(mapper);
            var logonList = logonhistorydao.Query(new LogonHistoryQueryForm { Token = token });
            //登录超时
            if (logonList.Count == 0 || DateTime.Now - logonList[0].ActiveTime > new TimeSpan(0, 30, 0)) return 3;
            logonhistorydao.Update(new LogonHistoryUpdateForm
            {
                Entity = new LogonHistory { ActiveTime = DateTime.Now },
                LogonHistoryQueryForm = new LogonHistoryQueryForm { ID = logonList[0].ID },
            });
            if (ServiceSession.Current != null) return CheckAuth(user.Role);
            return -1;
        }
Exemple #6
0
 /// <summary>
 /// 3:验证失效。4:没有权限
 /// </summary>
 /// <param name="token"></param>
 /// <returns></returns>
 public int CheckUserAuth(string token)
 {
     ISqlMapper mapper = Common.GetMapperFromSession();
     //验证有没有登录
     UserEntireInfo user = GetUserEntireInfoFromCache(token);
     if (user == null) return 3;
     LogonHistoryDao logonhistorydao = new LogonHistoryDao(mapper);
     var logonList = logonhistorydao.Query(new LogonHistoryQueryForm { Token = token });
     //登录超时
     if (logonList.Count == 0 || DateTime.Now - logonList[0].ActiveTime > new TimeSpan(0, 30, 0)) return 3;
     logonhistorydao.Update(new LogonHistoryUpdateForm
     {
         Entity = new LogonHistory { ActiveTime = DateTime.Now },
         LogonHistoryQueryForm = new LogonHistoryQueryForm { Token = token },
     });
     if (ServiceSession.Current != null) return CheckAuth(user.Role);
     return -1;
 }