<commit_before>﻿// -----------------------------------------------------------------------
// <copyright file="AccountController.cs" company="<NAME>">
// Copyright (c) <NAME>. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace Dub.Web.Mvc.Controllers.Api
{
    using System.Threading.Tasks;
#if !NETCORE
    using System.Web.Http;
#else
    using System.Linq;
#endif
    using Dub.Web.Core;
    using Dub.Web.Identity;
    using Dub.Web.Mvc.Models.Account;
    using Microsoft.AspNet.Identity;
#if !NETCORE
    using Microsoft.AspNet.Identity.Owin;
#endif
#if NETCORE
    using Microsoft.AspNet.Mvc;
#endif
#if !NETCORE
    using Microsoft.Owin.Security;
    using IActionResult = System.Web.Http.IHttpActionResult;
#endif

    /// <summary>
    /// API Account controller.
    /// </summary>
    /// <typeparam name="TUser">Type of the user.</typeparam>
    /// <typeparam name="TSignInManager">Type of sign in manager used.</typeparam>
    /// <typeparam name="TUserManager">Type of user manager used to manage the users.</typeparam>
    public class AccountController<TUser, TSignInManager, TUserManager> : ApiControllerBase
        where TUser : DubUser, new()
#if NETCORE
        where TSignInManager : SignInManager<TUser>
        where TUserManager : UserManager<TUser>
#else
        where TSignInManager : SignInManager<TUser, string>
        where TUserManager : UserManager<TUser, string>
#endif
    {
#if !NETCORE
        /// <summary>
        /// Sign-in manager.
        /// </summary>
        private TSignInManager signInManager;

        /// <summary>
        /// User manager.
        /// </summary>
        private TUserManager userManager;

        /// <summary>
        /// Initializes a new instance of the <see cref="AccountController{TUser,TSignInManager,TUserManager}"/> class.
        /// </summary>
        public AccountController()
        {
        }
#endif

        /// <summary>
        /// Initializes a new instance of the <see cref="AccountController{TUser,TSignInManager,TUserManager}"/> class.
        /// </summary>
        /// <param name="userManager">User manager for this controller.</param>
        /// <param name="signInManager">Sign-in manager for this controller.</param>
        public AccountController(TUserManager userManager, TSignInManager signInManager)
        {
            this.UserManager = userManager;
            this.SignInManager = signInManager;
        }

#if !NETCORE
        /// <summary>
        /// Gets sign-in manager.
        /// </summary>
        public TSignInManager SignInManager
        {
            get
            {
                return this.signInManager ?? this.OwinContext.Get<TSignInManager>();
            }

            private set
            {
                this.signInManager = value;
            }
        }

        /// <summary>
        /// Gets user manager.
        /// </summary>
        public TUserManager UserManager
        {
            get
            {
                return this.userManager ?? this.OwinContext.GetUserManager<TUserManager>();
            }

            private set
            {
                this.userManager = value;
            }
        }

        /// <summary>
        /// Gets authentication manager.
        /// </summary>
        private IAuthenticationManager AuthenticationManager
        {
            get
            {
                return this.OwinContext.Authentication;
            }
        }
#else
        /// <summary>
        /// Gets sign-in manager.
        /// </summary>
        public TSignInManager SignInManager { get; set; }

        /// <summary>
        /// Gets user manager.
        /// </summary>
        public TUserManager UserManager { get; set; }
#endif

        /// <summary>
        /// Performs registration of the API.
        /// </summary>
        /// <param name="model">Model for the performing login.</param>
        /// <returns>HTTP OK in case of success; </returns>
        [HttpPost]
        [Route("account/login")]
        public async Task<IActionResult> Login([FromBody]LoginViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.StatusCode(ApiStatusCode.InvalidArguments);
            }

            var result = await this.SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false);
#if !NETCORE
            switch (result)
            {
                case SignInStatus.Success:
                    return await this.OnSuccessLogin(model.Email);
                case SignInStatus.LockedOut:
                    return this.StatusCode(ApiStatusCode.AccountLockedOut);
                case SignInStatus.RequiresVerification:
                    return await this.OnAccountRequiresVerification(model.Email);
                case SignInStatus.Failure:
                default:
                    return this.StatusCode(ApiStatusCode.AuthorizationFailure);
            }
#else
            if (result.Succeeded)
            {
                return await this.OnSuccessLogin(model.Email);
            }

            if (result.IsLockedOut)
            {
                return this.StatusCode(ApiStatusCode.AccountLockedOut);
            }

            if (result.IsNotAllowed)
            {
                return this.StatusCode(ApiStatusCode.AccountRequiresVerification);
            }

            return this.StatusCode(ApiStatusCode.AuthorizationFailure);
#endif
        }

        /// <summary>
        /// Logout from the service.
        /// </summary>
        /// <returns>Action result.</returns>
        [HttpPost]
        [Route("account/logout")]<commit_msg>Allow override account veririfcation for both options<commit_after>﻿// -----------------------------------------------------------------------
// <copyright file="AccountController.cs" company="<NAME>">
// Copyright (c) <NAME>. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace Dub.Web.Mvc.Controllers.Api
{
    using System.Threading.Tasks;
#if !NETCORE
    using System.Web.Http;
#else
    using System.Linq;
#endif
    using Dub.Web.Core;
    using Dub.Web.Identity;
    using Dub.Web.Mvc.Models.Account;
    using Microsoft.AspNet.Identity;
#if !NETCORE
    using Microsoft.AspNet.Identity.Owin;
#endif
#if NETCORE
    using Microsoft.AspNet.Mvc;
#endif
#if !NETCORE
    using Microsoft.Owin.Security;
    using IActionResult = System.Web.Http.IHttpActionResult;
#endif

    /// <summary>
    /// API Account controller.
    /// </summary>
    /// <typeparam name="TUser">Type of the user.</typeparam>
    /// <typeparam name="TSignInManager">Type of sign in manager used.</typeparam>
    /// <typeparam name="TUserManager">Type of user manager used to manage the users.</typeparam>
    public class AccountController<TUser, TSignInManager, TUserManager> : ApiControllerBase
        where TUser : DubUser, new()
#if NETCORE
        where TSignInManager : SignInManager<TUser>
        where TUserManager : UserManager<TUser>
#else
        where TSignInManager : SignInManager<TUser, string>
        where TUserManager : UserManager<TUser, string>
#endif
    {
#if !NETCORE
        /// <summary>
        /// Sign-in manager.
        /// </summary>
        private TSignInManager signInManager;

        /// <summary>
        /// User manager.
        /// </summary>
        private TUserManager userManager;

        /// <summary>
        /// Initializes a new instance of the <see cref="AccountController{TUser,TSignInManager,TUserManager}"/> class.
        /// </summary>
        public AccountController()
        {
        }
#endif

        /// <summary>
        /// Initializes a new instance of the <see cref="AccountController{TUser,TSignInManager,TUserManager}"/> class.
        /// </summary>
        /// <param name="userManager">User manager for this controller.</param>
        /// <param name="signInManager">Sign-in manager for this controller.</param>
        public AccountController(TUserManager userManager, TSignInManager signInManager)
        {
            this.UserManager = userManager;
            this.SignInManager = signInManager;
        }

#if !NETCORE
        /// <summary>
        /// Gets sign-in manager.
        /// </summary>
        public TSignInManager SignInManager
        {
            get
            {
                return this.signInManager ?? this.OwinContext.Get<TSignInManager>();
            }

            private set
            {
                this.signInManager = value;
            }
        }

        /// <summary>
        /// Gets user manager.
        /// </summary>
        public TUserManager UserManager
        {
            get
            {
                return this.userManager ?? this.OwinContext.GetUserManager<TUserManager>();
            }

            private set
            {
                this.userManager = value;
            }
        }

        /// <summary>
        /// Gets authentication manager.
        /// </summary>
        private IAuthenticationManager AuthenticationManager
        {
            get
            {
                return this.OwinContext.Authentication;
            }
        }
#else
        /// <summary>
        /// Gets sign-in manager.
        /// </summary>
        public TSignInManager SignInManager { get; set; }

        /// <summary>
        /// Gets user manager.
        /// </summary>
        public TUserManager UserManager { get; set; }
#endif

        /// <summary>
        /// Performs registration of the API.
        /// </summary>
        /// <param name="model">Model for the performing login.</param>
        /// <returns>HTTP OK in case of success; </returns>
        [HttpPost]
        [Route("account/login")]
        public async Task<IActionResult> Login([FromBody]LoginViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.StatusCode(ApiStatusCode.InvalidArguments);
            }

            var result = await this.SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false);
#if !NETCORE
            switch (result)
            {
                case SignInStatus.Success:
                    return await this.OnSuccessLogin(model.Email);
                case SignInStatus.LockedOut:
                    return this.StatusCode(ApiStatusCode.AccountLockedOut);
                case SignInStatus.RequiresVerification:
                    return await this.OnAccountRequiresVerification(model.Email);
                case SignInStatus.Failure:
                default:
                    return this.StatusCode(ApiStatusCode.AuthorizationFailure);
            }
#else
            if (result.Succeeded)
            {
                return await this.OnSuccessLogin(model.Email);
            }

            if (result.IsLockedOut)
            {
                return this.StatusCode(ApiStatusCode.AccountLockedOut);
            }

            if (result.IsNotAllowed)
            {
                return await this.OnAccountRequiresVerification(model.Email);
            }

            return this.StatusCode(ApiStatusCode.AuthorizationFailure);
#endif
        }

        /// <summary>
        /// Logout from the service.
        /// </summary>
        /// <returns>Action result.</returns>
        [HttpPost]
        [Route("account/logout")]
{'fraction_non_alphanumeric': 0.13094718463553034, 'fraction_numerical': 0.0, 'mean_word_length': 1.614331355545413, 'pattern_counts': {'":': 0, '<': 111, '<?xml version=': 0, '>': 111, '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': '2397645', 'n_tokens_mistral': 2902, 'n_tokens_neox': 2884, 'n_words': 648}