示例#1
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            var sessid = Request.Cookies.Where(c => (c.Key == "sessid"));

            if (sessid.Count() == 0)
            {
                return(Redirect("/Login"));
            }
            var valid_sessions = _context.Session.Where(s => (s.ID == sessid.First().Value));

            if (valid_sessions.Count() == 0)
            {
                return(Redirect("/Login"));
            }

            _session = valid_sessions.First();

            if (_session.Role != UserRole.Admin)
            {
                return(Redirect("/Login"));
            }
            if (_session.Expires.CompareTo(DateTime.Now) <= 0)
            {
                _context.Session.Remove(_session);
                await _context.SaveChangesAsync();

                _session = null;
                return(Redirect("/Login"));
            }
            return(Page());
        }
示例#2
0
        public async Task <IActionResult> OnGetAsync()
        {
            _context.Session.RemoveRange(_context.Session.Where(s => (s.Expires.CompareTo(DateTime.Now) <= 0)));
            await _context.SaveChangesAsync();

            return(Page());
        }
示例#3
0
        public async Task OnGetAsync()
        {
            Session = new List <Session>();
            var sessid = Request.Cookies.Where(c => (c.Key == "sessid"));

            if (sessid.Count() == 0)
            {
                Redirect("/Login");
                return;
            }
            var valid_sessions = _context.Session.Where(s => (s.ID == sessid.First().Value));

            if (valid_sessions.Count() == 0)
            {
                Redirect("/Login");
                return;
            }

            _session = valid_sessions.First();
            if (_session.Role != UserRole.Admin)
            {
                Redirect("/Login");
                return;
            }
            if (_session.Expires.CompareTo(DateTime.Now) <= 0)
            {
                _context.Session.Remove(_session);
                await _context.SaveChangesAsync();

                _session = null;
                Redirect("/Login");
                return;
            }
            Session = await _context.Session.ToListAsync();
        }