Пример #1
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            bool result;

            bool.TryParse(ConfigurationManager.AppSettings["useADlogin"], out bool useADlogin);

            if (useADlogin && !string.IsNullOrEmpty(model.Tenant)) // if tenant is null, then assume that it is system level login. Go to the ValidateLogin which is used for regular login process first
            {
                result = await SignInManager.ADSigninAsync(model.Tenant, model.Password, model.RememberMe);
            }
            else
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, change to shouldLockout: true
                result = await SignInManager.PasswordSigninAsync(model.Tenant, model.Email, model.Password, model.RememberMe);
            }

            if (result)
            {
                return(RedirectToLocal(returnUrl));
            }
            else
            {
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }