refactoring & pv authorization
This commit is contained in:
parent
92fc6c6c95
commit
5a08e29d11
16 changed files with 2992 additions and 49 deletions
|
|
@ -3,8 +3,9 @@
|
|||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Yavsc.Interfaces;
|
||||
using Yavsc.ViewModels.Auth;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
namespace Yavsc.AuthorizationHandlers
|
||||
{
|
||||
public class AnnouceEditHandler : AuthorizationHandler<EditRequirement, IOwned>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Yavsc.ViewModels.Auth;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
namespace Yavsc.AuthorizationHandlers
|
||||
{
|
||||
using Billing;
|
||||
public class BillEditHandler : AuthorizationHandler<EditRequirement, IBillable>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Yavsc.ViewModels.Auth;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
namespace Yavsc.AuthorizationHandlers
|
||||
{
|
||||
using Billing;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
using Microsoft.AspNet.Authorization;
|
||||
using System.Security.Claims;
|
||||
using Yavsc.Models.Blog;
|
||||
using Yavsc.ViewModels.Auth;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
namespace Yavsc.AuthorizationHandlers
|
||||
{
|
||||
public class BlogEditHandler : AuthorizationHandler<EditRequirement, BlogPost>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ using System.Linq;
|
|||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Yavsc.Models.Blog;
|
||||
using Yavsc.ViewModels.Auth;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
namespace Yavsc.AuthorizationHandlers
|
||||
{
|
||||
public class BlogViewHandler : AuthorizationHandler<ViewRequirement, BlogPost>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.AspNet.Authorization;
|
||||
using Yavsc.ViewModels.Auth;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
namespace Yavsc.AuthorizationHandlers
|
||||
{
|
||||
public class HasBadgeHandler : AuthorizationHandler<PrivateChatEntryRequirement>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Yavsc.ViewModels.Auth;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
namespace Yavsc.AuthorizationHandlers
|
||||
{
|
||||
public class HasTemporaryPassHandler : AuthorizationHandler<PrivateChatEntryRequirement>
|
||||
{
|
||||
|
|
@ -24,4 +25,4 @@ namespace Yavsc.ViewModels.Auth.Handlers
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Yavsc.ViewModel.Auth;
|
||||
using Yavsc.ViewModels.Auth;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
namespace Yavsc.AuthorizationHandlers
|
||||
{
|
||||
public class PostUserFileHandler : AuthorizationHandler<EditRequirement, FileSpotInfo>
|
||||
{
|
||||
|
|
|
|||
34
src/Yavsc/AuthorizationHandlers/SendMessageHandler.cs
Normal file
34
src/Yavsc/AuthorizationHandlers/SendMessageHandler.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.ViewModels.Auth;
|
||||
using System.Linq;
|
||||
|
||||
namespace Yavsc.AuthorizationHandlers
|
||||
{
|
||||
public class SendMessageHandler : AuthorizationHandler<PrivateChatEntryRequirement, string>
|
||||
{
|
||||
ApplicationDbContext _dbContext ;
|
||||
|
||||
public SendMessageHandler(ApplicationDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
protected override void Handle(AuthorizationContext context, PrivateChatEntryRequirement requirement, string destUserId)
|
||||
{
|
||||
var uid = context.User.GetUserId();
|
||||
if (context.User.IsInRole(Constants.BlogModeratorGroupName)
|
||||
|| context.User.IsInRole(Constants.AdminGroupName))
|
||||
context.Succeed(requirement);
|
||||
else if (!context.User.Identity.IsAuthenticated)
|
||||
context.Fail();
|
||||
else if (destUserId == uid)
|
||||
context.Succeed(requirement);
|
||||
else if (_dbContext.Banlist.Any(b=>b.TargetId == uid)) context.Fail();
|
||||
else if (_dbContext.BlackListed.Any(b=>b.OwnerId == destUserId && b.UserId == uid)) context.Fail();
|
||||
else context.Succeed(requirement);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.AspNet.Authorization;
|
||||
using Yavsc.ViewModels.Auth;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
namespace Yavsc.AuthorizationHandlers
|
||||
{
|
||||
public class ViewFileHandler : AuthorizationHandler<ViewRequirement, ViewFileContext>
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue