Ejemplo n.º 1
0
        public async Task <ActionResult> DeleteUser_Perform(ActionWithUserSearchData data, string submitAction)
        {
            if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.UserManagement))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (submitAction != "Delete")
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (data.FindUserData.SelectedUserIDs == null || data.FindUserData.SelectedUserIDs.Count <= 0)
            {
                return(await DeleteUser_Find(data));
            }

            int userIdToDelete = data.FindUserData.SelectedUserIDs.FirstOrDefault();
            var user           = await UserGuiHelper.GetUserAsync(userIdToDelete);

            bool result = await UserManager.DeleteUserAsync(userIdToDelete);

            if (result)
            {
                ApplicationAdapter.AddUserToListToBeLoggedOutByForce(user.NickName);
            }

            await FillUserDataForStateAsync(data.FindUserData, AdminFindUserState.PostAction, string.Empty, string.Empty);

            var viewData = new ActionWithUserSearchData(data.FindUserData);

            viewData.FinalActionResult = result ? "The user has been deleted" : "Deleting the user failed, perhaps you selected a user that couldn't be deleted?";

            return(View("~/Views/Admin/DeleteUser.cshtml", viewData));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> BanUnbanUser_Perform(ActionWithUserSearchData data, string submitAction)
        {
            if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.UserManagement))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (submitAction != "ToggleBanFlag")
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (data.FindUserData.SelectedUserIDs == null || data.FindUserData.SelectedUserIDs.Count <= 0)
            {
                return(await BanUnbanUser_Find(data));
            }

            int userIdToToggleBanFlagOf = data.FindUserData.SelectedUserIDs.FirstOrDefault();

            var(toggleResult, newBanFlagValue) = await UserManager.ToggleBanFlagValueAsync(userIdToToggleBanFlagOf);

            if (newBanFlagValue)
            {
                var user = await UserGuiHelper.GetUserAsync(userIdToToggleBanFlagOf);

                ApplicationAdapter.AddUserToListToBeLoggedOutByForce(user.NickName);
            }

            await FillUserDataForStateAsync(data.FindUserData, AdminFindUserState.PostAction, string.Empty, string.Empty);

            var viewData = new ActionWithUserSearchData(data.FindUserData);

            if (toggleResult)
            {
                viewData.FinalActionResult = newBanFlagValue ? "The user is now banned" : "The user has been unbanned";
            }
            else
            {
                viewData.FinalActionResult = "Toggling the ban flag failed.";
            }

            return(View("~/Views/Admin/BanUnbanUser.cshtml", viewData));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> ShowAuditInfoUser_UserSelected(ActionWithUserSearchData data, string submitAction, string filterAsString, string foundUserIds)
        {
            if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.UserManagement))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (submitAction == "SearchAgain")
            {
                return(await ShowAuditInfoUser());
            }

            if (submitAction != "PerformAction")
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (data.FindUserData.SelectedUserIDs == null || data.FindUserData.SelectedUserIDs.Count <= 0 || string.IsNullOrWhiteSpace(foundUserIds))
            {
                return(await ShowAuditInfoUser_Find(data));
            }

            int selectedUserId   = data.FindUserData.SelectedUserIDs.FirstOrDefault();
            var auditDataForView = new ShowAuditInfoUserData(data.FindUserData)
            {
                AuditData   = await SecurityGuiHelper.GetAllAuditsForUserAsync(selectedUserId),
                AuditedUser = await UserGuiHelper.GetUserAsync(selectedUserId)
            };

            data.FindUserData.OverrideFilterAsString(filterAsString);

            // we'll keep the search form open so we can quickly view data of multiple users without searching again. This means we'll keep the finduserdata state
            // as it is, as this is the end state of this action anyway.
            data.FindUserData.ActionButtonText = "View audit info";
            data.FindUserData.FindUserState    = AdminFindUserState.UsersFound;
            var userIDsFoundAsString = foundUserIds.Split(',');
            var userIDsOfUsersToLoad = userIDsFoundAsString.Select(us => Convert.ToInt32(us)).ToList();

            data.FindUserData.FoundUsers = await UserGuiHelper.GetUsersAsync(userIDsOfUsersToLoad);

            return(View("~/Views/Admin/ShowAuditInfoUser.cshtml", auditDataForView));
        }
Ejemplo n.º 5
0
 public async Task <ActionResult> EditUserInfo_Find(ActionWithUserSearchData data)
 {
     return(await ActionWithUserSearch_FindAsync(d => Task.FromResult(new ActionWithUserSearchData(d)), data.FindUserData, "Manage profile",
                                                 "EditUserInfo_UserSelected", "EditUserInfo_Find", "~/Views/Admin/EditUserInfo_Search.cshtml", false));
 }
Ejemplo n.º 6
0
 public async Task <ActionResult> BanUnbanUser_UserSelected(ActionWithUserSearchData data, string submitAction)
 {
     return(await ActionWithUserSearch_UserSelectedAsync(d => Task.FromResult(new ActionWithUserSearchData(d)), data.FindUserData, submitAction,
                                                         async() => await BanUnbanUser(), async d => await BanUnbanUser_Find(data),
                                                         "BanUnbanUser_Perform", "~/Views/Admin/BanUnbanUser.cshtml"));
 }
Ejemplo n.º 7
0
 public async Task <ActionResult> BanUnbanUser_Find(ActionWithUserSearchData data)
 {
     return(await ActionWithUserSearch_FindAsync(d => Task.FromResult(new ActionWithUserSearchData(d)), data.FindUserData, "Ban / Unban selected user",
                                                 "BanUnbanUser_UserSelected", "BanUnbanUser_Find", "~/Views/Admin/BanUnbanUser.cshtml", true));
 }
Ejemplo n.º 8
0
 public async Task <ActionResult> ShowAuditInfoUser_Find(ActionWithUserSearchData data)
 {
     return(await ActionWithUserSearch_FindAsync(d => Task.FromResult(new ActionWithUserSearchData(d)), data.FindUserData, "View audit info",
                                                 "ShowAuditInfoUser_UserSelected", "ShowAuditInfoUser_Find", "~/Views/Admin/ShowAuditInfoUser.cshtml", false));
 }