public async Task <ActionResult> DeleteAccount(DeleteAccountViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = UserManager.FindById(User.Identity.GetUserId <int>());

            if (UserManager.CheckPassword(user, model.Password))
            {
                // Delete UserDetails (connection with User [FK])
                user.RemoveUserDetails();

                IdentityResult result = await UserManager.DeleteAsync(user);

                if (result.Succeeded)
                {
                    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                    return(RedirectToAction("Index", "Home", new { area = "" }));
                }
                AddErrors(result);
                model.Checked = false;
                return(View(model));
            }
            else
            {
                IdentityResult uncorrectPassword = IdentityResult.Failed("You entered a wrong password.");
                AddErrors(uncorrectPassword);
                model.Checked = false;
                return(View(model));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> DeleteAccount2step(DeleteAccountViewModel model)
        {
            ViewBag.Token = model.Token;
            var userIsAuth = HttpContext.User.Identity.IsAuthenticated;

            if (!userIsAuth)
            {
                ModelState.AddModelError("Error", "You need to be log in.");
                return(PartialView("~/Views/Auth/DeleteAccountConfirmation.cshtml"));
            }

            var responseFromApi = await _apiService.DeleteAccountProcess(model, "2step");

            if (!responseFromApi.Success)
            {
                ModelState.AddModelError("Error", responseFromApi.Messages.First());
                return(PartialView("~/Views/Auth/DeleteAccountConfirmation.cshtml"));
            }

            if (responseFromApi.Success)
            {
                _encryptionService.RemoveEncryptionKey(HttpContext.User.Identity.Name);
                await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

                TempData["logoutMessage"] = "You account has been deleted.";
            }
            return(RedirectToAction(controllerName: "Home", actionName: "Index"));
        }
Beispiel #3
0
        public async Task <IActionResult> Delete([FromBody] DeleteAccountViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Ok());
            }

            var user = await _userManager.FindByIdAsync(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value);

            if (user == null)
            {
                return(Ok(new { error = "User not found.", error_description = $"Unable to load user with ID '{_userManager.GetUserId(User)}'." }));
            }

            if (user.UserName != model.UserName)
            {
                return(Ok());
            }

            await _signInManager.SignOutAsync();

            _userContext.RemoveUserGuidCookies();

            var deleteUserResult = await _userManager.DeleteAsync(user);

            if (!deleteUserResult.Succeeded)
            {
                AddErrors(deleteUserResult);
                return(Ok());
            }

            _logger.LogInformation("User deleted and logged out.");
            return(Ok(new { token = await _userContext.GenerateToken(_userContext.NewGuestUser()) }));
        }
        public async Task <IActionResult> Deletes([FromBody] DeleteAccountViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                return(BadRequest(Errors.AddErrorToModelState("user_search_failure", "Could not find user in database.", ModelState)));
            }
            if (await _userManager.CheckPasswordAsync(user, model.Password))
            {
                var temp = _appDbContext.Users.First(u => u.Identity.Email.Equals(model.Email));
                _appDbContext.Users.Remove(temp);
                await _userManager.DeleteAsync(user);

                await _appDbContext.SaveChangesAsync();

                return(new OkObjectResult("Account Deleted"));
            }
            else
            {
                return(BadRequest(Errors.AddErrorToModelState("user_search_failure", "Password is invalid", ModelState)));
            }
        }
        public ActionResult DeleteAccount(DeleteAccountViewModel user)
        {
            if (!ModelState.IsValid)
            {
                return(View(user));
            }

            if (user.password != user.ConfirmPassword)
            {
                ModelState.AddModelError("", "Passwords do not match");
                return(View(user));
            }

            var result = m.AccountDelete(user);

            if (result)
            {
                return(RedirectToAction("Login", "Home"));
            }
            else
            {
                ModelState.AddModelError("", "Invalid Password");
                return(View(user));
            }
        }
Beispiel #6
0
        public ActionResult DeleteAccount(DeleteAccountViewModel model)
        {
            // require users to enter their password in order to execute account delete action
            var user = UserManager.Find(User.Identity.Name, model.CurrentPassword);

            if (user != null)
            {
                // execute delete action
                if (UserHelper.DeleteUser(User.Identity.Name))
                {
                    // delete email address and set password to something random
                    UserManager.SetEmail(User.Identity.GetUserId(), null);

                    string randomPassword = "";
                    using (SHA512 shaM = new SHA512Managed())
                    {
                        randomPassword = Convert.ToBase64String(shaM.ComputeHash(Encoding.UTF8.GetBytes(Path.GetRandomFileName())));
                    }

                    UserManager.ChangePassword(User.Identity.GetUserId(), model.CurrentPassword, randomPassword);

                    AuthenticationManager.SignOut();
                    return(View("~/Views/Account/AccountDeleted.cshtml"));
                }

                // something went wrong when deleting user account
                return(View("~/Views/Errors/Error.cshtml"));
            }

            return(RedirectToAction("Manage", new { message = ManageMessageId.WrongPassword }));
        }
Beispiel #7
0
        public ActionResult DeleteAccount(DeleteAccountViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (User.Identity.IsAuthenticated)
                {
                    AuthenticationManager.SignOut();

                    // execute delete action
                    if (Whoaverse.Utils.User.DeleteUser(User.Identity.Name))
                    {
                        // deletion executed without errors
                        return(View("~/Views/Account/AccountDeleted.cshtml"));
                    }
                    else
                    {
                        return(View("~/Views/Errors/Error.cshtml"));
                    }
                }
                else
                {
                    return(View("~/Views/Errors/Error.cshtml"));
                }
            }
            else
            {
                return(View("~/Views/Errors/Error.cshtml"));
            }
        }
        public IActionResult GetAccount(string CustomerID)
        {
            DeleteAccountViewModel deleteAccountViewModel = null;
            Customer cust = _customerRepository.GetCustomer(Convert.ToInt32(CustomerID));
            Account  acc  = _accountRepository.GetAccountByCustomerID(Convert.ToInt32(CustomerID));

            if (cust != null && acc != null)
            {
                string name      = cust.Name;
                int    accountID = acc.AccountID;
                deleteAccountViewModel = new DeleteAccountViewModel()
                {
                    CustomerName = name, AccountID = accountID
                };
            }
            else
            {
                ViewData["DeleteSuccess"] = "false";
                deleteAccountViewModel    = new DeleteAccountViewModel()
                {
                    CustomerName = "No Account", AccountID = 000000000
                };
            }
            return(View("DeleteAccount", deleteAccountViewModel));
        }
Beispiel #9
0
        public async Task <JsonNetResult> DeleteMemberAccount(DeleteAccountViewModel model)
        {
            var response = new GetDeleteAccountResponse();

            if (string.IsNullOrWhiteSpace(model.Language) || string.IsNullOrEmpty(model.Language))
            {
                response.Success      = false;
                response.ResponseData = null;
                response.Message      = "An error has occured.";

                if (_logger.IsErrorEnabled)
                {
                    _logger.Error("Language is null or empty in  DeleteMemberAccount POST action of surface controller MyAccountController");
                }

                return(ReturnJsonResponse(response));
            }

            var    culture = GetCultureInformationForLanguage(model.Language);
            string locale  = culture.Locale;

            if (!ModelState.IsValid)
            {
                response.Success = false;
                response.Message = GetErrorsFromModelState(ModelState).FirstOrDefault();
                return(ReturnJsonResponse(response));
            }

            var result = await _profileService.DeleteAccount(model.Email, locale, model.Reason);

            if (result == null)
            {
                response.Success      = false;
                response.ResponseData = null;
                response.Message      = "An error has occured.";
            }

            if (result.Status != (int)ResponseStatus.Success)
            {
                response.Success      = false;
                response.ResponseData = model;
                response.Message      = result.Message;
                return(ReturnJsonResponse(response));
            }

            bool isDeleted = _umbracoHelper.DeleteUmbracoMember(model.Email);

            if (!isDeleted)
            {
                response.Success = false;
                response.Message = "An error has occured.";
                return(ReturnJsonResponse(response));
            }

            Logout();
            response.Success = true;
            response.Message = result.Message;
            return(ReturnJsonResponse(response));
        }
Beispiel #10
0
 public AccountViewModel()
 {
     CreateAccountViewModel        = new CreateAccountViewModel();
     DeleteAccountViewModel        = new DeleteAccountViewModel();
     UpdateAccountView             = new UpdateAccountViewModel();
     GetAccountViewModel           = new GetAccountViewModel();
     GetAccountCollectionViewModel = new GetAccountCollectionViewModel();
 }
        public IActionResult DeleteAccount()
        {
            var model = new DeleteAccountViewModel {
                StatusMessage = StatusMessage
            };

            return(View(model));
        }
        public ActionResult DeleteAccount(DeleteAccountViewModel model)
        {
            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login"));
            }

            UserModel user;

            if (model.ID == 0)
            {
                user = userService.GetByUserName(Session["Username"].ToString());
            }

            else
            {
                user = userService.GetByID(model.ID);
            }

            if (user == null)
            {
                ViewBag.Status = false;
                ModelState.AddModelError("", "User not found");

                return(View());
            }

            else if (Session["Role"].ToString() == "Admin")
            {
                if (userService.Delete(user))
                {
                    TempData["Status"]  = true;
                    TempData["Message"] = "User Account successfully deleted";

                    return(RedirectToAction("ListUsers"));
                }
            }

            else if (userService.PasswordIsMatched(user.UserName, model.Password))
            {
                if (userService.Delete(user))
                {
                    Logout();

                    TempData["Status"]  = true;
                    TempData["Message"] = "User Account successfully deleted";

                    return(RedirectToAction("Index", "Home"));
                }

                else
                {
                    ModelState.AddModelError("", "Can't delete user");
                }
            }
            return(View());
        }
        public async Task <ActionResult> DeleteAccount(DeleteAccountViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _userService.FindById(User.Identity.GetUserId <int>());

                var picture = _userService.FindById(user.Id).PictureId;
                if (picture.HasValue)
                {
                    _pictureService.Delete(picture.Value);
                }

                var ordersId = _orderService.GetAll().Where(o => o.UserId == user.Id).Select(o => o.Id).ToList();
                if (ordersId.Any())
                {
                    var responses = _responseService.GetAll()
                                    .Select(r => r.OrderId.Value)
                                    .Where(r => ordersId.Contains(r)).ToList();
                    if (responses.Any())
                    {
                        foreach (var response in responses)
                        {
                            _responseService.Delete(response);
                        }
                    }
                }

                var comments = _commentService.GetAll().Where(c => c.CustomerId == user.Id).ToList();
                if (comments.Any())
                {
                    foreach (var comment in comments)
                    {
                        _commentService.Delete(comment.Id);
                    }
                }

                ClientViewModelBLL userDto = new ClientViewModelBLL
                {
                    Password = model.Password,
                    Email    = User.Identity.Name
                };
                var operationDetails = await _userService.DeleteAccount(userDto);

                if (operationDetails.Succedeed)
                {
                    _unitOfWork.Save();
                    LogOff();
                    return(RedirectToAction("Index", "Home"));
                }

                ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
            }
            return(View(model));
        }
Beispiel #14
0
        public async Task <IActionResult> Delete([Bind] DeleteAccountViewModel password)
        {
            var user = await GetCurrentLocalUserAsync();

            if (HttpContext.Request.Method == "GET")
            {
                ViewData["Controller"] = "Account";
                ViewData["Action"]     = nameof(Delete);
                HttpContext.Items["RequirePassword"] = await _userManager.HasPasswordAsync(user);

                ModelState.Clear();
                return(View(password ?? new DeleteAccountViewModel()));
            }
            else if (HttpContext.Request.Method == "POST")
            {
                if (user == null)
                {
                    return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
                }

                var RequirePassword = await _userManager.HasPasswordAsync(user);

                if (RequirePassword)
                {
                    if (password.CurrentPassword != password.ConfirmPassword || !await _userManager.CheckPasswordAsync(user, password.CurrentPassword))
                    {
                        ModelState.AddModelError(string.Empty, "Password not correct.");
                        return(View(password));
                    }
                }

                var result = await _userManager.DeleteAsync(user);

                var userId = await _userManager.GetUserIdAsync(user);

                if (!result.Succeeded)
                {
                    throw new InvalidOperationException($"Unexpected error occurred deleteing user with ID '{userId}'.");
                }

                await _signInManager.SignOutAsync();

                return(Redirect("~/"));
            }
            else
            {
                throw new ArgumentOutOfRangeException("Method");
            }
        }
Beispiel #15
0
        public ActionResult DeleteAccount(DeleteAccountViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("~/Views/Errors/Error.cshtml"));
            }
            if (!User.Identity.IsAuthenticated)
            {
                return(View("~/Views/Errors/Error.cshtml"));
            }
            AuthenticationManager.SignOut();

            // execute delete action
            return(View(Utils.User.DeleteUser(User.Identity.Name) ? "~/Views/Account/AccountDeleted.cshtml" : "~/Views/Errors/Error.cshtml"));
        }
        public IActionResult DeleteAccount(DeleteAccountViewModel model)
        {
            Account account = _accountRepository.Delete(model.AccountID);

            if (account != null)
            {
                ViewData["DeleteSuccess"] = "true";
            }
            else
            {
                ViewData["DeleteSuccess"] = "false";
            }
            return(View(model));
            //return model.AccountID;
        }
Beispiel #17
0
        public IActionResult DeleteAccount1Step(DeleteAccountViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("Error", "There was an error. Try again or contact support.");
                return(PartialView("~/Views/Auth/DeleteAccount.cshtml"));
            }
            var responseFromApi = _apiService.DeleteAccountProcess(model, "1step").Result;

            if (!responseFromApi.Success)
            {
                ModelState.AddModelError("Error", responseFromApi.Messages.First());
                return(PartialView("~/Views/Auth/DeleteAccount.cshtml"));
            }
            return(PartialView("~/Views/Auth/DeleteAccountNotification.cshtml"));
        }
        public async Task <IActionResult> DeleteAccount(DeleteAccountViewModel model)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }
            try
            {
                var passwordIsCorrect = await _userManager.CheckPasswordAsync(user, model.Password);

                if (passwordIsCorrect)
                {
                    user.UserName           = user.Id;
                    user.NormalizedUserName = null;
                    user.NormalizedEmail    = null;
                    user.AccessFailedCount  = 0;
                    user.Email                = "deleted";
                    user.FirstName            = null;
                    user.LastName             = null;
                    user.Organisation         = null;
                    user.Degree               = null;
                    user.VATID                = null;
                    user.PhoneNumber          = null;
                    user.EmailConfirmed       = false;
                    user.PhoneNumberConfirmed = false;
                    user.IsDeleted            = true;
                    var roles = _userManager.GetRolesAsync(user).Result.ToAsyncEnumerable().ToEnumerable();
                    await _userManager.RemoveFromRolesAsync(user, roles);

                    var result = await _userManager.UpdateAsync(user);

                    await _signInManager.SignOutAsync();

                    _logger.LogInformation("User logged out.");
                    return(RedirectToAction(nameof(HomeController.Index), "Home"));
                }
                return(View());
            }
            catch
            {
                return(View());
            }
        }
Beispiel #19
0
        public JsonResult DeleteAccount(DeleteAccountViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (!_userService.PasswordIsValidForCurrentUser(viewModel.DeleteConfirmPassword))
                {
                    ModelState.AddModelError("DeleteConfirmPassword", @"The password you provided is invalid.");
                }

                var currentUser = _userService.GetCurrentUser();

                _userService.Logout();
                _userService.Delete(currentUser);
                _emailService.SendAccountDeletionReasonsEmail(viewModel.Reason, viewModel.Elaboration, viewModel.Suggestions);
            }

            return(Json(_validationHelper.ModelStateToJsonResult(ModelState)));
        }
Beispiel #20
0
        public async Task <IActionResult> Delete(string returnUrl = "")
        {
            try
            {
                // check user exists
                var userAccount = await _userStore.GetUserAccountAsync(User.Identity.Name);

                var davm = new DeleteAccountViewModel();
                return(View(davm));
            }
            catch (Exception)
            {
                Log.Warning($"User account not found: '{User.Identity.Name}'");
                var davm = new DeleteAccountViewModel();
                ModelState.AddModelError("", $"No user found with name '{User.Identity.Name}'");
                return(View(davm));
            }
        }
        public ActionResult DeleteAccount(int id = 0)
        {
            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login"));
            }

            if (id == 0)
            {
                ViewBag.Message = $"Are you sure you want to delete account called {Session["Username"]}?";
                return(View());
            }

            DeleteAccountViewModel model = new DeleteAccountViewModel
            {
                ID = id
            };

            return(DeleteAccount(model));
        }
Beispiel #22
0
        public ActionResult DeleteAccount(DeleteAccountViewModel model)
        {
            // require users to enter their password in order to execute account delete action
            var user = UserManager.Find(User.Identity.Name, model.CurrentPassword);

            if (user != null)
            {
                // execute delete action
                if (Utils.User.DeleteUser(User.Identity.Name))
                {
                    AuthenticationManager.SignOut();
                    return(View("~/Views/Account/AccountDeleted.cshtml"));
                }

                // something went wrong when deleting user account
                return(View("~/Views/Errors/Error.cshtml"));
            }

            return(RedirectToAction("Manage", new { message = ManageMessageId.WrongPassword }));
        }
Beispiel #23
0
        public async Task <IActionResult> Delete(DeleteAccountViewModel davm)
        {
            try
            {
                if (!ModelState.IsValid || !davm.Confirm)
                {
                    ModelState.AddModelError("", "You must confirm that you want to delete your user account and associated settings.");
                    return(View("Delete"));
                }
                var deleted = await _userStore.DeleteUserAsync(User.Identity.Name);

                if (deleted)
                {
                    // delete user's settings
                    try
                    {
                        var us = await _userStore.GetUserSettingsAsync(User.Identity.Name);

                        await _userStore.DeleteUserSettingsAsync(User.Identity.Name);
                    }
                    catch (UserSettingsNotFoundException)
                    {
                        // no action needed
                    }
                    catch (UserStoreException e)
                    {
                        Log.Error($"Error deleting user settings during user account {User.Identity.Name} deletion", e);
                    }

                    // repositories
                    try
                    {
                        var repos = await _repoSettingsStore.GetRepoSettingsForOwnerAsync(User.Identity.Name);

                        foreach (var r in repos)
                        {
                            await _repoSettingsStore.DeleteRepoSettingsAsync(r.OwnerId, r.RepositoryId);
                        }
                    }
                    catch (RepoSettingsNotFoundException)
                    {
                        // no action needed
                    }
                    catch (RepoSettingsStoreException e)
                    {
                        Log.Error($"Error deleting repo settings during user account {User.Identity.Name} deletion", e);
                    }

                    // owner settings
                    try
                    {
                        var owner = await _ownerSettingsStore.GetOwnerSettingsAsync(User.Identity.Name);

                        await _ownerSettingsStore.DeleteOwnerSettingsAsync(owner.OwnerId);
                    }
                    catch (OwnerSettingsNotFoundException)
                    {
                        // no action needed
                    }
                    catch (OwnerSettingsStoreException e)
                    {
                        Log.Error($"Error deleting owner settings during user account {User.Identity.Name} deletion", e);
                    }

                    // datasets
                    try
                    {
                        await _datasetStore.DeleteDatasetsForOwnerAsync(User.Identity.Name);
                    }
                    catch (DatasetStoreException e)
                    {
                        Log.Error($"Error deleting datasets during user account {User.Identity.Name} deletion", e);
                    }

                    // templates
                    try
                    {
                        await _schemaStore.DeleteSchemaRecordsForOwnerAsync(User.Identity.Name);
                    }
                    catch (Exception e)
                    {
                        Log.Error($"Error deleting templates during user account {User.Identity.Name} deletion", e);
                    }

                    // jobs
                    try
                    {
                        await _jobStore.DeleteJobsForOwnerAsync(User.Identity.Name);
                    }
                    catch (Exception e)
                    {
                        Log.Error($"Error deleting jobs during user account {User.Identity.Name} deletion", e);
                    }


                    await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

                    return(RedirectToAction("Index", "Home"));
                }

                // error
                ViewBag.Message =
                    "Unable to delete account at this time, if the problem persists please open a ticket with support.";
                return(View("Delete"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Beispiel #24
0
            public void WhenPackagesNotSet_ReturnsFalse()
            {
                var viewModel = new DeleteAccountViewModel();

                Assert.False(viewModel.HasOrphanPackages);
            }
Beispiel #25
0
 public DeleteAccountPage()
 {
     InitializeComponent();
     _vm      = BindingContext as DeleteAccountViewModel;
     _vm.Page = this;
 }
Beispiel #26
0
 public Task <DeleteAccountResponse> DeleteAccountAsync(DeleteAccountViewModel deleteAccount)
 {
     throw new NotImplementedException();
 }
Beispiel #27
0
		public async Task<IActionResult> Delete(DeleteAccountViewModel request)
		{
			var result = await _mediator.SendAsync(request);

			return Json(result);
		}