Esempio n. 1
0
        protected void submit_Click(object sender, EventArgs e)
        {
            string usId = this.name.Text.Trim();
            string pswd = this.password.Text.Trim();

            if (string.IsNullOrEmpty(usId))
            {
                ShowErrorMsg("登录失败,用户名不能为空!");
                return;
            }

            if (string.IsNullOrEmpty(pswd))
            {
                ShowErrorMsg("登录失败,密码不能为空!");
                return;
            }

            Session.Clear();

            Response.Cookies["webfwu"].Value = usId;
            Response.Cookies["webfwu"].Expires = DateTime.Now.AddMonths(2);

            if (this.remember.Checked)
            {
                Response.Cookies["webfwp"].Value = pswd;
                Response.Cookies["webfwp"].Expires = DateTime.Now.AddMonths(2);
            }
            else
            {
                Response.Cookies["webfwp"].Value = "";
            }

            var uiBiz = new BcUserInfoBiz();
            var result = uiBiz.DoLogin(usId, pswd);
            switch (result)
            {
                case LoginStatusEnum.Success:
                    FormsAuthentication.SetAuthCookie(usId, false);
                    //登陆成功,把用户编号保存到票据中
                    var ticket = new FormsAuthenticationTicket(1, usId, DateTime.Now, DateTime.Now.AddMonths(2), false, usId, FormsAuthentication.FormsCookiePath);
                    var encTicket = FormsAuthentication.Encrypt(ticket);
                    var newCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
                    HttpContext.Current.Response.Cookies.Add(newCookie);
                    //登陆成功,跳转到首页
                    Response.Redirect(ReturnUrl);
                    break;
                case LoginStatusEnum.PasswordError:
                    ShowErrorMsg("登录失败,密码错误!");
                    break;
                case LoginStatusEnum.UserNotExist:
                    ShowErrorMsg("登录失败,用户名不存在!");
                    break;
                case LoginStatusEnum.UserDisabled:
                    ShowErrorMsg("登录失败,用户被禁用!");
                    break;
                default:
                    ShowErrorMsg("登录失败,请重试!");
                    break;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="permissionType">1=��ɫȨ�ޣ�2=�û�Ȩ��</param>
        /// <param name="userRoleId"></param>
        public List<BcPermissionEntity> GetEnabledBcPermissionList(int? permissionType, int? userRoleId = 0)
        {
            //��ȡ���õ�Ȩ���б�
            var allBcPermissionList = EntityExecution.ReadEntityList2<BcPermissionEntity>(null);
            var enabledBcPermissionList = new List<BcPermissionEntity>();
            if (userRoleId == 0)
            {
                enabledBcPermissionList.AddRange(allBcPermissionList.Where(n =>
                    n.PermissionType == permissionType));
            }
            else
            {
                enabledBcPermissionList.AddRange(allBcPermissionList.Where(n =>
                    n.UserRoleId == userRoleId && n.PermissionType == permissionType));
            }

            //���ؿ��õIJ˵��б�
            var listEnabledSysMenuEntity = new SysMenuBiz().GetEnabledSysMenuList();

            //���ݿ��õIJ˵��б��ȥ��û�������õĹ��ܵ�
            for (int i = enabledBcPermissionList.Count - 1; i >= 0; i--)
            {
                var permisionEntity = enabledBcPermissionList[i];
                var list = listEnabledSysMenuEntity.Where(n => n.ModuleId == permisionEntity.ModuleId && n.FuncPointId == permisionEntity.FuncPointId).ToList();
                if (list.Count <= 0) enabledBcPermissionList.Remove(permisionEntity);
            }

            //��������id��name
            var allBcRoleList = new BcRoleBiz().GetBcRoleList();
            var allBcUserInfoList = new BcUserInfoBiz().GetBcUserInfoList();

            foreach (BcPermissionEntity bcPermissionEntity in enabledBcPermissionList)
            {
                bcPermissionEntity.ModuleName = SysEnumNameExtensionBiz.GetDescription<SysModuleEnum>(bcPermissionEntity.ModuleId);
                bcPermissionEntity.FuncPointName = SysEnumNameExtensionBiz.GetDescription<SysFuncPointEnum>(bcPermissionEntity.FuncPointId);
                if (permissionType == 1)
                {
                    var list = allBcRoleList.Where(n => n.RoleId == bcPermissionEntity.UserRoleId).ToList();
                    if (list.Count > 0) bcPermissionEntity.UserRoleName = list[0].RoleName;
                }
                else if (permissionType == 2)
                {
                    var list = allBcUserInfoList.Where(n => n.UserId == bcPermissionEntity.UserRoleId).ToList();
                    if (list.Count > 0) bcPermissionEntity.UserRoleName = list[0].UserName;
                }

                if (!string.IsNullOrEmpty(bcPermissionEntity.Permissions))
                {
                    bcPermissionEntity.PermissionList = new List<string>();
                    bcPermissionEntity.PermissionNameList = new List<string>();
                    var list = bcPermissionEntity.Permissions.Split(',').ToList();
                    foreach (string s in list)
                    {
                        if (!string.IsNullOrEmpty(s))
                        {
                            bcPermissionEntity.PermissionList.Add(s);
                            bcPermissionEntity.PermissionNameList.Add(SysEnumNameExtensionBiz.GetDescription<SysFuncPointEnum>(s));
                        }
                    }
                    if (bcPermissionEntity.PermissionNameList.Count > 0)
                        bcPermissionEntity.PermissionNames = string.Join(",", bcPermissionEntity.PermissionNameList.ToArray());
                }
            }
            return enabledBcPermissionList.OrderBy(n => n.ModuleId).ThenBy(n => n.FuncPointId).ToList();
        }
Esempio n. 3
0
        protected void Application_Error(object sender, EventArgs e)
        {
            string errorLogPath = Server.MapPath("/TempFile/ErrorLogPath");
            string errorPage = "/CustomPage/error.html";
            Exception ex = null;
            try
            {
                ex = Server.GetLastError().GetBaseException();

                var sysSettingEntity = new SysGlobalSettingBiz().GetSysSettingEntity();
                errorLogPath = Server.MapPath(sysSettingEntity.ErrorLogPath);
                errorPage = sysSettingEntity.ErrorPage;

                BcUserInfoEntity userInfo = null;
                var identity = HttpContext.Current.User.Identity as FormsIdentity;
                if (identity != null) userInfo = new BcUserInfoBiz().GetBcUserInfoWithPermission(identity.Ticket.UserData);

                var entity = new BcLogErrorEntity();
                if (userInfo != null)
                {
                    entity.UserId = userInfo.UserId;
                    entity.UserName = userInfo.UserName;
                }
                else
                {
                    entity.UserId = 0;
                    entity.UserName = "";
                }
                entity.OpUrl = Request.Url.ToString();
                entity.OpTime = DateTime.Now;
                entity.OpHostAddress = Request.UserHostAddress;
                entity.OpHostName = Request.UserHostName;
                entity.OpUserAgent = Request.UserAgent;
                entity.OpQueryString = Request.QueryString.ToString();
                entity.OpHttpMethod = Request.HttpMethod;
                entity.Message = ex.ToString();

                try
                {
                    new BcLogErrorBiz().AddNewBcLogError(entity);
                }
                catch (Exception ex2)
                {
                    WriteLocalLog(errorLogPath, ex.ToString());
                    WriteLocalLog(errorLogPath, ex2.ToString());
                }

            }
            catch (Exception ex3)
            {
                if (ex != null) WriteLocalLog(errorLogPath, ex.ToString());
                WriteLocalLog(errorLogPath, ex3.ToString());
            }
            finally
            {
                if (!ConfigHelper.GetConfigBool("IsDevelopMode"))
                {
                    Server.ClearError();
                    Response.Redirect(errorPage);
                }
            }
        }