Added a new policy to require being an admin. Implemented ability to delete a user.
This commit is contained in:
parent
bb276a5984
commit
f0919042b0
6 changed files with 44 additions and 5 deletions
|
|
@ -26,10 +26,18 @@ namespace API.Controllers
|
|||
}
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpDelete]
|
||||
[HttpDelete("delete-user")]
|
||||
public async Task<ActionResult> DeleteUser(string username)
|
||||
{
|
||||
return BadRequest("Not Implemented");
|
||||
var user = await _userRepository.GetUserByUsernameAsync(username);
|
||||
_userRepository.Delete(user);
|
||||
|
||||
if (await _userRepository.SaveAllAsync())
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
return BadRequest("Could not delete the user.");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue