Пример #1
0
        public Task InvokeAsync(HttpContext context)
        {
            var credential = CookieUtils.Get(context, "login");

            context.Items["loginId"] = credential == null ? 0 : LoggedUsers.Forward[credential];

            return(next(context));
        }
Пример #2
0
        /// <summary>
        /// Procedura logująca użytkownika. Tworzy identyfikator sesji i go zapisuje
        /// </summary>
        public static bool LogUser(HttpContext context, int userId)
        {
            if (LoggedUsers.ContainsValue(userId))
            {
                return(false);
            }

            var guid = CreateCryptographicallySecureGuid().ToString();

            LoggedUsers.Add(guid, userId);
            Statuses.Add(userId, Status.Available);
            CookieUtils.Set(context, "login", guid);
            return(true);
        }