vgquotes/Src/VideoGameQuotes.Web/Security/IsValidUserAttribute.cs
tmont b45c82e5fa * quote editing, although not quite finished
* flag dismissal
* fixed some mapping issues by adding inverse="true" to some one-to-many relationships
2011-02-19 09:41:09 +00:00

31 lines
910 B
C#

using System.Net;
using System.Web.Mvc;
using Portoa.Web;
using Portoa.Web.ErrorHandling;
using VideoGameQuotes.Api;
namespace VideoGameQuotes.Web.Security {
[NeedsBuildUp]
public class IsValidUserAttribute : ActionFilterAttribute {
public IsValidUserAttribute() {
Group = UserGroup.User;
}
public ICurrentUserProvider UserProvider { get; set; }
public UserGroup Group { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext) {
var allowedToExecuteAction = UserProvider != null
&& UserProvider.CurrentUser != null
&& UserProvider.CurrentUser.Group >= Group;
if (!allowedToExecuteAction) {
filterContext.Result = new ErrorViewResult {
Message = "You are not a verified user (are you hiding your IP address?)",
StatusCode = HttpStatusCode.Forbidden,
ViewName = "Forbidden"
};
}
}
}
}