示例#1
0
        public override async Task <ActionResult> RequestAccountDeletion(string accountName = null)
        {
            var user = GetAccount(accountName);

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

            if (!user.Confirmed)
            {
                // Unconfirmed users can be deleted immediately without creating a support request.
                DeleteUserAccountStatus accountDeleteStatus = await _deleteAccountService.DeleteAccountAsync(userToBeDeleted : user,
                                                                                                             userToExecuteTheDelete : user,
                                                                                                             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)
            {
                var emailMessage = new AccountDeleteNoticeMessage(MessageServiceConfiguration, user);
                await MessageService.SendMessageAsync(emailMessage);
            }
            else
            {
                TempData["RequestFailedMessage"] = Strings.AccountDelete_CreateSupportRequestFails;
            }

            return(RedirectToAction(nameof(DeleteRequest)));
        }
示例#2
0
        public override async Task <ActionResult> RequestAccountDeletion(string accountName = null)
        {
            var user = GetAccount(accountName);

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

            if (_config.SelfServiceAccountDeleteEnabled && _featureFlagService.IsSelfServiceAccountDeleteEnabled())
            {
                return(await DeleteAndCheckSuccess(user));
            }
            else
            {
                if (!user.Confirmed)
                {
                    // Unconfirmed users can be deleted immediately without creating a support request.
                    return(await DeleteAndCheckSuccess(user));
                }

                var isSupportRequestCreated = await _supportRequestService.TryAddDeleteSupportRequestAsync(user);

                if (isSupportRequestCreated)
                {
                    var emailMessage = new AccountDeleteNoticeMessage(MessageServiceConfiguration, user);
                    await MessageService.SendMessageAsync(emailMessage);

                    return(RedirectToAction(nameof(DeleteRequest)));
                }
                else
                {
                    TempData["RequestFailedMessage"] = Strings.AccountDelete_CreateSupportRequestFails;

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