コード例 #1
0
ファイル: RoleSyncronizer.cs プロジェクト: jspsoft/YAFNET-DNN
        /// <summary>
        /// Creates the YAF role.
        /// </summary>
        /// <param name="roleName">Name of the role.</param>
        /// <param name="boardId">The board id.</param>
        /// <param name="yafBoardAccessMasks">The YAF board access masks.</param>
        /// <returns>
        /// Returns the Role id of the created Role
        /// </returns>
        public static long CreateYafRole(string roleName, int boardId, List <RoleInfo> yafBoardAccessMasks)
        {
            // If not Create Role in YAF
            if (!RoleMembershipHelper.RoleExists(roleName))
            {
                RoleMembershipHelper.CreateRole(roleName);
            }

            int accessMaskId;

            try
            {
                // Give the default DNN Roles Member Access, unknown roles get "No Access Mask"
                accessMaskId = roleName.Equals("Registered Users") || roleName.Equals("Subscribers")
                               ? yafBoardAccessMasks.Find(mask => mask.RoleName.Equals("Member Access")).RoleID
                               : yafBoardAccessMasks.Find(mask => mask.RoleName.Equals("No Access Mask")).RoleID;
            }
            catch (Exception)
            {
                accessMaskId = yafBoardAccessMasks.Find(mask => mask.RoleGroupID.Equals(0)).RoleID;
            }

            // Role exists in membership but not in yaf itself simply add it to yaf
            return(LegacyDb.group_save(
                       DBNull.Value,
                       boardId,
                       roleName,
                       false,
                       false,
                       false,
                       false,
                       accessMaskId,
                       0,
                       null,
                       100,
                       null,
                       0,
                       null,
                       null,
                       0,
                       0));
        }
コード例 #2
0
ファイル: default.aspx.cs プロジェクト: Pathfinder-Fr/Website
        /// <summary>
        ///     Creates the forum.
        /// </summary>
        /// <returns>
        ///     The create forum.
        /// </returns>
        private bool CreateForum()
        {
            if (this.InstallUpgradeService.IsForumInstalled)
            {
                this.ShowErrorMessage("Forum is already installed.");
                return(false);
            }

            if (this.TheForumName.Text.Length == 0)
            {
                this.ShowErrorMessage("You must enter a forum name.");
                return(false);
            }

            if (this.ForumEmailAddress.Text.Length == 0)
            {
                this.ShowErrorMessage("You must enter a forum email address.");
                return(false);
            }

            MembershipUser user;

            if (this.UserChoice.SelectedValue == "create")
            {
                if (this.UserName.Text.Length == 0)
                {
                    this.ShowErrorMessage("You must enter the admin user name,");
                    return(false);
                }

                if (this.AdminEmail.Text.Length == 0)
                {
                    this.ShowErrorMessage("You must enter the administrators email address.");
                    return(false);
                }

                if (this.Password1.Text.Length == 0)
                {
                    this.ShowErrorMessage("You must enter a password.");
                    return(false);
                }

                if (this.Password1.Text != this.Password2.Text)
                {
                    this.ShowErrorMessage("The passwords must match.");
                    return(false);
                }

                // create the admin user...
                MembershipCreateStatus status;
                user = this.Get <MembershipProvider>()
                       .CreateUser(
                    this.UserName.Text,
                    this.Password1.Text,
                    this.AdminEmail.Text,
                    this.SecurityQuestion.Text,
                    this.SecurityAnswer.Text,
                    true,
                    null,
                    out status);
                if (status != MembershipCreateStatus.Success)
                {
                    this.ShowErrorMessage(
                        "Create Admin User Failed: {0}".FormatWith(this.GetMembershipErrorMessage(status)));
                    return(false);
                }
            }
            else
            {
                // try to get data for the existing user...
                user = UserMembershipHelper.GetUser(this.ExistingUserName.Text.Trim());

                if (user == null)
                {
                    this.ShowErrorMessage(
                        "Existing user name is invalid and does not represent a current user in the membership store.");
                    return(false);
                }
            }

            try
            {
                var prefix = Config.CreateDistinctRoles && Config.IsAnyPortal ? "YAF " : string.Empty;

                // add administrators and registered if they don't already exist...
                if (!RoleMembershipHelper.RoleExists("{0}Administrators".FormatWith(prefix)))
                {
                    RoleMembershipHelper.CreateRole("{0}Administrators".FormatWith(prefix));
                }

                if (!RoleMembershipHelper.RoleExists("{0}Registered".FormatWith(prefix)))
                {
                    RoleMembershipHelper.CreateRole("{0}Registered".FormatWith(prefix));
                }

                if (!RoleMembershipHelper.IsUserInRole(user.UserName, "{0}Administrators".FormatWith(prefix)))
                {
                    RoleMembershipHelper.AddUserToRole(user.UserName, "{0}Administrators".FormatWith(prefix));
                }

                // logout administrator...
                FormsAuthentication.SignOut();


                // init forum...
                this.InstallUpgradeService.InitializeForum(
                    this.TheForumName.Text,
                    this.TimeZones.SelectedValue,
                    this.Culture.SelectedValue,
                    this.ForumEmailAddress.Text,
                    this.ForumBaseUrlMask.Text,
                    user.UserName,
                    user.Email,
                    user.ProviderUserKey);
            }
            catch (Exception x)
            {
                this.ShowErrorMessage(x.Message);
                return(false);
            }

            return(true);
        }
コード例 #3
0
ファイル: editboard.ascx.cs プロジェクト: jiangsq123/YAFNET
        /// <summary>
        /// The create board.
        /// </summary>
        /// <param name="adminName">The admin name.</param>
        /// <param name="adminPassword">The admin password.</param>
        /// <param name="adminEmail">The admin email.</param>
        /// <param name="adminPasswordQuestion">The admin password question.</param>
        /// <param name="adminPasswordAnswer">The admin password answer.</param>
        /// <param name="boardName">The board name.</param>
        /// <param name="boardMembershipAppName">The board membership app name.</param>
        /// <param name="boardRolesAppName">The board roles app name.</param>
        /// <param name="createUserAndRoles">The create user and roles.</param>
        protected bool CreateBoard(
            [NotNull] string adminName,
            [NotNull] string adminPassword,
            [NotNull] string adminEmail,
            [NotNull] string adminPasswordQuestion,
            [NotNull] string adminPasswordAnswer,
            [NotNull] string boardName,
            [NotNull] string boardMembershipAppName,
            [NotNull] string boardRolesAppName,
            bool createUserAndRoles)
        {
            // Store current App Names
            string currentMembershipAppName = this.Get <MembershipProvider>().ApplicationName;
            string currentRolesAppName      = this.Get <RoleProvider>().ApplicationName;

            if (boardMembershipAppName.IsSet() && boardRolesAppName.IsSet())
            {
                // Change App Names for new board
                this.Get <MembershipProvider>().ApplicationName = boardMembershipAppName;
                this.Get <MembershipProvider>().ApplicationName = boardRolesAppName;
            }

            int       newBoardID;
            DataTable cult     = StaticDataHelper.Cultures();
            string    langFile = "english.xml";

            foreach (DataRow drow in
                     cult.Rows.Cast <DataRow>().Where(drow => drow["CultureTag"].ToString() == this.Culture.SelectedValue))
            {
                langFile = (string)drow["CultureFile"];
            }

            if (createUserAndRoles)
            {
                // Create new admin users
                MembershipCreateStatus createStatus;
                MembershipUser         newAdmin = this.Get <MembershipProvider>()
                                                  .CreateUser(
                    adminName,
                    adminPassword,
                    adminEmail,
                    adminPasswordQuestion,
                    adminPasswordAnswer,
                    true,
                    null,
                    out createStatus);

                if (createStatus != MembershipCreateStatus.Success)
                {
                    this.PageContext.AddLoadMessage(
                        "Create User Failed: {0}".FormatWith(this.GetMembershipErrorMessage(createStatus)),
                        MessageTypes.Error);

                    return(false);
                }

                // Create groups required for the new board
                RoleMembershipHelper.CreateRole("Administrators");
                RoleMembershipHelper.CreateRole("Registered");

                // Add new admin users to group
                RoleMembershipHelper.AddUserToRole(newAdmin.UserName, "Administrators");

                // Create Board
                newBoardID = this.DbCreateBoard(
                    boardName,
                    boardMembershipAppName,
                    boardRolesAppName,
                    langFile,
                    newAdmin);
            }
            else
            {
                // new admin
                MembershipUser newAdmin = UserMembershipHelper.GetUser();

                // Create Board
                newBoardID = this.DbCreateBoard(
                    boardName,
                    boardMembershipAppName,
                    boardRolesAppName,
                    langFile,
                    newAdmin);
            }

            if (newBoardID > 0 && Config.MultiBoardFolders)
            {
                // Successfully created the new board
                string boardFolder = this.Server.MapPath(Path.Combine(Config.BoardRoot, "{0}/".FormatWith(newBoardID)));

                // Create New Folders.
                if (!Directory.Exists(Path.Combine(boardFolder, "Images")))
                {
                    // Create the Images Folders
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images"));

                    // Create Sub Folders
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Avatars"));
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Categories"));
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Forums"));
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Emoticons"));
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Medals"));
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Ranks"));
                }

                if (!Directory.Exists(Path.Combine(boardFolder, "Themes")))
                {
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Themes"));

                    // Need to copy default theme to the Themes Folder
                }

                if (!Directory.Exists(Path.Combine(boardFolder, "Uploads")))
                {
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Uploads"));
                }
            }

            // Return application name to as they were before.
            this.Get <MembershipProvider>().ApplicationName = currentMembershipAppName;
            this.Get <RoleProvider>().ApplicationName       = currentRolesAppName;

            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Saves the click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void SaveClick([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (!ValidationHelper.IsValidInt(this.PMLimit.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(
                    this.GetText("ADMIN_EDITGROUP", "MSG_VALID_NUMBER"),
                    MessageTypes.warning);
                return;
            }

            if (!ValidationHelper.IsValidInt(this.Priority.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITGROUP", "MSG_INTEGER"), MessageTypes.warning);
                return;
            }

            if (!ValidationHelper.IsValidInt(this.UsrAlbums.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(
                    this.GetText("ADMIN_EDITGROUP", "MSG_ALBUM_NUMBER"),
                    MessageTypes.warning);
                return;
            }

            if (!ValidationHelper.IsValidInt(this.UsrSigChars.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(
                    this.GetText("ADMIN_EDITGROUP", "MSG_SIG_NUMBER"),
                    MessageTypes.warning);
                return;
            }

            if (!ValidationHelper.IsValidInt(this.UsrAlbumImages.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(
                    this.GetText("ADMIN_EDITGROUP", "MSG_TOTAL_NUMBER"),
                    MessageTypes.warning);
                return;
            }

            // Role
            long roleId = 0;

            // get role ID from page's parameter
            if (this.Get <HttpRequestBase>().QueryString.Exists("i"))
            {
                roleId = long.Parse(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("i"));
            }

            // get new and old name
            var roleName    = this.Name.Text.Trim();
            var oldRoleName = string.Empty;

            // if we are editing existing role, get it's original name
            if (roleId != 0)
            {
                // get the current role name in the DB
                var groups = this.GetRepository <Group>().List(boardId: this.PageContext.PageBoardID);

                groups.ForEach(group => oldRoleName = @group.Name);
            }

            // save role and get its ID if it's new (if it's old role, we get it anyway)
            roleId = this.GetRepository <Group>().Save(
                roleId,
                this.PageContext.PageBoardID,
                roleName,
                this.IsAdminX.Checked,
                this.IsGuestX.Checked,
                this.IsStartX.Checked,
                this.IsModeratorX.Checked,
                this.AccessMaskID.SelectedValue,
                this.PMLimit.Text.Trim(),
                this.StyleTextBox.Text.Trim(),
                this.Priority.Text.Trim(),
                this.Description.Text,
                this.UsrSigChars.Text,
                this.UsrSigBBCodes.Text,
                this.UsrSigHTMLTags.Text,
                this.UsrAlbums.Text.Trim(),
                this.UsrAlbumImages.Text.Trim());

            // empty out access table(s)
            this.GetRepository <Active>().DeleteAll();
            this.GetRepository <ActiveAccess>().DeleteAll();

            // see if need to rename an existing role...
            if (oldRoleName.IsSet() && roleName != oldRoleName && RoleMembershipHelper.RoleExists(oldRoleName) &&
                !RoleMembershipHelper.RoleExists(roleName) && !this.IsGuestX.Checked)
            {
                // transfer users in addition to changing the name of the role...
                var users = this.Get <RoleProvider>().GetUsersInRole(oldRoleName);

                // delete the old role...
                RoleMembershipHelper.DeleteRole(oldRoleName, false);

                // create new role...
                RoleMembershipHelper.CreateRole(roleName);

                if (users.Any())
                {
                    // put users into new role...
                    this.Get <RoleProvider>().AddUsersToRoles(users, new[] { roleName });
                }
            }
            else if (!RoleMembershipHelper.RoleExists(roleName) && !this.IsGuestX.Checked)
            {
                // if role doesn't exist in provider's data source, create it

                // simply create it
                RoleMembershipHelper.CreateRole(roleName);
            }

            // Access masks for a newly created or an existing role
            if (this.Get <HttpRequestBase>().QueryString.Exists("i"))
            {
                // go through all forums
                for (var i = 0; i < this.AccessList.Items.Count; i++)
                {
                    // get current repeater item
                    var item = this.AccessList.Items[i];

                    // get forum ID
                    var forumId = int.Parse(item.FindControlAs <Label>("ForumID").Text);

                    // save forum access masks for this role
                    this.GetRepository <ForumAccess>().Save(
                        forumId,
                        roleId.ToType <int>(),
                        item.FindControlAs <DropDownList>("AccessmaskID").SelectedValue.ToType <int>());
                }

                YafBuildLink.Redirect(ForumPages.admin_groups);
            }

            // remove caching in case something got updated...
            this.Get <IDataCache>().Remove(Constants.Cache.ForumModerators);

            // Clearing cache with old permissions data...
            this.Get <IDataCache>().Remove(
                k => k.StartsWith(string.Format(Constants.Cache.ActiveUserLazyData, string.Empty)));

            // Clear Styling Caching
            this.Get <IDataCache>().Remove(Constants.Cache.GroupRankStyles);

            // Done, redirect to role editing page
            YafBuildLink.Redirect(ForumPages.admin_editgroup, "i={0}", roleId);
        }
コード例 #5
0
        /// <summary>
        /// Handles click on save button.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void Save_Click([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (!ValidationHelper.IsValidInt(this.PMLimit.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITGROUP", "MSG_VALID_NUMBER"));
                return;
            }

            if (!ValidationHelper.IsValidInt(this.Priority.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITGROUP", "MSG_INTEGER"));
                return;
            }

            if (!ValidationHelper.IsValidInt(this.UsrAlbums.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITGROUP", "MSG_ALBUM_NUMBER"));
                return;
            }

            if (!ValidationHelper.IsValidInt(this.UsrSigChars.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITGROUP", "MSG_SIG_NUMBER"));
                return;
            }

            if (!ValidationHelper.IsValidInt(this.UsrAlbumImages.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITGROUP", "MSG_TOTAL_NUMBER"));
                return;
            }

            // Role
            long roleID = 0;

            // get role ID from page's parameter
            if (this.Request.QueryString.GetFirstOrDefault("i") != null)
            {
                roleID = long.Parse(this.Request.QueryString.GetFirstOrDefault("i"));
            }

            // get new and old name
            string roleName    = this.Name.Text.Trim();
            string oldRoleName = string.Empty;

            // if we are editing exising role, get it's original name
            if (roleID != 0)
            {
                // get the current role name in the DB
                using (DataTable dt = LegacyDb.group_list(YafContext.Current.PageBoardID, roleID))
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        oldRoleName = row["Name"].ToString();
                    }
                }
            }

            // save role and get its ID if it's new (if it's old role, we get it anyway)
            roleID = LegacyDb.group_save(
                roleID,
                this.PageContext.PageBoardID,
                roleName,
                this.IsAdminX.Checked,
                this.IsGuestX.Checked,
                this.IsStartX.Checked,
                this.IsModeratorX.Checked,
                AccessMaskID.SelectedValue,
                this.PMLimit.Text.Trim(),
                this.StyleTextBox.Text.Trim(),
                this.Priority.Text.Trim(),
                this.Description.Text,
                this.UsrSigChars.Text,
                this.UsrSigBBCodes.Text,
                this.UsrSigHTMLTags.Text,
                this.UsrAlbums.Text.Trim(),
                this.UsrAlbumImages.Text.Trim());

            // empty out access table
            this.GetRepository <ActiveAccess>().Reset();

            // see if need to rename an existing role...
            if (oldRoleName.IsSet() && roleName != oldRoleName && RoleMembershipHelper.RoleExists(oldRoleName) && !RoleMembershipHelper.RoleExists(roleName) && !this.IsGuestX.Checked)
            {
                // transfer users in addition to changing the name of the role...
                var users = this.Get <RoleProvider>().GetUsersInRole(oldRoleName);

                // delete the old role...
                RoleMembershipHelper.DeleteRole(oldRoleName, false);

                // create new role...
                RoleMembershipHelper.CreateRole(roleName);

                if (users.Any())
                {
                    // put users into new role...
                    this.Get <RoleProvider>().AddUsersToRoles(users, new[] { roleName });
                }
            }
            else if (!RoleMembershipHelper.RoleExists(roleName) && !this.IsGuestX.Checked)
            {
                // if role doesn't exist in provider's data source, create it

                // simply create it
                RoleMembershipHelper.CreateRole(roleName);
            }

            // Access masks for a newly created or an existing role
            if (this.Request.QueryString.GetFirstOrDefault("i") != null)
            {
                // go trhough all forums
                for (int i = 0; i < this.AccessList.Items.Count; i++)
                {
                    // get current repeater item
                    RepeaterItem item = this.AccessList.Items[i];

                    // get forum ID
                    int forumID = int.Parse(((Label)item.FindControl("ForumID")).Text);

                    // save forum access maks for this role
                    LegacyDb.forumaccess_save(forumID, roleID,
                                              ((DropDownList)item.FindControl("AccessmaskID")).SelectedValue);
                }

                YafBuildLink.Redirect(ForumPages.admin_groups);
            }

            // remove caching in case something got updated...
            this.Get <IDataCache>().Remove(Constants.Cache.ForumModerators);

            // Clearing cache with old permissions data...
            this.Get <IDataCache>().Remove(k => k.StartsWith(Constants.Cache.ActiveUserLazyData.FormatWith(String.Empty)));

            // Done, redirect to role editing page
            YafBuildLink.Redirect(ForumPages.admin_editgroup, "i={0}", roleID);
        }
コード例 #6
0
        /// <summary>
        /// The create board.
        /// </summary>
        /// <param name="adminName">The admin name.</param>
        /// <param name="adminPassword">The admin password.</param>
        /// <param name="adminEmail">The admin email.</param>
        /// <param name="adminPasswordQuestion">The admin password question.</param>
        /// <param name="adminPasswordAnswer">The admin password answer.</param>
        /// <param name="boardName">The board name.</param>
        /// <param name="boardMembershipAppName">The board membership app name.</param>
        /// <param name="boardRolesAppName">The board roles app name.</param>
        /// <param name="createUserAndRoles">The create user and roles.</param>
        /// <returns>Returns if the board was created or not</returns>
        protected bool CreateBoard(
            [NotNull] string adminName,
            [NotNull] string adminPassword,
            [NotNull] string adminEmail,
            [NotNull] string adminPasswordQuestion,
            [NotNull] string adminPasswordAnswer,
            [NotNull] string boardName,
            [NotNull] string boardMembershipAppName,
            [NotNull] string boardRolesAppName,
            bool createUserAndRoles)
        {
            // Store current App Names
            var currentMembershipAppName = this.Get <MembershipProvider>().ApplicationName;
            var currentRolesAppName      = this.Get <RoleProvider>().ApplicationName;

            if (boardMembershipAppName.IsSet() && boardRolesAppName.IsSet())
            {
                // Change App Names for new board
                this.Get <MembershipProvider>().ApplicationName = boardMembershipAppName;
                this.Get <MembershipProvider>().ApplicationName = boardRolesAppName;
            }

            int newBoardId;
            var cult     = StaticDataHelper.Cultures();
            var langFile = "english.xml";

            cult.Where(dataRow => dataRow.CultureTag == this.Culture.SelectedValue)
            .ForEach(row => langFile = row.CultureFile);

            if (createUserAndRoles)
            {
                // Create new admin users
                var newAdmin = this.Get <MembershipProvider>()
                               .CreateUser(
                    adminName,
                    adminPassword,
                    adminEmail,
                    adminPasswordQuestion,
                    adminPasswordAnswer,
                    true,
                    null,
                    out var createStatus);

                if (createStatus != MembershipCreateStatus.Success)
                {
                    this.PageContext.AddLoadMessage(
                        $"Create User Failed: {this.GetMembershipErrorMessage(createStatus)}",
                        MessageTypes.danger);

                    return(false);
                }

                // Create groups required for the new board
                RoleMembershipHelper.CreateRole("Administrators");
                RoleMembershipHelper.CreateRole("Registered");

                // Add new admin users to group
                RoleMembershipHelper.AddUserToRole(newAdmin.UserName, "Administrators");

                // Create Board
                newBoardId = this.DbCreateBoard(
                    boardName,
                    boardMembershipAppName,
                    boardRolesAppName,
                    langFile,
                    newAdmin);
            }
            else
            {
                // new admin
                var newAdmin = UserMembershipHelper.GetUser();

                // Create Board
                newBoardId = this.DbCreateBoard(
                    boardName,
                    boardMembershipAppName,
                    boardRolesAppName,
                    langFile,
                    newAdmin);
            }

            if (newBoardId > 0 && Config.MultiBoardFolders)
            {
                // Successfully created the new board
                var boardFolder = this.Server.MapPath(Path.Combine(Config.BoardRoot, $"{newBoardId}/"));

                // Create New Folders.
                if (!Directory.Exists(Path.Combine(boardFolder, "Images")))
                {
                    // Create the Images Folders
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images"));

                    // Create Sub Folders
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Avatars"));
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Categories"));
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Forums"));
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Medals"));
                }

                if (!Directory.Exists(Path.Combine(boardFolder, "Uploads")))
                {
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Uploads"));
                }
            }

            // Return application name to as they were before.
            this.Get <MembershipProvider>().ApplicationName = currentMembershipAppName;
            this.Get <RoleProvider>().ApplicationName       = currentRolesAppName;

            return(true);
        }
コード例 #7
0
        /// <summary>
        /// The create board.
        /// </summary>
        /// <param name="adminName">
        /// The admin name.
        /// </param>
        /// <param name="adminPassword">
        /// The admin password.
        /// </param>
        /// <param name="adminEmail">
        /// The admin email.
        /// </param>
        /// <param name="adminPasswordQuestion">
        /// The admin password question.
        /// </param>
        /// <param name="adminPasswordAnswer">
        /// The admin password answer.
        /// </param>
        /// <param name="boardName">
        /// The board name.
        /// </param>
        /// <param name="boardMembershipAppName">
        /// The board membership app name.
        /// </param>
        /// <param name="boardRolesAppName">
        /// The board roles app name.
        /// </param>
        /// <param name="createUserAndRoles">
        /// The create user and roles.
        /// </param>
        /// <exception cref="ApplicationException">
        /// </exception>
        protected void CreateBoard(
            string adminName,
            string adminPassword,
            string adminEmail,
            string adminPasswordQuestion,
            string adminPasswordAnswer,
            string boardName,
            string boardMembershipAppName,
            string boardRolesAppName,
            bool createUserAndRoles)
        {
            // Store current App Names
            string currentMembershipAppName = PageContext.CurrentMembership.ApplicationName;
            string currentRolesAppName      = PageContext.CurrentRoles.ApplicationName;

            if (boardMembershipAppName.IsSet() && boardRolesAppName.IsSet())
            {
                // Change App Names for new board
                PageContext.CurrentMembership.ApplicationName = boardMembershipAppName;
                PageContext.CurrentMembership.ApplicationName = boardRolesAppName;
            }

            int newBoardID = 0;

            System.Data.DataTable cult = StaticDataHelper.Cultures();
            string langFile            = "english.xml";

            foreach (System.Data.DataRow drow in cult.Rows)
            {
                if (drow["CultureTag"].ToString() == this.Culture.SelectedValue)
                {
                    langFile = (string)drow["CultureFile"];
                }
            }
            if (createUserAndRoles)
            {
                // Create new admin users
                MembershipCreateStatus createStatus;
                MembershipUser         newAdmin = PageContext.CurrentMembership.CreateUser(
                    adminName, adminPassword, adminEmail, adminPasswordQuestion, adminPasswordAnswer, true, null, out createStatus);
                if (createStatus != MembershipCreateStatus.Success)
                {
                    PageContext.AddLoadMessage("Create User Failed: {0}".FormatWith(this.GetMembershipErrorMessage(createStatus)));
                    throw new ApplicationException("Create User Failed: {0}".FormatWith(this.GetMembershipErrorMessage(createStatus)));
                }

                // Create groups required for the new board
                RoleMembershipHelper.CreateRole("Administrators");
                RoleMembershipHelper.CreateRole("Registered");

                // Add new admin users to group
                RoleMembershipHelper.AddUserToRole(newAdmin.UserName, "Administrators");

                // Create Board
                newBoardID = DB.board_create(newAdmin.UserName, newAdmin.Email, newAdmin.ProviderUserKey, boardName, this.Culture.SelectedItem.Value, langFile, boardMembershipAppName, boardRolesAppName);
            }
            else
            {
                // new admin
                MembershipUser newAdmin = UserMembershipHelper.GetUser();

                // Create Board
                newBoardID = DB.board_create(newAdmin.UserName, newAdmin.Email, newAdmin.ProviderUserKey, boardName, this.Culture.SelectedItem.Value, langFile, boardMembershipAppName, boardRolesAppName);
            }


            if (newBoardID > 0 && Config.MultiBoardFolders)
            {
                // Successfully created the new board
                string boardFolder = Server.MapPath(Path.Combine(Config.BoardRoot, newBoardID.ToString() + "/"));

                // Create New Folders.
                if (!Directory.Exists(Path.Combine(boardFolder, "Images")))
                {
                    // Create the Images Folders
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images"));

                    // Create Sub Folders
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Avatars"));
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Categories"));
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Forums"));
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Emoticons"));
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Medals"));
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Ranks"));
                }

                if (!Directory.Exists(Path.Combine(boardFolder, "Themes")))
                {
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Themes"));

                    // Need to copy default theme to the Themes Folder
                }

                if (!Directory.Exists(Path.Combine(boardFolder, "Uploads")))
                {
                    Directory.CreateDirectory(Path.Combine(boardFolder, "Uploads"));
                }
            }


            // Return application name to as they were before.
            YafContext.Current.CurrentMembership.ApplicationName = currentMembershipAppName;
            YafContext.Current.CurrentRoles.ApplicationName      = currentRolesAppName;
        }
コード例 #8
0
ファイル: editgroup.ascx.cs プロジェクト: RichardBer/ParkCMS
        /// <summary>
        /// Handles click on save button.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void Save_Click(object sender, EventArgs e)
        {
            if (!ValidationHelper.IsValidInt(this.PMLimit.Text.Trim()))
            {
                PageContext.AddLoadMessage("You should enter integer value for pmessage number.");
                return;
            }

            if (!ValidationHelper.IsValidInt(this.Priority.Text.Trim()))
            {
                PageContext.AddLoadMessage("You should enter integer value for priority.");
                return;
            }
            if (!ValidationHelper.IsValidInt(this.UsrAlbums.Text.Trim()))
            {
                PageContext.AddLoadMessage("You should enter integer value for the number of user albums.");
                return;
            }
            if (!ValidationHelper.IsValidInt(this.UsrSigChars.Text.Trim()))
            {
                PageContext.AddLoadMessage("You should enter integer value for the number of chars in user signature.");
                return;
            }
            if (!ValidationHelper.IsValidInt(this.UsrAlbumImages.Text.Trim()))
            {
                PageContext.AddLoadMessage("You should enter integer value for the total number of images in all albums.");
                return;
            }

            // Role
            long roleID = 0;

            // get role ID from page's parameter
            if (Request.QueryString.GetFirstOrDefault("i") != null)
            {
                roleID = long.Parse(Request.QueryString.GetFirstOrDefault("i"));
            }

            // get new and old name
            string roleName    = this.Name.Text.Trim();
            string oldRoleName = string.Empty;

            // if we are editing exising role, get it's original name
            if (roleID != 0)
            {
                // get the current role name in the DB
                using (DataTable dt = DB.group_list(YafContext.Current.PageBoardID, roleID))
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        oldRoleName = row["Name"].ToString();
                    }
                }
            }

            // save role and get its ID if it's new (if it's old role, we get it anyway)
            roleID = DB.group_save(
                roleID,
                PageContext.PageBoardID,
                roleName,
                this.IsAdminX.Checked,
                this.IsGuestX.Checked,
                this.IsStartX.Checked,
                this.IsModeratorX.Checked,
                this.AccessMaskID.SelectedValue,
                this.PMLimit.Text.Trim(),
                this.StyleTextBox.Text.Trim(),
                this.Priority.Text.Trim(),
                this.Description.Text,
                this.UsrSigChars.Text,
                this.UsrSigBBCodes.Text,
                this.UsrSigHTMLTags.Text,
                this.UsrAlbums.Text.Trim(),
                this.UsrAlbumImages.Text.Trim()
                );


            // see if need to rename an existing role...
            if (roleName != oldRoleName && RoleMembershipHelper.RoleExists(oldRoleName) && !RoleMembershipHelper.RoleExists(roleName) && !this.IsGuestX.Checked)
            {
                // transfer users in addition to changing the name of the role...
                string[] users = PageContext.CurrentRoles.GetUsersInRole(oldRoleName);

                // delete the old role...
                RoleMembershipHelper.DeleteRole(oldRoleName, false);

                // create new role...
                RoleMembershipHelper.CreateRole(roleName);

                if (users.Length > 0)
                {
                    // put users into new role...
                    PageContext.CurrentRoles.AddUsersToRoles(users, new[] { roleName });
                }
            }

            // if role doesn't exist in provider's data source, create it
            else if (!RoleMembershipHelper.RoleExists(roleName) && !this.IsGuestX.Checked)
            {
                // simply create it
                RoleMembershipHelper.CreateRole(roleName);
            }


            // Access masks for a newly created or an existing role
            if (Request.QueryString.GetFirstOrDefault("i") != null)
            {
                // go trhough all forums
                for (int i = 0; i < this.AccessList.Items.Count; i++)
                {
                    // get current repeater item
                    RepeaterItem item = this.AccessList.Items[i];

                    // get forum ID
                    int forumID = int.Parse(((Label)item.FindControl("ForumID")).Text);

                    // save forum access maks for this role
                    DB.forumaccess_save(forumID, roleID, ((DropDownList)item.FindControl("AccessmaskID")).SelectedValue);
                }

                YafBuildLink.Redirect(ForumPages.admin_groups);
            }

            // remove caching in case something got updated...
            PageContext.Cache.Remove(YafCache.GetBoardCacheKey(Constants.Cache.ForumModerators));

            // Clearing cache with old permissions data...
            this.PageContext.Cache.RemoveAllStartsWith(Constants.Cache.ActiveUserLazyData.FormatWith(String.Empty));

            // Done, redirect to role editing page
            YafBuildLink.Redirect(ForumPages.admin_editgroup, "i={0}", roleID);
        }