Can delete user

This commit is contained in:
nicolas.dorier
2017-12-04 14:39:02 +09:00
parent 45aee607e3
commit a52a1901c4
4 changed files with 40 additions and 2 deletions

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<Version>1.0.0.36</Version> <Version>1.0.0.37</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="Build\dockerfiles\**" /> <Compile Remove="Build\dockerfiles\**" />

View File

@@ -32,15 +32,50 @@ namespace BTCPayServer.Controllers
public IActionResult ListUsers() public IActionResult ListUsers()
{ {
var users = new UsersViewModel(); var users = new UsersViewModel();
users.StatusMessage = StatusMessage;
users.Users users.Users
= _UserManager.Users.Select(u => new UsersViewModel.UserViewModel() = _UserManager.Users.Select(u => new UsersViewModel.UserViewModel()
{ {
Name = u.UserName, Name = u.UserName,
Email = u.Email Email = u.Email,
Id = u.Id
}).ToList(); }).ToList();
return View(users); return View(users);
} }
[Route("server/users/{userId}/delete")]
public async Task<IActionResult> DeleteUser(string userId)
{
var user = userId == null ? null : await _UserManager.FindByIdAsync(userId);
if (user == null)
return NotFound();
return View("Confirm", new ConfirmModel()
{
Title = "Delete user " + user.Email,
Description = "This user will be permanently deleted",
Action = "Delete"
});
}
[Route("server/users/{userId}/delete")]
[HttpPost]
public async Task<IActionResult> DeleteUserPost(string userId)
{
var user = userId == null ? null : await _UserManager.FindByIdAsync(userId);
if (user == null)
return NotFound();
await _UserManager.DeleteAsync(user);
StatusMessage = "User deleted";
return RedirectToAction(nameof(ListUsers));
}
[TempData]
public string StatusMessage
{
get; set;
}
[Route("server/emails")] [Route("server/emails")]
public async Task<IActionResult> Emails() public async Task<IActionResult> Emails()
{ {

View File

@@ -9,6 +9,7 @@ namespace BTCPayServer.Models.ServerViewModels
{ {
public class UserViewModel public class UserViewModel
{ {
public string Id { get; set; }
public string Name public string Name
{ {
get; set; get; set;

View File

@@ -14,6 +14,7 @@
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Email</th> <th>Email</th>
<th>Actions</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -22,6 +23,7 @@
<tr> <tr>
<td>@user.Name</td> <td>@user.Name</td>
<td>@user.Email</td> <td>@user.Email</td>
<td><a asp-action="DeleteUser" asp-route-userId="@user.Id">Remove</a></td>
</tr>} </tr>}
</tbody> </tbody>
</table> </table>