2016-11-03 18:49:19 +08:00
|
|
|
|
using Bootstrap.DataAccess;
|
|
|
|
|
using Longbow.Web.Mvc;
|
|
|
|
|
using System;
|
2016-11-17 12:37:24 +08:00
|
|
|
|
using System.Collections.Generic;
|
2016-11-03 18:49:19 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
|
|
|
|
|
class BAAuthorizeAttribute : LgbAuthorizeAttribute
|
|
|
|
|
{
|
2016-11-17 12:37:24 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="userName"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected override IEnumerable<string> RetrieveRolesByUserName(string userName)
|
2016-11-03 18:49:19 +08:00
|
|
|
|
{
|
2016-11-17 12:37:24 +08:00
|
|
|
|
return RoleHelper.RetrieveRolesByUserName(userName).Select(r => r.RoleName);
|
2016-11-03 18:49:19 +08:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2016-11-17 12:37:24 +08:00
|
|
|
|
/// <param name="url"></param>
|
2016-11-03 18:49:19 +08:00
|
|
|
|
/// <returns></returns>
|
2016-11-17 12:37:24 +08:00
|
|
|
|
protected override IEnumerable<string> RetrieveRolesByUrl(string url)
|
2016-11-03 18:49:19 +08:00
|
|
|
|
{
|
2016-11-17 12:37:24 +08:00
|
|
|
|
return RoleHelper.RetrieveRolesByUrl(url).Select(r => r.RoleName);
|
2016-11-03 18:49:19 +08:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="filterContext"></param>
|
|
|
|
|
protected override void HandleUnauthorizedRequest(System.Web.Mvc.AuthorizationContext filterContext)
|
|
|
|
|
{
|
|
|
|
|
if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
|
|
|
|
|
{
|
|
|
|
|
base.HandleUnauthorizedRequest(filterContext);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var view = new ViewResult();
|
|
|
|
|
view.ViewName = "UnAuthorized";
|
|
|
|
|
filterContext.Result = view;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-21 16:35:26 +08:00
|
|
|
|
}
|