Example #1
0
        public async Task <bool> DeleteAccount(User user)
        {
            _logger.LogInformation("Attempting delete...");
            if (user == null)
            {
                _logger.LogWarning("Requested user was not found in DB. Delete was probably already done.");
                throw new UserNotFoundException();
            }

            if (!_userEvaluator.CanUserBeDeleted(user))
            {
                _logger.LogInformation("User was not able to be automatically deleted. Criteria check failed.");
                return(false);
            }

            _logger.LogInformation("All criteria passed.");
            var result = await _deleteAccountService.DeleteAccountAsync(userToBeDeleted : user, userToExecuteTheDelete : user, orphanPackagePolicy : AccountDeletionOrphanPackagePolicy.UnlistOrphans);

            if (result.Success)
            {
                _logger.LogInformation("Deleted user successfully.");
                return(true);
            }
            else
            {
                _logger.LogError("Criteria passed but delete failed.");
                return(false);
            }
        }
Example #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 (!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)));
        }