This repository was archived by the owner on Dec 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 858
Add Manage/Privacy-Delete/Download functionality #1559
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d310c02
Add Privacy-Delete/Download
HaoK 13f5b28
Cleanup
HaoK 6d17a2e
Cleanup
HaoK 662a966
UI tweaks
HaoK 36528e9
Add password to DeletePersonalData, whitelist dl
HaoK c0b2141
Cleanup
HaoK 5adcf3f
Fix redirect
HaoK aa1fc6c
Force download prompt
HaoK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/UI/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
@page | ||
@model DeletePersonalDataModel | ||
@{ | ||
ViewData["Title"] = "Delete Personal Data"; | ||
ViewData["ActivePage"] = ManageNavPages.DeletePersonalData; | ||
} | ||
|
||
<h4>@ViewData["Title"]</h4> | ||
|
||
<div class="alert alert-warning" role="alert"> | ||
<p> | ||
<span class="glyphicon glyphicon-warning-sign"></span> | ||
<strong>Deleting this data will permanently remove your account, and this cannot be recovered.</strong> | ||
</p> | ||
</div> | ||
|
||
<div> | ||
<form method="post" class="form-group"> | ||
<div asp-validation-summary="All" class="text-danger"></div> | ||
@if (Model.RequirePassword) | ||
{ | ||
<div class="form-group"> | ||
<label asp-for="Input.Password"></label> | ||
<input asp-for="Input.Password" class="form-control" /> | ||
<span asp-validation-for="Input.Password" class="text-danger"></span> | ||
</div> | ||
} | ||
<button class="btn btn-danger" type="submit">Delete data and close my account</button> | ||
</form> | ||
</div> | ||
|
||
@section Scripts { | ||
<partial name="_ValidationScriptsPartial" /> | ||
} |
84 changes: 84 additions & 0 deletions
84
src/UI/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.AspNetCore.Identity.UI.Pages.Account.Manage | ||
{ | ||
public class DeletePersonalDataModel : PageModel | ||
{ | ||
private readonly UserManager<IdentityUser> _userManager; | ||
private readonly SignInManager<IdentityUser> _signInManager; | ||
private readonly ILogger<DeletePersonalDataModel> _logger; | ||
|
||
public DeletePersonalDataModel( | ||
UserManager<IdentityUser> userManager, | ||
SignInManager<IdentityUser> signInManager, | ||
ILogger<DeletePersonalDataModel> logger) | ||
{ | ||
_userManager = userManager; | ||
_signInManager = signInManager; | ||
_logger = logger; | ||
} | ||
|
||
[BindProperty] | ||
public InputModel Input { get; set; } | ||
|
||
public class InputModel | ||
{ | ||
[Required] | ||
[DataType(DataType.Password)] | ||
public string Password { get; set; } | ||
} | ||
|
||
public bool RequirePassword { get; set; } | ||
|
||
public async Task<IActionResult> OnGet() | ||
{ | ||
var user = await _userManager.GetUserAsync(User); | ||
if (user == null) | ||
{ | ||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); | ||
} | ||
|
||
RequirePassword = await _userManager.HasPasswordAsync(user); | ||
return Page(); | ||
} | ||
|
||
public async Task<IActionResult> OnPostAsync() | ||
{ | ||
var user = await _userManager.GetUserAsync(User); | ||
if (user == null) | ||
{ | ||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); | ||
} | ||
|
||
RequirePassword = await _userManager.HasPasswordAsync(user); | ||
if (RequirePassword) | ||
{ | ||
if (!await _userManager.CheckPasswordAsync(user, Input.Password)) | ||
{ | ||
ModelState.AddModelError(string.Empty, "Password not correct."); | ||
return Page(); | ||
} | ||
} | ||
|
||
var result = await _userManager.DeleteAsync(user); | ||
if (!result.Succeeded) | ||
{ | ||
throw new InvalidOperationException($"Unexpected error occurred deleteing user with ID '{user.Id}'."); | ||
} | ||
|
||
await _signInManager.SignOutAsync(); | ||
|
||
_logger.LogInformation("User with ID '{UserId}' deleted themselves.", _userManager.GetUserId(User)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it ok to log the userId as is (as this can be the email address, which is PII) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The UserName is the email, the user id is a guid by default, but this is the pattern the existing templates use for logging I believe. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
|
||
return Redirect("~/"); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/UI/Areas/Identity/Pages/Account/Manage/DownloadPersonalData.cshtml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@page | ||
@model DownloadPersonalDataModel | ||
@{ | ||
ViewData["Title"] = "Download Your Data"; | ||
ViewData["ActivePage"] = ManageNavPages.DownloadPersonalData; | ||
} | ||
|
||
<h4>@ViewData["Title"]</h4> | ||
|
||
@section Scripts { | ||
<partial name="_ValidationScriptsPartial" /> | ||
} |
51 changes: 51 additions & 0 deletions
51
src/UI/Areas/Identity/Pages/Account/Manage/DownloadPersonalData.cshtml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.Extensions.Logging; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.AspNetCore.Identity.UI.Pages.Account.Manage | ||
{ | ||
public class DownloadPersonalDataModel : PageModel | ||
{ | ||
private readonly UserManager<IdentityUser> _userManager; | ||
private readonly ILogger<DownloadPersonalDataModel> _logger; | ||
|
||
public DownloadPersonalDataModel( | ||
UserManager<IdentityUser> userManager, | ||
ILogger<DownloadPersonalDataModel> logger) | ||
{ | ||
_userManager = userManager; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<IActionResult> OnPostAsync() | ||
{ | ||
var user = await _userManager.GetUserAsync(User); | ||
if (user == null) | ||
{ | ||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); | ||
} | ||
|
||
_logger.LogInformation("User with ID '{UserId}' asked for their personal data.", _userManager.GetUserId(User)); | ||
|
||
// Only include personal data for download | ||
var personalData = new Dictionary<string, string>(); | ||
personalData.Add("UserId", await _userManager.GetUserIdAsync(user)); | ||
personalData.Add("UserName", await _userManager.GetUserNameAsync(user)); | ||
personalData.Add("Email", await _userManager.GetEmailAsync(user)); | ||
personalData.Add("EmailConfirmed", (await _userManager.IsEmailConfirmedAsync(user)).ToString()); | ||
personalData.Add("PhoneNumber", await _userManager.GetPhoneNumberAsync(user)); | ||
personalData.Add("PhoneNumberConfirmed", (await _userManager.IsEmailConfirmedAsync(user)).ToString()); | ||
|
||
Response.Headers.Add("Content-Disposition", "attachment; filename=PersonalData.json"); | ||
return new FileContentResult(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(personalData)), "text/json"); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/UI/Areas/Identity/Pages/Account/Manage/PersonalData.cshtml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@page | ||
@model PersonalDataModel | ||
@{ | ||
ViewData["Title"] = "Personal Data"; | ||
ViewData["ActivePage"] = ManageNavPages.PersonalData; | ||
} | ||
|
||
<h4>@ViewData["Title"]</h4> | ||
|
||
<div class="row"> | ||
<div class="col-md-6"> | ||
<p>Your account contains personal data that you have given us. This page allows you to download or delete that data.</p> | ||
<p> | ||
<strong>Deleting this data will permanently remove your account, and this cannot be recovered.</strong> | ||
</p> | ||
<form asp-page="DownloadPersonalData" method="post" class="form-group"> | ||
<button class="btn btn-default" type="submit">Download</button> | ||
</form> | ||
<p> | ||
<a asp-page="DeletePersonalData" class="btn btn-default">Delete</a> | ||
</p> | ||
</div> | ||
</div> | ||
|
||
@section Scripts { | ||
<partial name="_ValidationScriptsPartial" /> | ||
} |
35 changes: 35 additions & 0 deletions
35
src/UI/Areas/Identity/Pages/Account/Manage/PersonalData.cshtml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.AspNetCore.Identity.UI.Pages.Account.Manage | ||
{ | ||
public class PersonalDataModel : PageModel | ||
{ | ||
private readonly UserManager<IdentityUser> _userManager; | ||
private readonly ILogger<PersonalDataModel> _logger; | ||
|
||
public PersonalDataModel( | ||
UserManager<IdentityUser> userManager, | ||
ILogger<PersonalDataModel> logger) | ||
{ | ||
_userManager = userManager; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<IActionResult> OnGet() | ||
{ | ||
var user = await _userManager.GetUserAsync(User); | ||
if (user == null) | ||
{ | ||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); | ||
} | ||
|
||
return Page(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AddModelError("Input.Password",
) if we'd like to show error along the password field.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error shows up at the top in the summary and at the bottom (below the password field) with this change so I think i'll leave it as is, so its only shown at the top