<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Identity;
using AspnetIdentitySample.Models;
using System.Security.Claims;
using Microsoft.Extensions.DependencyInjection;

namespace AspnetIdentitySample.CurrentUser
{
    // You may need to install the Microsoft.AspNet.Http.Abstractions package into your project
    public class CurrentUserMiddleware
    {
        private readonly RequestDelegate _next;

        public CurrentUserMiddleware(RequestDelegate next)
        {
            _next = next;
        }

        public async Task<Task> Invoke(HttpContext httpContext, ICurrentUserService cus, UserManager<ApplicationUser> um)
        {
            if (httpContext.User.Identity.IsAuthenticated)
            {
                ApplicationUser au = await um.FindByIdAsync(httpContext.User.GetUserId());
                await cus.Set(au);
            }
            return _next(httpContext);
        }
    }

    // Extension method used to add the middleware to the HTTP request pipeline.
    public static class CurrentUserExtensions
    {
        public static IApplicationBuilder SetCurrentUser(this IApplicationBuilder builder)
        {
            return builder.UseMiddleware<CurrentUserMiddleware>();
        }
    }
}<commit_msg>fixed whitescreen error in middleware on registration<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Identity;
using AspnetIdentitySample.Models;
using System.Security.Claims;
using Microsoft.Extensions.DependencyInjection;

namespace AspnetIdentitySample.CurrentUser
{
    // You may need to install the Microsoft.AspNet.Http.Abstractions package into your project
    public class CurrentUserMiddleware
    {
        private readonly RequestDelegate _next;

        public CurrentUserMiddleware(RequestDelegate next)
        {
            _next = next;
        }

        public async Task Invoke(HttpContext httpContext, ICurrentUserService cus, UserManager<ApplicationUser> um)
        {
            if (httpContext.User.Identity.IsAuthenticated)
            {
                ApplicationUser au = await um.FindByIdAsync(httpContext.User.GetUserId());
                await cus.Set(au);
            }
            await _next(httpContext);
        }
    }

    // Extension method used to add the middleware to the HTTP request pipeline.
    public static class CurrentUserExtensions
    {
        public static IApplicationBuilder SetCurrentUser(this IApplicationBuilder builder)
        {
            return builder.UseMiddleware<CurrentUserMiddleware>();
        }
    }
}
{'fraction_non_alphanumeric': 0.06669031571479248, 'fraction_numerical': 0.0, 'mean_word_length': 2.900414937759336, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1563070', 'n_tokens_mistral': 686, 'n_tokens_neox': 695, 'n_words': 182}