docker files fixes from liaqat
This commit is contained in:
35
src/Managing.Api/Controllers/BaseController.cs
Normal file
35
src/Managing.Api/Controllers/BaseController.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Domain.Users;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Managing.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
[Produces("application/json")]
|
||||
public abstract class BaseController : ControllerBase
|
||||
{
|
||||
private readonly IUserService _userService;
|
||||
|
||||
public BaseController(IUserService userService)
|
||||
{
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
protected async Task<User> GetUser()
|
||||
{
|
||||
var identity = HttpContext?.User.Identity as ClaimsIdentity;
|
||||
if (identity != null)
|
||||
{
|
||||
var address = identity.Claims.FirstOrDefault(c => c.Type == "address").Value;
|
||||
var user = await _userService.GetUserByAddressAsync(address);
|
||||
|
||||
if (user != null)
|
||||
return user;
|
||||
|
||||
throw new Exception("User not found for this token");
|
||||
}
|
||||
throw new Exception("Not identity assigned to this token");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user