示例#1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public OnLineTest.Model.Users GetModel(string UserName)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 UserId,UserName,UserPassword,UserChineseName,UserImageName,UserEmail,IsValidate,Tel,UserScore,UserRegisterDatetime,UserGroupId from Users ");
            if (System.Text.RegularExpressions.Regex.IsMatch(UserName, "^[a-z]([a-z0-9]*[-_]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\\.][a-z]{2,3}([\\.][a-z]{2})?$", System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace))
            {
                strSql.Append(" where UserEmail=@UserName");
            }
            else
            {
                strSql.Append(" where UserName=@UserName ");
            }
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserName", SqlDbType.VarChar, 20)
            };
            parameters[0].Value = UserName;

            OnLineTest.Model.Users model = new OnLineTest.Model.Users();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
示例#2
0
        /// <summary>
        /// 对于特定的网页,用户是否被授权访问
        /// </summary>
        /// <param name="user">用户实例</param>
        /// <param name="requestFileName">要访问的网页,且是存在授权要求的</param>
        /// <returns>要求授权的网页,用户没有得到授权返回false,否则返回true</returns>
        public static bool isAuthorized(OnLineTest.Model.Users user, string requestFileName)
        {
            log4net.ILog     logger           = log4net.LogManager.GetLogger(typeof(common));
            bool             isauthorized     = true;
            UserGroupManager usergroupmanager = new UserGroupManager();

            if (((UserGroup)usergroupmanager.GetModel(user.UserGroupId)).UserGroupName.Trim() != "超级管理员")
            {
                UserAuthorityManager userauthoritymanager = new UserAuthorityManager();
                AuthorityManager     authoritymanager     = new AuthorityManager();
                try
                {
                    Authority authority = new Authority();
                    if (HttpRuntime.Cache[requestFileName] != null)
                    {
                        authority = (Authority)HttpRuntime.Cache[requestFileName];
                    }
                    else
                    {
                        authority = authoritymanager.GetModel(requestFileName);
                        if (authority != null)
                        {
                            HttpRuntime.Cache.Insert(requestFileName, authority, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero);
                            logger.Info(requestFileName + "处理网页,对应的权限缓存成功。");
                        }
                    }
                    if (authority != null)
                    {
                        isauthorized = userauthoritymanager.Exists(user, authoritymanager.GetModel(requestFileName));
                        //if (isauthorized)
                        //{
                        //    authority.AuthorityClickNum += 1;
                        //    authoritymanager.Update(authority);
                        //}
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("查询网页授权过程出错。", ex);
                    ServerTransfer("error.aspx", 1005, ex, string.Empty);
                }
            }
            return(isauthorized);
        }
示例#3
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(OnLineTest.Model.Users model)
 {
     return(dal.Update(model));
 }
示例#4
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int  Add(OnLineTest.Model.Users model)
 {
     return(dal.Add(model));
 }