| | | 1 | | using Microsoft.AspNetCore.Authorization; |
| | | 2 | | using Microsoft.AspNetCore.Mvc; |
| | | 3 | | using Microsoft.AspNetCore.RateLimiting; |
| | | 4 | | using OzonOrdersWeb.Extensions; |
| | | 5 | | using Services.Authorization; |
| | | 6 | | |
| | | 7 | | namespace OzonOrdersWeb.Areas.Admin.Controllers; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Базовый класс для всех контроллеров Admin Area. |
| | | 11 | | /// Требует авторизации и доступен только пользователям с системной ролью SuperAdmin. |
| | | 12 | | /// </summary> |
| | | 13 | | [Area("Admin")] |
| | | 14 | | [Authorize(Roles = AuthorizationConstants.SuperAdminRoleName + ",Admin")] |
| | | 15 | | [Route("Admin/[controller]/[action]/{id?}")] |
| | | 16 | | [EnableRateLimiting(AuthorizationExtensions.AdminRateLimitPolicy)] |
| | | 17 | | public abstract class AdminAreaControllerBase : Controller |
| | | 18 | | { |
| | | 19 | | protected string CurrentUserId => |
| | 0 | 20 | | User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value ?? string.Empty; |
| | | 21 | | |
| | | 22 | | protected bool IsSuperAdmin => |
| | 0 | 23 | | User.HasClaim(c => c.Type == "app_is_super_admin" && c.Value == "true") || |
| | 0 | 24 | | User.IsInRole(AuthorizationConstants.SuperAdminRoleName); |
| | | 25 | | } |