2011-02-12 23:53:43 +00:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
using Portoa.Web;
|
|
|
|
|
using Portoa.Web.ErrorHandling;
|
|
|
|
|
using VideoGameQuotes.Api;
|
|
|
|
|
|
|
|
|
|
namespace VideoGameQuotes.Web.Security {
|
|
|
|
|
[NeedsBuildUp]
|
2011-02-21 23:59:06 +00:00
|
|
|
|
public class VerifyUserAttribute : ActionFilterAttribute {
|
|
|
|
|
public VerifyUserAttribute() {
|
2011-02-12 23:53:43 +00:00
|
|
|
|
Group = UserGroup.User;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 23:59:06 +00:00
|
|
|
|
public ICurrentUserProvider<User> UserProvider { get; set; }
|
2011-02-12 23:53:43 +00:00
|
|
|
|
public UserGroup Group { get; set; }
|
|
|
|
|
|
|
|
|
|
public override void OnActionExecuting(ActionExecutingContext filterContext) {
|
|
|
|
|
var allowedToExecuteAction = UserProvider != null
|
|
|
|
|
&& UserProvider.CurrentUser != null
|
2011-02-19 09:41:09 +00:00
|
|
|
|
&& UserProvider.CurrentUser.Group >= Group;
|
2011-02-12 23:53:43 +00:00
|
|
|
|
|
|
|
|
|
if (!allowedToExecuteAction) {
|
|
|
|
|
filterContext.Result = new ErrorViewResult {
|
|
|
|
|
Message = "You are not a verified user (are you hiding your IP address?)",
|
|
|
|
|
StatusCode = HttpStatusCode.Forbidden,
|
|
|
|
|
ViewName = "Forbidden"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|