<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using CompetitionPlatform.Data.AzureRepositories.Users;
using CompetitionPlatform.Models;
using Microsoft.AspNetCore.Http.Authentication;
using Microsoft.AspNetCore.Http.Authentication.Internal;
using Microsoft.AspNetCore.Mvc;

namespace CompetitionPlatform.Controllers
{
    public class UsersController : Controller
    {
        private readonly IUsersRepository _usersRepository;

        public UsersController(IUsersRepository usersRepository)
        {
            _usersRepository = usersRepository;
        }

        [HttpPost]
        public async Task<ActionResult> Authenticate(AuthenticateModel data)
        {
            var user = await _usersRepository.AuthenticateAsync(data.Username, data.Password);
            SignIn(user);

            return null;
        }

        private void SignIn(IUser user)
        {
            var authManager = HttpContext.Authentication;

            var identity = MakeIdentity(user);

            authManager.SignInAsync("MyCookieMiddlewareInstance", identity, new AuthenticationProperties { IsPersistent = false });
        }

        private static ClaimsPrincipal MakeIdentity(IUser user)
        {
            var claims = new List<Claim>
            {
                new Claim(ClaimTypes.Name, user.Id),
                new Claim(ClaimTypes.Email, user.Id)
            };
            
            var identity = new ClaimsIdentity(claims, "ApplicationCookie");

            var principalIdentity = new ClaimsPrincipal(identity);

            return principalIdentity;
        }

        public IActionResult Index()
        {
            return View();
        }
    }
}<commit_msg>Changed authentication Model.<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using CompetitionPlatform.Data.AzureRepositories.Users;
using CompetitionPlatform.Models;
using Microsoft.AspNetCore.Http.Authentication;
using Microsoft.AspNetCore.Http.Authentication.Internal;
using Microsoft.AspNetCore.Mvc;

namespace CompetitionPlatform.Controllers
{
    public static class UsersControllerExtension
    {
        public static string SessionCookie => "Session";

        public static string GetSession(this Controller contr)
        {
            var sessionCookie = contr.HttpContext.Request.Cookies[SessionCookie];
            if (sessionCookie != null)
                return sessionCookie;

            var sessionId = Guid.NewGuid().ToString();
            //var newCookie = new HttpCookie(SessionCookie, sessionId) { Expires = DateTime.UtcNow.AddYears(5) };
            //contr.Response.SetCookie(newCookie);
            return sessionId;
        }
    }

    public class UsersController : Controller
    {
        private readonly IUsersRepository _usersRepository;

        public UsersController(IUsersRepository usersRepository)
        {
            _usersRepository = usersRepository;
        }

        [HttpPost]
        public async Task<ActionResult> Authenticate(AuthenticateModel data)
        {
            var user = await _usersRepository.AuthenticateAsync(data.FullName, data.Password);
            SignIn(user);
            var authenticated = User.Identity.IsAuthenticated;
            return View("~/Views/Home/Index.cshtml");
        }

        private void SignIn(IUser user)
        {
            var authManager = HttpContext.Authentication;

            var identity = MakeIdentity(user);

            authManager.SignInAsync("MyCookieMiddlewareInstance", identity, new AuthenticationProperties { IsPersistent = false });
        }

        private static ClaimsPrincipal MakeIdentity(IUser user)
        {
            var claims = new List<Claim>
            {
                new Claim(ClaimTypes.Name, user.Id),
                new Claim(ClaimTypes.Email, user.Id)
            };

            var identity = new ClaimsIdentity(claims, "ApplicationCookie");

            var principalIdentity = new ClaimsPrincipal(identity);

            return principalIdentity;
        }



        public IActionResult Index()
        {
            return View();
        }
    }
}
{'fraction_non_alphanumeric': 0.07546728971962617, 'fraction_numerical': 0.00023364485981308412, 'mean_word_length': 2.4003177124702146, 'pattern_counts': {'":': 0, '<': 7, '<?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': '673060', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1000, 'n_words': 233}