Exemplo n.º 1
0
        public virtual async Task <ActionResult> RequestAccountDeletion()
        {
            var user = GetCurrentUser();

            if (user == null || user.IsDeleted)
            {
                return(HttpNotFound("User not found."));
            }

            var isSupportRequestCreated = await _supportRequestService.TryAddDeleteSupportRequestAsync(user);

            if (!isSupportRequestCreated)
            {
                TempData["RequestFailedMessage"] = Strings.AccountDelete_CreateSupportRequestFails;
                return(RedirectToAction("DeleteRequest"));
            }
            MessageService.SendAccountDeleteNotice(user.ToMailAddress(), user.Username);

            return(RedirectToAction("DeleteRequest"));
        }
Exemplo n.º 2
0
        public override async Task <ActionResult> RequestAccountDeletion(string accountName = null)
        {
            var user = GetAccount(accountName);

            if (user == null || user.IsDeleted)
            {
                return(HttpNotFound());
            }

            if (!user.Confirmed)
            {
                // Unconfirmed users can be deleted immediately without creating a support request.
                DeleteUserAccountStatus accountDeleteStatus = await _deleteAccountService.DeleteAccountAsync(userToBeDeleted : user,
                                                                                                             userToExecuteTheDelete : user,
                                                                                                             signature : user.Username,
                                                                                                             orphanPackagePolicy : AccountDeletionOrphanPackagePolicy.UnlistOrphans,
                                                                                                             commitAsTransaction : true);

                if (!accountDeleteStatus.Success)
                {
                    TempData["RequestFailedMessage"] = Strings.AccountSelfDelete_Fail;
                    return(RedirectToAction("DeleteRequest"));
                }
                OwinContext.Authentication.SignOut();
                return(SafeRedirect(Url.Home(false)));
            }

            var isSupportRequestCreated = await _supportRequestService.TryAddDeleteSupportRequestAsync(user);

            if (isSupportRequestCreated)
            {
                MessageService.SendAccountDeleteNotice(user);
            }
            else
            {
                TempData["RequestFailedMessage"] = Strings.AccountDelete_CreateSupportRequestFails;
            }

            return(RedirectToAction(nameof(DeleteRequest)));
        }