protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, ClubAdminOrSelfRequirement requirement) { var routeData = _httpContextAccessor.HttpContext !.GetRouteData(); if (routeData != null) { var emailFromRoute = await AuthTools.GetEmail(routeData, mediator); var email = context.User.GetEmailAddress(); if (emailFromRoute == email) { context.Succeed(requirement); } } }
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, ClubAdminRequirement requirement) { var routeData = _httpContextAccessor.HttpContext !.GetRouteData(); if (routeData != null) { var eventId = AuthTools.GetEventId(routeData); var @event = await mediator.Send(new GetEvent(eventId), CancellationToken.None); if (@event == null) { // new event context.Succeed(requirement); return; } var club = await mediator.Send(new GetClub(@event.ClubId)); if (club == null) { throw new NullReferenceException(nameof(club)); } var emails = club.AdminEmails.Select(b => b.Email); var email = context.User.GetEmailAddress(); if (emails.Contains(email)) { context.Succeed(requirement); } else { context.Fail(); } } else { context.Fail(); } }