using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Net.Http;
|
using System.Web;
|
using System.Web.Http.Filters;
|
using Pcb.Business;
|
using Pcb.Business.Authentication;
|
//using Pcb.Business.Biz;
|
using Pcb.Business.BizCore.BizMemberLoginLog.Interfaces;
|
using Pcb.Common;
|
using Pcb.Domain;
|
using Pcb.Infrastructure.Ioc;
|
|
namespace Pcb.Api.Infrastructures
|
{
|
/// <summary>
|
/// 授权验证拦截器
|
/// </summary>
|
public class AuthorizeInterceptAttribute : AuthorizationFilterAttribute
|
{
|
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
|
{
|
base.OnAuthorization(actionContext);
|
var apiMember = WebAuthenticationContext.AppAuthenticationUser;
|
if (apiMember == null || !apiMember.IsAuthenticated)
|
actionContext.Response = Response("请先登录!");
|
else
|
IocContainerManager.Container.Resolve<IMemberLoginLogApiBiz>().RecordMemberLoginLog(new MemberLoginLog() { DataFrom = apiMember.ReqFrom, MemberId = apiMember.UserId, AutoLogin = true }, apiMember.Account);
|
//new MemberLoginLogBiz().RecordMemberLoginLog(new MemberLoginLog() {DataFrom = apiMember.ReqFrom, MemberId = apiMember.UserId, AutoLogin = true}, apiMember.Account);
|
}
|
|
private HttpResponseMessage Response(string content)
|
{
|
return new HttpResponseMessage() { StatusCode = System.Net.HttpStatusCode.Unauthorized, Content = new StringContent(content) };
|
}
|
}
|
}
|