prevent self user deletion
All checks were successful
Build and Deploy API / build-and-deploy (push) Successful in 8s
All checks were successful
Build and Deploy API / build-and-deploy (push) Successful in 8s
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
|
||||||
using agologumApi.Models;
|
using agologumApi.Models;
|
||||||
using agologumApi.Services;
|
using agologumApi.Services;
|
||||||
@@ -64,12 +66,13 @@ public class UsersController : ControllerBase {
|
|||||||
[HttpDelete("{id}")]
|
[HttpDelete("{id}")]
|
||||||
public async Task<ActionResult> deleteUser(string 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);
|
var success = await service_.Delete(id);
|
||||||
|
|
||||||
if (!success) return NotFound();
|
if (!success) return NotFound();
|
||||||
|
|
||||||
// TODO: set safeguard to no delete the current user
|
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user