Files
yavsc/Yavsc/AuthorizationHandlers/BlogEditHandler.cs
2018-07-16 02:36:44 +02:00

19 lines
660 B
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNet.Authorization;
using System.Security.Claims;
using Yavsc.Models.Blog;
namespace Yavsc.ViewModels.Auth.Handlers
{
public class BlogEditHandler : AuthorizationHandler<EditRequirement, BlogPost>
{
protected override void Handle(AuthorizationContext context, EditRequirement requirement, BlogPost resource)
{
if (context.User.IsInRole(Constants.BlogModeratorGroupName))
context.Succeed(requirement);
else if (context.User.Identity.IsAuthenticated)
if (resource.AuthorId == context.User.GetUserId())
context.Succeed(requirement);
}
}
}