Feature/Auth: last one was authentication, this one is authorization #4
@@ -6,6 +6,8 @@
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
using agologumApi.Models;
|
||||
using agologumApi.Services;
|
||||
@@ -64,12 +66,13 @@ public class UsersController : ControllerBase {
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<ActionResult> deleteUser(string id) {
|
||||
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if(userId == id) return BadRequest(); // dont allow deletion of yourself
|
||||
|
||||
var success = await service_.Delete(id);
|
||||
|
||||
if (!success) return NotFound();
|
||||
|
||||
// TODO: set safeguard to no delete the current user
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user