<commit_before>using System;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using Joinrpg.Web.Identity;
using JoinRpg.Data.Interfaces;
using JoinRpg.Services.Interfaces.Notification;
using JoinRpg.Web.Helpers;
using JoinRpg.Web.Models;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security;

namespace JoinRpg.Web.Controllers
{
    [Authorize]
    public class AccountController : Common.ControllerBase
    {
        private readonly IEmailService _emailService;
        private ApplicationUserManager UserManager { get; }

        public AccountController(
            ApplicationUserManager userManager,
            ApplicationSignInManager signInManager,
            IEmailService emailService,
            IUserRepository userRepository
        ) : base(userRepository)
        {
            UserManager = userManager;
            SignInManager = signInManager;
            _emailService = emailService;
        }

        private ApplicationSignInManager SignInManager { get; }

        [AllowAnonymous]
        public ActionResult Login(string returnUrl)
        {
            return View(CreateLoginPageViewModel(returnUrl));
        }

        private LoginPageViewModel CreateLoginPageViewModel(string returnUrl)
        {
            return new LoginPageViewModel()
            {
                External = new ExternalLoginListViewModel
                {
                    ReturnUrl = returnUrl,
                    ExternalLogins = AuthenticationManager.GetExternalAuthenticationTypes().Select(ol => ol.ToViewModel()).ToList(),
                },
                Login = new LoginViewModel
                {
                    ReturnUrl = returnUrl,
                }
            };
        }

        //
        // POST: /Account/Login
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // Require the user to have a confirmed email before they can log on.
            var user = await UserManager.FindByNameAsync(model.Email);

            if (user != null)
            {
                if (!await UserManager.IsEmailConfirmedAsync(user.UserId))
                {
                    await SendConfirmationEmail(user);
                    return View("EmailUnconfirmed");
                }
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result =
                await SignInManager.PasswordSignInAsync(model.Email,
                    model.Password,
                    isPersistent: true,
                    shouldLockout: false);

            switch (result)
            {
                case SignInStatus.Success:
                    return RedirectToLocal(returnUrl);
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Не найден логин или пароль");
                    var vm = CreateLoginPageViewModel(returnUrl);
                    vm.Login.Email = model.Email;
                    return View();
            }
        }

        //
        // GET: /Account/Register
        [AllowAnonymous]<commit_msg>fix not passed model bug<commit_after>using System;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using Joinrpg.Web.Identity;
using JoinRpg.Data.Interfaces;
using JoinRpg.Services.Interfaces.Notification;
using JoinRpg.Web.Helpers;
using JoinRpg.Web.Models;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security;

namespace JoinRpg.Web.Controllers
{
    [Authorize]
    public class AccountController : Common.ControllerBase
    {
        private readonly IEmailService _emailService;
        private ApplicationUserManager UserManager { get; }

        public AccountController(
            ApplicationUserManager userManager,
            ApplicationSignInManager signInManager,
            IEmailService emailService,
            IUserRepository userRepository
        ) : base(userRepository)
        {
            UserManager = userManager;
            SignInManager = signInManager;
            _emailService = emailService;
        }

        private ApplicationSignInManager SignInManager { get; }

        [AllowAnonymous]
        public ActionResult Login(string returnUrl)
        {
            return View(CreateLoginPageViewModel(returnUrl));
        }

        private LoginPageViewModel CreateLoginPageViewModel(string returnUrl)
        {
            return new LoginPageViewModel()
            {
                External = new ExternalLoginListViewModel
                {
                    ReturnUrl = returnUrl,
                    ExternalLogins = AuthenticationManager.GetExternalAuthenticationTypes().Select(ol => ol.ToViewModel()).ToList(),
                },
                Login = new LoginViewModel
                {
                    ReturnUrl = returnUrl,
                }
            };
        }

        //
        // POST: /Account/Login
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // Require the user to have a confirmed email before they can log on.
            var user = await UserManager.FindByNameAsync(model.Email);

            if (user != null)
            {
                if (!await UserManager.IsEmailConfirmedAsync(user.UserId))
                {
                    await SendConfirmationEmail(user);
                    return View("EmailUnconfirmed");
                }
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result =
                await SignInManager.PasswordSignInAsync(model.Email,
                    model.Password,
                    isPersistent: true,
                    shouldLockout: false);

            switch (result)
            {
                case SignInStatus.Success:
                    return RedirectToLocal(returnUrl);
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Не найден логин или пароль");
                    var vm = CreateLoginPageViewModel(returnUrl);
                    vm.Login.Email = model.Email;
                    return View(vm);
            }
        }

        //
        // GET: /Account/Register
        [AllowAnonymous]
{'fraction_non_alphanumeric': 0.068304872969596, 'fraction_numerical': 0.0, 'mean_word_length': 1.6359312111233077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3818717', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1633, 'n_words': 383}