Пример #1
0
        public override string[] GetAllRoles()
        {
            var bll  = new SiteRoles();
            var list = bll.GetList();

            return(list.Select(m => m.Named).ToArray());
        }
Пример #2
0
        private unsafe void __BindRole(ListControl __drp)
        {
            SiteRoles[] rolesArray;
            SiteRoles   roles;

            SiteRoles[] rolesArray2;
            int         num;
            bool        flag;

            __drp.Items.Clear();
            rolesArray = SiteRoles.List(SitePortal.GetCurrentPortalId());
            __drp.Items.Add(new ListItem("--请选择--", ""));
            rolesArray2 = rolesArray;
            num         = 0;
            goto Label_0066;
Label_003A:
            roles = rolesArray2[num];
            __drp.Items.Add(new ListItem(roles.RoleName, &roles.Id.ToString()));
            num += 1;
Label_0066:
            if ((num < ((int)rolesArray2.Length)) != null)
            {
                goto Label_003A;
            }
            return;
        }
Пример #3
0
 public ResResultModel GetMenusTreeGrid(MenusPermissionModel model)
 {
     try
     {
         var accessId         = Guid.Empty;
         var accessType       = "";
         var isAdministrators = false;
         if (!string.IsNullOrWhiteSpace(model.AllowRole))
         {
             accessType = "Roles";
             SiteRoles rBll     = new SiteRoles();
             var       roleInfo = rBll.GetAspnetModel(Membership.ApplicationName, model.AllowRole);
             accessId         = roleInfo.Id;
             isAdministrators = roleInfo.LowerName == "administrators";
         }
         if (!string.IsNullOrWhiteSpace(model.DenyUser))
         {
             accessType = "Users";
             accessId   = Guid.Parse(Membership.GetUser(model.DenyUser).ProviderUserKey.ToString());
         }
         var bll = new SiteMenus();
         return(ResResult.Response(true, "", bll.GetTreeGridJson(Membership.ApplicationName, accessId, accessType, isAdministrators)));
     }
     catch (Exception ex)
     {
         return(ResResult.Response(false, ex.Message, ""));
     }
 }
Пример #4
0
        public override bool RoleExists(string roleName)
        {
            var bll   = new SiteRoles();
            var model = bll.GetModel(roleName);

            return(model != null);
        }
Пример #5
0
        public override void CreateRole(string roleName)
        {
            var bll   = new SiteRoles();
            var appId = Guid.Parse(new Applications().GetApplicationId(ApplicationName).ToString());
            var model = new SiteRolesInfo(appId, Guid.Empty, roleName, roleName.ToLower(), DateTime.Now);

            bll.Insert(model);
        }
Пример #6
0
        public void SetMigrateAnonymous()
        {
            var userId = WebCommon.GetUserId();
            IList <SiteMenusInfo> smis = new List <SiteMenusInfo>();
            UserProfileInfo       upi  = new UserProfileInfo();
            var menuBll = new SiteMenus();

            if (Roles.GetRolesForUser().Length == 0)
            {
                var      guestRole = new SiteRoles().GetAspnetModel(Membership.ApplicationName, "guest");
                string[] accessIds = { guestRole.Id.ToString() };
                smis = menuBll.GetMenusAccess(Membership.ApplicationName, accessIds, false);
                upi  = new UserProfileInfo {
                    SiteCode = AppCode, SiteTitle = GlobalConfig.SiteTitle
                };
            }
            else
            {
                var accessIds = new List <string>();
                accessIds.Add(userId.ToString());
                var roleIds = new SiteRoles().GetAspnetRoleIds(Membership.ApplicationName, Roles.GetRolesForUser());
                foreach (var item in roleIds)
                {
                    accessIds.Add(item.ToString());
                }
                var    isAdmin = HttpContext.Current.User.IsInRole("Administrators");
                Task[] tasks   = new Task[2];
                tasks[0] = Task.Factory.StartNew(() =>
                {
                    var fuInfo = new FeatureUser().GetModel(userId, "UserProfile");
                    if (fuInfo != null)
                    {
                        upi.SiteCode    = fuInfo.SiteCode;
                        upi.SiteTitle   = fuInfo.SiteTitle;
                        upi.SiteLogo    = string.IsNullOrWhiteSpace(fuInfo.SiteLogo) ? "" : WebCommon.GetSiteAppName() + fuInfo.SiteLogo;
                        upi.CultureName = fuInfo.CultureName;
                    }
                });

                tasks[1] = Task.Factory.StartNew(() =>
                {
                    smis = menuBll.GetMenusAccess(Membership.ApplicationName, accessIds.ToArray(), isAdmin);
                });
                Task.WaitAll(tasks);
            }

            var Profile = new CustomProfileCommon();

            Profile.UserMenus = JsonConvert.SerializeObject(smis);
            Profile.UserInfo  = JsonConvert.SerializeObject(upi);

            Profile.Save();
        }
Пример #7
0
        private void __BindData()
        {
            SiteRoles[] rolesArray;
            ArrayList   list;

            rolesArray          = SiteRoles.List(SitePortal.GetCurrentPortalId());
            list                = PageUtil.GetPagedResult(rolesArray, this.PaginationBar1.PageIndex - 1, this.PaginationBar1.PageSize);
            this.rpt.DataSource = list;
            this.rpt.DataBind();
            this.PaginationBar1.RecordCount = (int)rolesArray.Length;
            this.PaginationBar1.Visible     = (((int)rolesArray.Length) < this.PaginationBar1.PageSize) == 0;
            return;
        }
Пример #8
0
        protected unsafe void btnAdd_Click(object sender, EventArgs e)
        {
            SiteRoles roles;
            SiteRoles roles2;
            int       num;
            string    str;

            string[] strArray;
            bool     flag;
            int      num2;

            if (PageUtil.CheckValid(this, new string[] { "txt_RoleName#请输入角色名称" }) != null)
            {
                goto Label_0025;
            }
            goto Label_0134;
Label_0025:
            if ((string.IsNullOrEmpty(this.txt_OrderId.Value) == 0) != null)
            {
                goto Label_005D;
            }
            this.txt_OrderId.Value = &SiteRoles.GetNextOrderID(SitePortal.GetCurrentPortalId()).ToString();
Label_005D:
            roles = SiteRoles.GetByName(SitePortal.GetCurrentPortalId(), this.txt_RoleName.Value);
            if (((roles == null) ? 1 : (roles.Id == this.nId)) != null)
            {
                goto Label_00B0;
            }
            PageUtil.WriteAlertAndFocus(this.Page, "该名称已存在,请检查!", this.txt_RoleName.ClientID);
            goto Label_0134;
Label_00B0:
            roles2 = SiteRoles.Get(this.nId);
            if (((roles2 == null) == 0) != null)
            {
                goto Label_00CF;
            }
            roles2 = new SiteRoles();
Label_00CF:
            roles2.PortalId     = SitePortal.GetCurrentPortalId();
            roles2.DepartId     = -1;
            roles2.IsDepartRole = 2;
            if (((PageUtil.CommonModify(this, roles2, roles2.Id, "", "创建失败,请与系统管理员联系!", "") > 0) == 0) != null)
            {
                goto Label_0134;
            }
            str = this.GetRefreshUrl(1, 1);
            PageUtil.WriteAlertAndRet(this.Page, "", str, "");
Label_0134:
            return;
        }
Пример #9
0
        public ResResultModel SaveRole(RoleModel model)
        {
            try
            {
                if (!HttpContext.Current.User.IsInRole("Administrators"))
                {
                    throw new ArgumentException(MC.Role_InvalidError);
                }

                model.RoleName = model.RoleName.Trim();
                if (string.IsNullOrEmpty(model.RoleName))
                {
                    return(ResResult.Response(false, MC.Request_Params_InvalidError, ""));
                }

                if (Roles.RoleExists(model.RoleName))
                {
                    return(ResResult.Response(false, MC.Data_ExistError, ""));
                }

                Guid gId = Guid.Empty;
                if (model.RoleId != null)
                {
                    Guid.TryParse(model.RoleId.ToString(), out gId);
                }

                var bll       = new SiteRoles();
                var modelInfo = new SiteRolesInfo(Guid.Empty, gId, model.RoleName, model.UserName, DateTime.Now);

                if (!gId.Equals(Guid.Empty))
                {
                    if (modelInfo.Named == "Administrators" || modelInfo.Named == "System" || modelInfo.Named == "Users" || modelInfo.Named == "Guest")
                    {
                        return(ResResult.Response(false, MC.M_SysDataChangedError, ""));
                    }

                    bll.UpdateAspnetRoles(modelInfo);
                }
                else
                {
                    Roles.CreateRole(model.RoleName);
                }

                return(ResResult.Response(true, "", ""));
            }
            catch (Exception ex)
            {
                return(ResResult.Response(false, ex.Message, ""));
            }
        }
Пример #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string    str;
            SiteRoles roles;
            bool      flag;

            this.nUserId = FunUtil.GetCurrentUserID(this.Page);
            this.nId     = Util.GetInt(base.Request, "id", -1);
            this.nSelId  = Util.GetInt(base.Request, "sel", -1);
            SkinUtil.AdhereEntryStyleSheet(this.Page, "bootstrap.min.css");
            if ((base.IsPostBack == 0) != null)
            {
                goto Label_0063;
            }
            goto Label_0174;
Label_0063:
            this.btnCancel.Visible = 0;
            if (((this.nId > 0) == 0) != null)
            {
                goto Label_010A;
            }
            str = Util.GetString(base.Request, "act", "");
            if ((("del" == str) == 0) != null)
            {
                goto Label_00C3;
            }
            SiteRoles.Del(this.nId);
            this.nId = -1;
            goto Label_0109;
Label_00C3:
            if ((("mdy" == str) == 0) != null)
            {
                goto Label_0109;
            }
            roles = SiteRoles.Get(this.nId);
            PageUtil.CommonFillEdit(this, roles);
            this.btnAdd.Value      = "更新";
            this.btnCancel.Visible = 1;
            Label_0109 :;
            Label_010A :
            this.PaginationBar1.RecordCount = 0x2710;
            this.PaginationBar1.PageIndex   = Util.GetInt(base.Request, "pi", 0) + 1;
            this.PaginationBar1.PageSize    = Util.GetInt(base.Request, "ps", this.PaginationBar1.DefaultPageSize);
            PageUtil.RestoreSearchConditionFromSession(this.Page);
            this.__BindData();
Label_0174:
            return;
        }
Пример #11
0
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            var uBll  = new SiteUsers();
            var rBll  = new SiteRoles();
            var urBll = new UsersInRoles();

            foreach (var uItem in usernames)
            {
                var uInfo = uBll.GetModel(uItem);
                foreach (var rItem in roleNames)
                {
                    var rInfo  = rBll.GetModel(rItem);
                    var urInfo = new UsersInRolesInfo(uInfo.Id, rInfo.Id);
                    urBll.Insert(urInfo);
                }
            }
        }
Пример #12
0
        protected void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
        {
            AnonymousIdentificationModule.ClearAnonymousIdentifier();

            try
            {
                var userId    = WebCommon.GetUserId();
                var menuBll   = new SiteMenus();
                var accessIds = new List <string>();
                accessIds.Add(userId.ToString());
                Task[] tasks = new Task[3];
                tasks[0] = Task.Factory.StartNew(() =>
                {
                    var roleIds = new SiteRoles().GetAspnetRoleIds(Roles.GetRolesForUser());
                    foreach (var item in roleIds)
                    {
                        accessIds.Add(item.ToString());
                    }
                });
                var userProfileInfo = new UserProfileInfo();
                tasks[1] = Task.Factory.StartNew(() =>
                {
                    var fuInfo = new FeatureUser().GetModel(userId, "UserProfile");
                    if (fuInfo != null)
                    {
                        userProfileInfo.SiteCode    = fuInfo.SiteCode;
                        userProfileInfo.SiteTitle   = fuInfo.SiteTitle;
                        userProfileInfo.SiteLogo    = string.IsNullOrWhiteSpace(fuInfo.SiteLogo) ? "" : WebCommon.GetSiteAppName() + fuInfo.SiteLogo;
                        userProfileInfo.CultureName = fuInfo.CultureName;
                    }
                });
                IList <SiteMenusInfo> maList = new List <SiteMenusInfo>();
                tasks[2] = Task.Factory.StartNew(() =>
                {
                    maList = menuBll.GetMenusAccess(Membership.ApplicationName, accessIds.ToArray(), User.IsInRole("Administrators"));
                });
                Task.WaitAll(tasks);

                var Profile = new CustomProfileCommon();
                Profile.UserMenus = JsonConvert.SerializeObject(maList);
                Profile.UserInfo  = JsonConvert.SerializeObject(userProfileInfo);

                Profile.Save();
            }
            catch { }
        }
Пример #13
0
        /// <summary>
        /// 数据绑定
        /// </summary>
        private void Bind()
        {
            SiteRoles           bll      = new SiteRoles();
            var                 roleList = bll.GetAspnetList("", null);
            List <UserRoleInfo> list     = new List <UserRoleInfo>();

            string[] items = Roles.GetAllRoles();
            foreach (string item in items)
            {
                var model = new UserRoleInfo();
                model.RoleId   = roleList.First(m => m.Named == item).Id;
                model.RoleName = item;

                list.Add(model);
            }

            rpData.DataSource = list;
            rpData.DataBind();
        }
 public CustomAuthorizeAttribute(SiteRoles roles)
 {
     Roles = roles;
 }
Пример #15
0
 public static bool isUserRole(SiteRoles role, HttpContext httpContext)
 {
     return (int)role == (int)httpContext.Session["role"];
 }
 public bool IsUserInRole(SiteRoles roles)
 {
     return Roles == 0 || (Roles & roles) == roles;
 }
Пример #17
0
        //private void SaveBarcodeTemplate(HttpContext context)
        //{
        //    try
        //    {
        //        var isInsert = false;
        //        Guid Id = Guid.Empty;
        //        if (!string.IsNullOrWhiteSpace(context.Request.Form["Id"])) Guid.TryParse(context.Request.Form["Id"], out Id);
        //        if (Id.Equals(Guid.Empty))
        //        {
        //            Id = Guid.NewGuid();
        //            isInsert = true;
        //        }
        //        var sTypeName = context.Request.Form["TypeName"].Trim();
        //        var userId = WebCommon.GetUserId();
        //        BarcodeTemplateInfo modelInfo = null;
        //        var sTitle = context.Request.Form["Title"].Trim();
        //        var sJContent = HttpUtility.UrlDecode(context.Request.Form["JContent"]).Trim();
        //        var isDefault = bool.Parse(context.Request.Form["IsDefault"]);

        //        if (string.IsNullOrWhiteSpace(sTitle) && string.IsNullOrWhiteSpace(sJContent) && string.IsNullOrWhiteSpace(sTypeName))
        //        {
        //            throw new ArgumentException(MC.M_RuleInvalidError);
        //        }

        //        if (sTypeName == "Barcode")
        //        {
        //            var sBarcode = context.Request.Form["Barcode"].Trim();
        //            var sBarcodeFormat = context.Request.Form["BarcodeFormat"].Trim();
        //            var width = int.Parse(context.Request.Form["Width"]);
        //            var height = int.Parse(context.Request.Form["Height"]);
        //            var margin = int.Parse(context.Request.Form["Margin"]);

        //            var barcodeInfo = new BarcodeInfo(sBarcode, sBarcodeFormat, width, height, margin, "");
        //           barcodeInfo.ImageUrl = FilesHelper.GetRndUrl("Barcodes",
        //            barcodeInfo.ImageUrl = ZxingHelper.CreateBarcode(barcodeInfo, Id.ToString(), true);
        //            modelInfo = new BarcodeTemplateInfo(Id, userId, sTitle, JsonConvert.SerializeObject(barcodeInfo), isDefault, sTypeName, DateTime.Now);
        //        }
        //        else
        //        {
        //            modelInfo = new BarcodeTemplateInfo(Id, userId, sTitle, sJContent, isDefault, sTypeName, DateTime.Now);
        //        }

        //        var bll = new BarcodeTemplate();
        //        int effect = -1;

        //        if (isInsert)
        //        {
        //            effect = bll.InsertByOutput(modelInfo);
        //        }
        //        else
        //        {
        //            effect = bll.Update(modelInfo);
        //        }
        //        if (effect < 1) context.Response.Write(ResResult.ResJsonString(false, MC.M_Save_Error, ""));

        //        context.Response.Write(ResResult.ResJsonString(true, "", ""));
        //    }
        //    catch (Exception ex)
        //    {
        //        context.Response.Write(ResResult.ResJsonString(false, ex.Message, ""));
        //    }
        //}

        #endregion

        #region 系统管理

        private void SaveMenuAccess(HttpContext context)
        {
            if (!(HttpContext.Current.User.IsInRole("Administrators") || HttpContext.Current.User.IsInRole("System")))
            {
                throw new ArgumentException(MC.Role_InvalidError);
            }

            var sRoleName     = context.Request.Form["RoleName"];
            var sUserName     = context.Request.Form["UserName"];
            var sMenuItemJson = context.Request.Form["MenuItemJson"];

            if (string.IsNullOrWhiteSpace(sMenuItemJson))
            {
                throw new ArgumentException(MC.Request_Params_InvalidError);
            }
            sMenuItemJson = HttpUtility.UrlDecode(sMenuItemJson);
            if (string.IsNullOrWhiteSpace(sRoleName) && string.IsNullOrWhiteSpace(sUserName))
            {
                throw new ArgumentException(MC.Request_Params_InvalidError);
            }
            List <SiteMenusAccessItemInfo> list = JsonConvert.DeserializeObject <List <SiteMenusAccessItemInfo> >(sMenuItemJson);
            var accessId   = Guid.Empty;
            var isRole     = !string.IsNullOrWhiteSpace(sRoleName);
            var accessType = isRole ? "Roles" : "Users";

            if (isRole)
            {
                if (sRoleName.ToLower() == "administrators")
                {
                    throw new ArgumentException(MC.GetString(MC.Params_SaveRoleAccessError, sRoleName));
                }

                var roleBll = new SiteRoles();
                accessId = roleBll.GetAspnetModel(Membership.ApplicationName, sRoleName).Id;
            }
            else
            {
                if (Roles.GetRolesForUser(sUserName).Contains("administrators"))
                {
                    throw new ArgumentException(MC.GetString(MC.Params_SaveUserAccessError, sUserName));
                }

                accessId = Guid.Parse(Membership.GetUser(sUserName).ProviderUserKey.ToString());
            }
            var menuBll = new SiteMenus();
            var maBll   = new SiteMenusAccess();
            List <SiteMenusAccessItemInfo> maitems = null;
            var appId           = new Applications().GetAspnetAppId(Membership.ApplicationName);
            var menusAccessInfo = maBll.GetModel(appId, accessId);

            if (menusAccessInfo != null)
            {
                maitems = JsonConvert.DeserializeObject <List <SiteMenusAccessItemInfo> >(menusAccessInfo.OperationAccess);
            }
            else
            {
                maitems = new List <SiteMenusAccessItemInfo>();
            }

            foreach (var item in list)
            {
                var menuId = Guid.Parse(item.MenuId.ToString());

                var itemIndex = maitems.FindIndex(m => m.MenuId.Equals(menuId));
                if (itemIndex > -1)
                {
                    maitems[itemIndex] = item;
                }
                else
                {
                    maitems.Add(item);
                }
            }

            if (menusAccessInfo != null)
            {
                menusAccessInfo.OperationAccess = JsonConvert.SerializeObject(maitems);
                maBll.Update(menusAccessInfo);
            }
            else
            {
                menusAccessInfo = new SiteMenusAccessInfo(appId, accessId, JsonConvert.SerializeObject(maitems), accessType);
                maBll.Insert(menusAccessInfo);
            }

            context.Response.Write(ResResult.ResJsonString(true, "", ""));
        }
Пример #18
0
 public void Login(string username, SiteRoles roles)
 {
     if (string.IsNullOrEmpty(username)) throw new ArgumentException("username is null or empty!", "username");
     _session[SessionKeys.Roles] = roles;
     _session[SessionKeys.Username] = username;
 }