Added a new policy to require being an admin. Implemented ability to delete a user.

This commit is contained in:
Joseph Milazzo 2020-12-24 08:13:58 -06:00
parent bb276a5984
commit f0919042b0
6 changed files with 44 additions and 5 deletions

View file

@ -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.");
}