public async Task <IActionResult> Login(LoginInputModel model) { if (!this._applicationOptions.EnableAccountLogin) { return(this.NotFound()); } if (this.ModelState.IsValid) { UserAccountVerificationResult result = await this._userAccountService .VerifyByEmailAndPasswordAsync( model.Email, model.Password ); if (result.UserAccount != null) { if (!result.IsLoginAllowed) { this.ModelState.AddModelError(this._localizer[ ErrorMessages.UserAccountIsDeactivated]); } else if (result.IsLocalAccount) { if (result.IsPasswordValid) { await this._authenticationService.SignInAsync( result.UserAccount, model.ReturnUrl, model.RememberLogin); return(this.RedirectToReturnUrl( model.ReturnUrl, this._interaction)); } else { await this._userAccountService .PerceiveFailedLoginAsync(result.UserAccount); } } else { LoginViewModel vm = await this.CreateViewModelAsync( model, result.UserAccount ); return(this.View(vm)); } } this.ModelState.AddModelError( this._localizer[ErrorMessages.InvalidCredentials]); } // Something went wrong, show form with error return(this.RedirectToLogin(model.ReturnUrl)); }
internal async Task <IActionResult> SignInAsync( LoginInputModel model, UserAccountVerificationResult result) { AuthenticationProperties props = null; if (this.applicationOptions.EnableRememberLogin && model.RememberLogin) { props = new AuthenticationProperties { IsPersistent = true, // TODO: use DateTimeAccessor ExpiresUtc = DateTimeOffset.UtcNow.Add( TimeSpan.FromDays( this.applicationOptions.RememberMeLoginDuration ) ) }; } ; await this.HttpContext.SignInAsync(result.UserAccount, props); await this.userAccountService .UpdateSuccessfulLoginAsync(result.UserAccount); // Make sure the returnUrl is still valid, and if yes - // redirect back to authorize endpoint if (interaction.IsValidReturnUrl(model.ReturnUrl)) { return(Redirect(model.ReturnUrl)); } return(Redirect("/")); }