コード例 #1
0
ファイル: UserInfo.cs プロジェクト: omeryesil/awapicms
        /// <summary>
        /// Returns current user's role for the speficifed module
        /// </summary>
        /// <param name="lookForWholeWord">
        /// if true then modulename has to be matched (blog == blog)
        /// else module name should include that word (example:  blog, blogs, blogposts, blogcomments,, etc)
        /// </param>
        /// <param name="moduleName"></param>
        /// <returns></returns>
        public static AWAPI_Data.Data.awRole GetUserRole(bool lookForWholeWord, string moduleName)
        {
            AWAPI_Data.Data.awRole rtnRole = new AWAPI_Data.Data.awRole();

            if (App_Code.SessionInfo.CurrentUser == null ||
                App_Code.SessionInfo.CurrentUserRoles == null ||
                String.IsNullOrEmpty(moduleName))
            {
                return(rtnRole);
            }

            if (App_Code.SessionInfo.CurrentUser.isSuperAdmin)
            {
                rtnRole.canAdd          = true;
                rtnRole.canDelete       = true;
                rtnRole.canRead         = true;
                rtnRole.canUpdate       = true;
                rtnRole.canUpdateStatus = true;
                return(rtnRole);
            }


            var role = from r in App_Code.SessionInfo.CurrentUserRoles
                       where (lookForWholeWord && r.module.ToLower().Trim().Equals(moduleName.ToLower().Trim())) ||
                       (!lookForWholeWord && r.module.ToLower().Trim().IndexOf(moduleName.ToLower().Trim()) >= 0)
                       select r;

            if (role == null || role.Count() == 0)
            {
                return(rtnRole);
            }


            return(role.FirstOrDefault <AWAPI_Data.Data.awRole>());
        }
コード例 #2
0
        /// <summary>
        /// Populates menu, controls, etc based on the user rights
        /// </summary>
        void PopulatePageControls()
        {
            bool siteEnabled = false;

            if (App_Code.SessionInfo.CurrentSite != null)
            {
                siteEnabled = true;
            }

            #region GET USER RIGHTS FOR EACH MODULE
            //Get Roles for each module
            AWAPI_Data.Data.awRole rlBlog         = App_Code.UserInfo.GetUserRole(false, RoleLibrary.Module.blog.ToString());
            AWAPI_Data.Data.awRole rlContent      = App_Code.UserInfo.GetUserRole(true, RoleLibrary.Module.content.ToString());
            AWAPI_Data.Data.awRole rlContentForm  = App_Code.UserInfo.GetUserRole(false, RoleLibrary.Module.contentForm.ToString());
            AWAPI_Data.Data.awRole rlFiles        = App_Code.UserInfo.GetUserRole(false, RoleLibrary.Module.file.ToString());
            AWAPI_Data.Data.awRole rlPolls        = App_Code.UserInfo.GetUserRole(false, RoleLibrary.Module.poll.ToString());
            AWAPI_Data.Data.awRole rlUser         = App_Code.UserInfo.GetUserRole(false, RoleLibrary.Module.user.ToString());
            AWAPI_Data.Data.awRole rlContest      = App_Code.UserInfo.GetUserRole(false, RoleLibrary.Module.contest.ToString());
            AWAPI_Data.Data.awRole rlDataTransfer = App_Code.UserInfo.GetUserRole(false, RoleLibrary.Module.datatransfer.ToString());

            //AWAPI_Data.Data.awRole roleSite = App_Code.UserInfo.GetUserRole(false, "poll"); //poll is only available for the siteadmin
            #endregion

            #region POPULATE MENUS
            //Show hide menu's based on the rights
            menuLiDashboard.Visible     = true;
            menuLiConfiguration.Visible = App_Code.SessionInfo.CurrentUser.isSuperAdmin;
            menuLiSites.Visible         = App_Code.SessionInfo.CurrentUser.isSuperAdmin;
            menuLiBlogs.Visible         = App_Code.SessionInfo.CurrentUser.isSuperAdmin || (siteEnabled && (rlBlog.canRead || rlBlog.canAdd || rlBlog.canDelete || rlBlog.canUpdate || rlBlog.canUpdateStatus));
            menuLiContents.Visible      = App_Code.SessionInfo.CurrentUser.isSuperAdmin || (siteEnabled && (rlContent.canRead || rlContent.canAdd || rlContent.canDelete || rlContent.canUpdate || rlContent.canUpdateStatus));
            menuLiContentForms.Visible  = App_Code.SessionInfo.CurrentUser.isSuperAdmin || (siteEnabled && (rlContentForm.canRead || rlContentForm.canAdd || rlContentForm.canDelete || rlContentForm.canUpdate || rlContentForm.canUpdateStatus));
            menuLiContest.Visible       = App_Code.SessionInfo.CurrentUser.isSuperAdmin || (siteEnabled && (rlContest.canRead || rlContest.canAdd || rlContest.canDelete || rlContest.canUpdate || rlContest.canUpdateStatus));
            menuLiFiles.Visible         = App_Code.SessionInfo.CurrentUser.isSuperAdmin || (siteEnabled && (rlFiles.canRead || rlFiles.canAdd || rlFiles.canDelete || rlFiles.canUpdate || rlFiles.canUpdateStatus));
            menuLiUsers.Visible         = App_Code.SessionInfo.CurrentUser.isSuperAdmin || (siteEnabled && (rlUser.canRead || rlUser.canAdd || rlUser.canDelete || rlUser.canUpdate || rlUser.canUpdateStatus));
            menuLiPolls.Visible         = App_Code.SessionInfo.CurrentUser.isSuperAdmin || (siteEnabled && (rlPolls.canRead || rlPolls.canAdd || rlPolls.canDelete || rlPolls.canUpdate || rlPolls.canUpdateStatus));
            menuLiDataTransfer.Visible  = App_Code.SessionInfo.CurrentUser.isSuperAdmin || (siteEnabled && (rlDataTransfer.canRead || rlDataTransfer.canAdd || rlDataTransfer.canDelete || rlDataTransfer.canUpdate || rlDataTransfer.canUpdateStatus));

            //SET SELECTED CLASS
            menuLiDashboard.Attributes.Add("class", IsCurrentPage("default.aspx") == true ? "active" : "");
            menuLiConfiguration.Attributes.Add("class", IsCurrentPage("admin/configuration") == true ? "active" : "");
            menuLiSites.Attributes.Add("class", IsCurrentPage("admin/site") == true ? "active" : "");
            menuLiBlogs.Attributes.Add("class", IsCurrentPage("admin/blog") == true ? "active" : "");
            if (IsCurrentPage("admin/contentforms"))
            {
                menuLiContentForms.Attributes.Add("class", "active");
            }
            else if (IsCurrentPage("admin/content"))
            {
                menuLiContents.Attributes.Add("class", "active");
            }
            menuLiContest.Attributes.Add("class", IsCurrentPage("admin/contest") == true ? "active" : "");
            menuLiFiles.Attributes.Add("class", IsCurrentPage("admin/file") == true ? "active" : "");
            menuLiUsers.Attributes.Add("class", IsCurrentPage("admin/users") == true ? "active" : "");
            menuLiPolls.Attributes.Add("class", IsCurrentPage("admin/poll") == true ? "active" : "");
            menuLiDataTransfer.Attributes.Add("class", IsCurrentPage("admin/datatransfer") == true ? "active" : "");
            #endregion
        }
コード例 #3
0
ファイル: UserInfo.cs プロジェクト: omeryesil/awapicms
        /// <summary>
        ///
        /// </summary>
        /// <param name="canAdd"></param>
        /// <param name="canDelete"></param>
        /// <param name="canRead"></param>
        /// <param name="canUpdate"></param>
        /// <param name="canUpdateStatus"></param>
        /// <param name="lookForWholeWord"></param>
        /// <param name="moduleName"></param>
        /// <returns></returns>
        public static bool GetUserRole(bool?canAdd,
                                       bool?canDelete,
                                       bool?canRead,
                                       bool?canUpdate,
                                       bool?canUpdateStatus, bool lookForWholeWord, string moduleName)
        {
            AWAPI_Data.Data.awRole rtnRole = GetUserRole(lookForWholeWord, moduleName);

            return(((canAdd != null && canAdd == rtnRole.canAdd) || canAdd == null) &&        //if canadd==null or equal to the user's role
                   ((canDelete != null && canDelete == rtnRole.canDelete) || canDelete == null) &&
                   ((canRead != null && canRead == rtnRole.canRead) || canRead == null) &&
                   ((canUpdate != null && canUpdate == rtnRole.canUpdate) || canUpdate == null) &&
                   ((canUpdateStatus != null && canUpdateStatus == rtnRole.canUpdateStatus) || canUpdateStatus == null));
        }