private static async Task FillUserDataForStateAsync(FindUserData data, AdminFindUserState stateToFillDataFor, string actionButtonText, string actionToPostTo, int roleIDWhichUsersToExclude = 0) { data.Roles = await SecurityGuiHelper.GetAllRolesAsync(); switch (stateToFillDataFor) { case AdminFindUserState.Start: // no-op break; case AdminFindUserState.UsersFound: data.FoundUsers = await UserGuiHelper.FindUsers(data.FilterOnRole, data.SelectedRoleID, data.FilterOnNickName, data.SpecifiedNickName, data.FilterOnEmailAddress, data.SpecifiedEmailAddress, roleIDWhichUsersToExclude); break; case AdminFindUserState.FinalAction: case AdminFindUserState.PostAction: data.SelectedUsers = await UserGuiHelper.GetAllUsersInRangeAsync(data.SelectedUserIDs); break; default: throw new ArgumentOutOfRangeException(nameof(stateToFillDataFor), stateToFillDataFor, null); } data.FindUserState = stateToFillDataFor; data.ActionButtonText = actionButtonText; data.ActionToPostTo = actionToPostTo; }
public async Task <ActionResult> EditUserInfo_FinalAction(EditUserInfoData data) { if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.UserManagement)) { return(RedirectToAction("Index", "Home")); } data.UserTitles = await UserGuiHelper.GetAllUserTitlesAsync(); data.Roles = await SecurityGuiHelper.GetAllRolesAsync(); if (!ModelState.IsValid) { return(View("~/Views/Admin/EditUserInfo.cshtml", data)); } data.Sanitize(); data.StripProtocolsFromUrls(); bool result = false; var user = await UserGuiHelper.GetUserAsync(data.UserId); if (user != null) { result = await UserManager.UpdateUserProfileAsync(data.UserId, data.DateOfBirth, data.EmailAddress, user.EmailAddressIsPublic ?? false, data.IconURL, data.Location, data.Occupation, data.NewPassword, data.Signature, data.Website, data.UserTitleId, user.AutoSubscribeToThread, user.DefaultNumberOfMessagesPerPage, data.IsBanned, data.RoleIDs); } data.InfoEdited = result; return(View("~/Views/Admin/EditUserInfo.cshtml", data)); }
public async Task <ActionResult> EditUserInfo_UserSelected(ActionWithUserSearchData data, string submitAction) { if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.UserManagement)) { return(RedirectToAction("Index", "Home")); } if (submitAction == "SearchAgain") { return(await EditUserInfo()); } if (submitAction != "PerformAction") { return(RedirectToAction("Index", "Home")); } if (data.FindUserData.SelectedUserIDs == null || data.FindUserData.SelectedUserIDs.Count <= 0) { return(await EditUserInfo_Find(data)); } var user = await UserGuiHelper.GetUserAsync(data.FindUserData.SelectedUserIDs.FirstOrDefault()); if (user == null) { // not found return(RedirectToAction("Index", "Home")); } var newData = new EditUserInfoData() { UserId = user.UserID, EmailAddress = user.EmailAddress, NickName = user.NickName, DateOfBirth = user.DateOfBirth, Occupation = user.Occupation ?? string.Empty, Location = user.Location ?? string.Empty, Signature = user.Signature ?? string.Empty, Website = user.Website ?? string.Empty, IconURL = user.IconURL ?? string.Empty, UserTitleId = user.UserTitleID, IPAddress = user.IPNumber, LastVisitDate = user.LastVisitedDate.HasValue ? user.LastVisitedDate.Value.ToString("f") : "Never", IsBanned = user.IsBanned, RoleIDs = await SecurityGuiHelper.GetAllRoleIDsForUserAsync(user.UserID), Roles = await SecurityGuiHelper.GetAllRolesAsync(), UserTitles = await UserGuiHelper.GetAllUserTitlesAsync(), }; newData.Sanitize(); return(View("~/Views/Admin/EditUserInfo.cshtml", newData)); }
public async Task <ActionResult> ManageUsersPerRole() { if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.SecurityManagement)) { return(RedirectToAction("Index", "Home")); } var data = new UsersInRolesData(); data.AvailableRoles = await SecurityGuiHelper.GetAllRolesAsync(); return(View("~/Views/Admin/ManageUsersPerRole.cshtml", data)); }
public async Task <ActionResult> SystemParameters() { if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.SystemManagement)) { return(RedirectToAction("Index", "Home")); } var data = new SystemParametersData() { AllRoles = await SecurityGuiHelper.GetAllRolesAsync(), AllUserTitles = await UserGuiHelper.GetAllUserTitlesAsync(), SystemData = await _cache.GetSystemDataAsync() }; return(View("~/Views/Admin/SystemParameters.cshtml", data)); }
public async Task <ActionResult> ManageRoleRights() { if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.SecurityManagement)) { return(RedirectToAction("Index", "Home")); } var allRoles = await SecurityGuiHelper.GetAllRolesAsync(); var roleId = allRoles.FirstOrDefault()?.RoleID ?? 0; var allForumIds = await ForumGuiHelper.GetAllForumIdsAsync(); var forumId = allForumIds.FirstOrDefault(); return(await ManageRightsForForum(new ManageForumRoleRightsData() { RoleID = roleId, ForumID = forumId })); }
public async Task <ActionResult> ManageRightsForForum(ManageForumRoleRightsData data, string submitAction = "") { if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.SecurityManagement)) { return(RedirectToAction("Index", "Home")); } data.AvailableRoles = await SecurityGuiHelper.GetAllRolesAsync(); data.AvailableActionRights = await SecurityGuiHelper.GetAllActionRightsApplybleToAForumAsync(); data.AvailableForums = await ForumGuiHelper.GetAllForumsWithSectionNamesAsync(); switch (submitAction) { case "save": // save the data, then after this action, it'll reload the data and show it. data.LastActionResult = await SecurityManager.SaveForumActionRightsForForumRoleAsync(data.ActionRightsSet, data.RoleID, data.ForumID) ? "Save successful" : "Save failed"; break; case "cancel": return(RedirectToAction("Index", "Home")); default: // nothin' break; } // postback which should simply fill in the data and show the form var forumActionRightRolesForForumRole = await SecurityGuiHelper.GetForumActionRightRolesForForumRoleAsync(data.RoleID, data.ForumID); data.ActionRightsSet = forumActionRightRolesForForumRole.Select(r => r.ActionRightID).ToList(); return(View("~/Views/Admin/ManageRightsPerForum.cshtml", data)); }