Skip to content

Commit

Permalink
feat: add account claims & login app services
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnkwlp committed Nov 5, 2023
1 parent 7a523c7 commit 9ce5ddb
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/account/src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Version>0.2.0</Version>
<PackageVersion>0.2.5</PackageVersion>
<PackageVersion>0.2.6</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Passingwind.Abp.Account;

public class AccountAuthenticationLoginResultDto
{
public string LoginProvider { get; set; } = null!;
public string? ProviderDisplayName { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;

namespace Passingwind.Abp.Account;

public interface IAccountAuthenticationLoginAppService : IApplicationService
{
Task<ListResultDto<AccountAuthenticationLoginResultDto>> GetListAsync();
}

public class AccountClaimResultDto
{
public string ClaimType { get; set; } = null!;
public string? ClaimValue { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;

namespace Passingwind.Abp.Account;

public interface IAccountClaimsAppService : IApplicationService
{
Task<ListResultDto<AccountClaimResultDto>> GetListAsync();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Passingwind.Abp.Identity;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Users;

namespace Passingwind.Abp.Account;

[Authorize]
public class AccountAuthenticationLoginAppService : AccountAppBaseService, IAccountAuthenticationLoginAppService
{
protected IdentityUserManager UserManager { get; }

public AccountAuthenticationLoginAppService(IdentityUserManager userManager)
{
UserManager = userManager;
}

public virtual async Task<ListResultDto<AccountAuthenticationLoginResultDto>> GetListAsync()
{
var user = await UserManager.GetByIdAsync(CurrentUser.GetId());

var list = await UserManager.GetLoginsAsync(user);

return new ListResultDto<AccountAuthenticationLoginResultDto>(list.Select(x => new AccountAuthenticationLoginResultDto()
{
LoginProvider = x.LoginProvider,
ProviderDisplayName = x.ProviderDisplayName,
}).ToList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Passingwind.Abp.Identity;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Users;

namespace Passingwind.Abp.Account;

[Authorize]
public class AccountClaimsAppService : AccountAppBaseService, IAccountClaimsAppService
{
protected IdentityUserManager UserManager { get; }

public AccountClaimsAppService(IdentityUserManager userManager)
{
UserManager = userManager;
}

public virtual async Task<ListResultDto<AccountClaimResultDto>> GetListAsync()
{
var user = await UserManager.GetByIdAsync(CurrentUser.GetId());

var list = await UserManager.GetClaimsAsync(user);

return new ListResultDto<AccountClaimResultDto>(list.Select(x => new AccountClaimResultDto()
{
ClaimType = x.Type,
ClaimValue = x.Value,
}).ToList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace Passingwind.Abp.Account;

[RemoteService(Name = AccountRemoteServiceConsts.RemoteServiceName)]
[Area(AccountRemoteServiceConsts.ModuleName)]
[Route("api/account/authentication/logins")]
public class AccountAuthenticationLoginController : AccountBaseController, IAccountAuthenticationLoginAppService
{
protected IAccountAuthenticationLoginAppService Service { get; }

public AccountAuthenticationLoginController(IAccountAuthenticationLoginAppService service)
{
Service = service;
}

/// <inheritdoc/>
[HttpGet]
public virtual Task<ListResultDto<AccountAuthenticationLoginResultDto>> GetListAsync()
{
return Service.GetListAsync();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace Passingwind.Abp.Account;

[RemoteService(Name = AccountRemoteServiceConsts.RemoteServiceName)]
[Area(AccountRemoteServiceConsts.ModuleName)]
[Route("api/account/claims")]
public class AccountClaimsController : AccountBaseController, IAccountClaimsAppService
{
protected IAccountClaimsAppService Service { get; }

public AccountClaimsController(IAccountClaimsAppService service)
{
Service = service;
}

/// <inheritdoc/>
[HttpGet]
public virtual Task<ListResultDto<AccountClaimResultDto>> GetListAsync()
{
return Service.GetListAsync();
}
}

0 comments on commit 9ce5ddb

Please sign in to comment.