@ -1,9 +1,11 @@
using System ;
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.ComponentModel.DataAnnotations ;
using System.ComponentModel.DataAnnotations ;
using System.Diagnostics ;
using System.Linq ;
using System.Linq ;
using System.Security.Claims ;
using System.Security.Claims ;
using System.Threading.Tasks ;
using System.Threading.Tasks ;
using IdentityServer4.Events ;
using IdentityServer4.Models ;
using IdentityServer4.Models ;
using IdentityServer4.Services ;
using IdentityServer4.Services ;
using IdentityServer4.Stores ;
using IdentityServer4.Stores ;
@ -12,6 +14,7 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.Extensions.Logging ;
using Microsoft.Extensions.Logging ;
using Microsoft.Extensions.Options ;
using Microsoft.Extensions.Options ;
using Volo.Abp.Account.Web.Auth ;
using Volo.Abp.Identity ;
using Volo.Abp.Identity ;
using Volo.Abp.Ui ;
using Volo.Abp.Ui ;
using Volo.Abp.Uow ;
using Volo.Abp.Uow ;
@ -46,6 +49,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
private readonly IAuthenticationSchemeProvider _ schemeProvider ;
private readonly IAuthenticationSchemeProvider _ schemeProvider ;
private readonly AbpAccountOptions _ accountOptions ;
private readonly AbpAccountOptions _ accountOptions ;
private readonly IClientStore _ clientStore ;
private readonly IClientStore _ clientStore ;
private readonly IEventService _ identityServerEvents ;
public IdsLoginModel (
public IdsLoginModel (
SignInManager < IdentityUser > signInManager ,
SignInManager < IdentityUser > signInManager ,
@ -53,13 +57,15 @@ namespace Volo.Abp.Account.Web.Pages.Account
IIdentityServerInteractionService interaction ,
IIdentityServerInteractionService interaction ,
IAuthenticationSchemeProvider schemeProvider ,
IAuthenticationSchemeProvider schemeProvider ,
IOptions < AbpAccountOptions > accountOptions ,
IOptions < AbpAccountOptions > accountOptions ,
IClientStore clientStore )
IClientStore clientStore ,
IEventService identityServerEvents )
{
{
_ signInManager = signInManager ;
_ signInManager = signInManager ;
_ userManager = userManager ;
_ userManager = userManager ;
_ interaction = interaction ;
_ interaction = interaction ;
_ schemeProvider = schemeProvider ;
_ schemeProvider = schemeProvider ;
_ clientStore = clientStore ;
_ clientStore = clientStore ;
_ identityServerEvents = identityServerEvents ;
_ accountOptions = accountOptions . Value ;
_ accountOptions = accountOptions . Value ;
}
}
@ -120,7 +126,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
var context = await _ interaction . GetAuthorizationContextAsync ( ReturnUrl ) ;
var context = await _ interaction . GetAuthorizationContextAsync ( ReturnUrl ) ;
if ( context = = null )
if ( context = = null )
{
{
return RedirectSafely ( "~/" ) ;
return Redirect ( "~/" ) ;
}
}
await _ interaction . GrantConsentAsync ( context , ConsentResponse . Denied ) ;
await _ interaction . GrantConsentAsync ( context , ConsentResponse . Denied ) ;
@ -136,12 +142,23 @@ namespace Volo.Abp.Account.Web.Pages.Account
true
true
) ;
) ;
//TODO: Find a way of getting user's id from the logged in user and do not query it again like that!
var user = await _ userManager . FindByNameAsync ( LoginInput . UserNameOrEmailAddress ) ? ?
await _ userManager . FindByEmailAsync ( LoginInput . UserNameOrEmailAddress ) ;
if ( ! result . Succeeded )
if ( ! result . Succeeded )
{
{
await _ identityServerEvents . RaiseAsync ( new UserLoginFailureEvent ( LoginInput . UserNameOrEmailAddress , "Login failed: " + result . GetResultAsString ( ) ) ) ;
throw new UserFriendlyException ( "Login failed!" ) ; //TODO: Handle other cases, do not throw exception
throw new UserFriendlyException ( "Login failed!" ) ; //TODO: Handle other cases, do not throw exception
}
}
//var user = _userManager.FindByIdAsync(result.)
Debug . Assert ( user ! = null , nameof ( user ) + " != null" ) ;
await _ identityServerEvents . RaiseAsync ( new UserLoginSuccessEvent ( user . UserName , user . Id . ToString ( ) , user . UserName ) ) ; //TODO: Use user's name once implemented
if ( ! _ interaction . IsValidReturnUrl ( ReturnUrl ) )
{
return Redirect ( "~/" ) ;
}
return RedirectSafely ( ReturnUrl , ReturnUrlHash ) ;
return RedirectSafely ( ReturnUrl , ReturnUrlHash ) ;
}
}