Exemple #1
0
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var credentials = new UserCredentials {
                    Username = model.Email, Password = model.Password
                };
                var authenticatedUser = await _authenticationEndpoint.Authenticate(credentials);

                if (authenticatedUser.Authenticated)
                {
                    var signInResult = await _signInManager.SignInOrTwoFactor(authenticatedUser);

                    if (signInResult.Success)
                    {
                        _logger.LogInformation("User logged in.");
                        returnUrl ??= Url.Content("~/");
                        return(RedirectToLocal(returnUrl));
                    }
                    if (signInResult.RequiresTwoFactor)
                    {
                        return(RedirectToAction(nameof(LoginWith2Fa), new { returnUrl }));
                    }
                }

                ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                return(View(model));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #2
0
        public async Task DoSignInAsync(string userId, bool rememberClient)
        {
            var authenticatedUser = await _authenticationEndpoint.Authenticate(userId);

            await DoSignInAsync(authenticatedUser, rememberClient);
        }