Ejemplo n.º 1
0
 public CommonBase()
 {
     CnnString = ConfigHelper.Read("ConnString");
     IsDebug   = ConfigHelper.Read("debug") == "1" ? true : false;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取权限
        /// </summary>
        /// <param name="token"></param>
        /// <param name="ts"></param>
        /// <returns></returns>
        protected TKS_FAS_PermissionInfo GetPermission(string token, IDbTransaction ts)
        {
            #region timeout
            string sql = "select * from tks_fas_token where token=@Token";

            var tokens = cnn.Query <TKS_FAS_Token>(sql, new { Token = token }, ts).ToList();

            if (tokens.Count() == 0)
            {
                //System.Web.HttpContext.Current.Session.Clear();
                //System.Web.HttpContext.Current.Response.Write("~/Login.aspx");
                throw new AppException("", "UserInfoGet", "登陆超时,请重新登陆", "登陆超时,请重新登陆");
            }
            TKS_FAS_Token curToken = tokens[0];
            DateTime      now      = DateTime.Now;

            var interval = now - DateTime.Parse(curToken.ActiveTime.ToString());
            var sec      = interval.TotalSeconds;
            var timeOut  = double.Parse(ConfigHelper.Read("timeOut"));
            if (timeOut < sec)
            {
                //System.Web.HttpContext.Current.Session.Clear();
                //System.Web.HttpContext.Current.Response.Write("~/Login.aspx");
                throw new AppException("", "UserInfoGet", "登陆超时,请重新登陆", "token 超时" + sec + "秒");
            }

            sql = @"update tks_fas_token set ActiveTime=@ActiveTime where token=@Token";
            cnn.Execute(sql, new { ActiveTime = DateTime.Now, Token = token }, ts);

            #endregion
            var user = cnn.Query <TKS_FAS_User>("select * from tks_fas_user where id=@UserId",
                                                new { UserId = curToken.UserId }, ts).ToList();
            if (user.Count == 0)
            {
                throw new AppException(curToken.UserId, "UserInfoGet",
                                       "用户信息异常,请联系管理员", "当前token没有对应的用户信息" + curToken.UserId);
            }
            var node = cnn.Query <TKS_FAS_Node>(@"select A.* from tks_fas_node A left 
                    join tks_fas_user2Node B on A.id=B.nodeId where B.userid=@UserId",
                                                new { UserId = curToken.UserId }, ts).ToList();
            if (node.Count() > 1)
            {
                throw new AppException(curToken.UserId, "UserInfoGet",
                                       "用户的机构信息异常,请联系管理员", "用户属于多个机构");
            }
            var roles = cnn.Query <TKS_FAS_Role>(@"select A.* from TKS_FAS_Role A left join 
                            TKS_FAS_User2Role B on A.id=B.roleId where   B.userid=@UserId",
                                                 new { UserId = curToken.UserId }, ts).ToList();


            TKS_FAS_PermissionInfo res = new TKS_FAS_PermissionInfo();
            if (roles.Count > 0)
            {
                string where = "(";
                foreach (var item in roles)
                {
                    if (where == "(")
                    {
                        where += "'" + item.Id + "'";
                    }
                    else
                    {
                        where += ",'" + item.Id + "'";
                    }
                }
                where += ")";
                sql    = string.Format(@"select Permission,PLevel from TKS_FAS_Role2Permission where RoleId in{0} order by PLevel", where);
                var Permission = cnn.Query <TKS_FAS_PermissionInfo>(sql,
                                                                    null, ts).Distinct().ToList();
                if (Permission.Count > 0)
                {
                    res = Permission[0];
                }
                else
                {
                    res = null;
                }
            }
            return(res);
        }
Ejemplo n.º 3
0
        protected MM_UserInfo UserInfoGet(string token, IDbTransaction ts)
        {
            #region timeout
            string sql = "select * from tks_fas_token where token=@Token";

            var tokens = cnn.Query <TKS_FAS_Token>(sql, new { Token = token }, ts).ToList();

            if (tokens.Count() == 0)
            {
                //System.Web.HttpContext.Current.Session.Clear();
                //System.Web.HttpContext.Current.Response.Write("~/Login.aspx");
                throw new AppException("", "UserInfoGet", "登陆超时,请重新登陆", "登陆超时,请重新登陆");
            }
            TKS_FAS_Token curToken = tokens[0];
            DateTime      now      = DateTime.Now;

            var interval = now - DateTime.Parse(curToken.ActiveTime.ToString());
            var sec      = interval.TotalSeconds;
            var timeOut  = double.Parse(ConfigHelper.Read("timeOut"));
            if (timeOut < sec)
            {
                //System.Web.HttpContext.Current.Session.Clear();
                //System.Web.HttpContext.Current.Response.Write("~/Login.aspx");
                throw new AppException("", "UserInfoGet", "登陆超时,请重新登陆", "token 超时" + sec + "秒");
            }

            sql = @"update tks_fas_token set ActiveTime=@ActiveTime where token=@Token";
            cnn.Execute(sql, new { ActiveTime = DateTime.Now, Token = token }, ts);

            #endregion

            var user = cnn.Query <TKS_FAS_User>("select * from tks_fas_user where id=@UserId",
                                                new { UserId = curToken.UserId }, ts).ToList();

            var node = cnn.Query <TKS_FAS_Node>(@"select A.* from tks_fas_node A left 
                    join tks_fas_user2Node B on A.id=B.nodeId where B.userid=@UserId",
                                                new { UserId = curToken.UserId }, ts).ToList();
            if (node.Count() > 1)
            {
                throw new AppException(curToken.UserId, "UserInfoGet",
                                       "用户的机构信息异常,请联系管理员", "用户属于多个机构");
            }

            var roles = cnn.Query <TKS_FAS_Role>(@"select A.* from TKS_FAS_Role A left join 
                            TKS_FAS_User2Role B on A.id=B.roleId where   B.userid=@UserId",
                                                 new { UserId = curToken.UserId }, ts).ToList();

            var currentAccount = cnn.Query <TKS_FAS_UserCurrentAccount>(
                @"select * from TKS_FAS_UserCurrentAccount where userId=@UserId",
                new { UserId = curToken.UserId }, ts).ToList();
            MM_UserInfo res = new MM_UserInfo();
            if (currentAccount.Count() == 0)
            {
                //update by Hero.Zhang
                //throw new AppException(curToken.UserId,"","请选择账套", "请选择账套");
            }
            else
            {
                res.AccountId = currentAccount[0].AccountId;
            }


            res.User  = user[0];
            res.Node  = node.Count > 0 ? node[0] : null;
            res.Roles = roles;
            return(res);
        }