Exemplo n.º 1
0
        protected override void OnAuthentication(AuthenticationContext filterContext)
        {
            var cookies = filterContext.HttpContext.Request.Cookies;

            if (cookies[Cookies.B_ADMIN_LOGIN_TOKEN] == null)
            {
                filterContext.Result = RedirectToLoginPage(Request.Url.ToString());
                return;
            }

            // expired session
            var dangNhap = dangNhapRepository.CheckLogin(cookies[Cookies.B_ADMIN_LOGIN_TOKEN].Value, new TimeSpan(31, 0, 0, 0));

            if (dangNhap != null)
            {
                LoggedInUser = nguoiDungRepository.GetByID(dangNhap.NguoidungID);
                // update last_login
                dangNhap.Thoigiandangnhap = DateTime.Now;
                dangNhap.Solandangnhapsai = 0;
                adminUow.SubmitChanges();
            }

            if (LoggedInUser == null)
            {
                filterContext.Result = RedirectToLoginPage(Request.Url.ToString());
                return;
            }

            // cache
            RequestScope.LoggedInUser = LoggedInUser;

            base.OnAuthentication(filterContext);
        }