aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-05-08 18:46:46 +0300
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-05-08 18:46:46 +0300
commitead0edec370483e5e80d42cc49c67f13e28c13b1 (patch)
tree37025a036c3ad8e6c6cc57315de88c3c003fdd0a
parent0714b1c3091114d3089ea094e68d57d6a553066b (diff)
downloadit-kariera-exam-template-ead0edec370483e5e80d42cc49c67f13e28c13b1.tar
it-kariera-exam-template-ead0edec370483e5e80d42cc49c67f13e28c13b1.tar.gz
it-kariera-exam-template-ead0edec370483e5e80d42cc49c67f13e28c13b1.zip
Implemented account deletion
-rw-r--r--ExamTemplate/Services/UserService.cs8
-rw-r--r--ExamTemplate/Web/Controllers/AccountController.cs16
-rw-r--r--ExamTemplate/Web/Views/Account/Profile.cshtml4
3 files changed, 23 insertions, 5 deletions
diff --git a/ExamTemplate/Services/UserService.cs b/ExamTemplate/Services/UserService.cs
index 2f137a1..8e5c682 100644
--- a/ExamTemplate/Services/UserService.cs
+++ b/ExamTemplate/Services/UserService.cs
@@ -77,6 +77,14 @@ namespace ExamTemplate.Services
return result.Succeeded;
}
+ public async Task<bool> DeleteUserAsync(ClaimsPrincipal claimsPrincipal)
+ {
+ User user = await this._userManager.GetUserAsync(claimsPrincipal);
+
+ IdentityResult result = await this._userManager.DeleteAsync(user);
+ return result.Succeeded;
+ }
+
public bool IsSignedIn(ClaimsPrincipal claimsPrincipal)
{
return this._signInManager.IsSignedIn(claimsPrincipal);
diff --git a/ExamTemplate/Web/Controllers/AccountController.cs b/ExamTemplate/Web/Controllers/AccountController.cs
index d56d3df..373dd4b 100644
--- a/ExamTemplate/Web/Controllers/AccountController.cs
+++ b/ExamTemplate/Web/Controllers/AccountController.cs
@@ -131,10 +131,16 @@ namespace ExamTemplate.Web.Controllers
return RedirectToAction("Profile", new { username = loggedInUser.Username });
}
- // [HttpPost]
- // public async Task<IActionResult> DeleteProfile(string username)
- // {
- // throw new System.NotImplementedException();
- // }
+ [HttpPost]
+ public async Task<IActionResult> Delete()
+ {
+ await this._userService.LogoutAsync();
+ bool result = await this._userService.DeleteUserAsync(HttpContext.User);
+
+ if (result)
+ return RedirectToAction("Login");
+ else
+ return RedirectToAction("Index", "Home");
+ }
}
}
diff --git a/ExamTemplate/Web/Views/Account/Profile.cshtml b/ExamTemplate/Web/Views/Account/Profile.cshtml
index c6f3e5c..6decb79 100644
--- a/ExamTemplate/Web/Views/Account/Profile.cshtml
+++ b/ExamTemplate/Web/Views/Account/Profile.cshtml
@@ -22,6 +22,10 @@
<form asp-controller="Account" asp-action="Edit" method="get">
<input type="submit" value="Edit Profile">
</form>
+
+ <form asp-controller="Account" asp-action="Delete" method="post">
+ <input type="submit" value="Delete Profile">
+ </form>
}
}
</p>