예제 #1
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 });
        }
예제 #2
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 });
        }