wyb
2021-05-11 49ce087bd2a34a150597e1cc1da157af242c0b6d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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) };
        }
    }
}