|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Sanhe.Abp.Identity.Dto;
|
|
|
|
using System;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Volo.Abp;
|
|
|
|
using Volo.Abp.Application.Dtos;
|
|
|
|
using Volo.Abp.AspNetCore.Mvc;
|
|
|
|
using Volo.Abp.Identity;
|
|
|
|
|
|
|
|
namespace Sanhe.Abp.Identity
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// 用户
|
|
|
|
/// </summary>
|
|
|
|
[RemoteService(true, Name = IdentityRemoteServiceConsts.RemoteServiceName)]
|
|
|
|
[Area("identity")]
|
|
|
|
[ControllerName("User")]
|
|
|
|
[Route("api/identity/users")]
|
|
|
|
public class IdentityUserController : AbpController, IIdentityUserAppService
|
|
|
|
{
|
|
|
|
protected IIdentityUserAppService UserAppService { get; }
|
|
|
|
|
|
|
|
public IdentityUserController(IIdentityUserAppService userAppService)
|
|
|
|
{
|
|
|
|
UserAppService = userAppService;
|
|
|
|
}
|
|
|
|
|
|
|
|
#region OrganizationUnit
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取该用户的组织单位
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[Route("{id}/organization-units")]
|
|
|
|
public async virtual Task<ListResultDto<OrganizationUnitDto>> GetOrganizationUnitsAsync(Guid id)
|
|
|
|
{
|
|
|
|
return await UserAppService.GetOrganizationUnitsAsync(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 修改该用户组织单位
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPut]
|
|
|
|
[Route("{id}/organization-units")]
|
|
|
|
public async virtual Task SetOrganizationUnitsAsync(Guid id, IdentityUserOrganizationUnitUpdateDto input)
|
|
|
|
{
|
|
|
|
await UserAppService.SetOrganizationUnitsAsync(id, input);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 删除该用户组织单位
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <param name="ouId"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpDelete]
|
|
|
|
[Route("{id}/organization-units/{ouId}")]
|
|
|
|
public async virtual Task RemoveOrganizationUnitsAsync(Guid id, Guid ouId)
|
|
|
|
{
|
|
|
|
await UserAppService.RemoveOrganizationUnitsAsync(id, ouId);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Claim
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取用户身份声明
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[Route("{id}/claims")]
|
|
|
|
public async virtual Task<ListResultDto<IdentityClaimDto>> GetClaimsAsync(Guid id)
|
|
|
|
{
|
|
|
|
return await UserAppService.GetClaimsAsync(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 创建用户身份声明
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
[Route("{id}/claims")]
|
|
|
|
public async virtual Task AddClaimAsync(Guid id, IdentityUserClaimCreateDto input)
|
|
|
|
{
|
|
|
|
await UserAppService.AddClaimAsync(id, input);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 修改用户身份声明
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPut]
|
|
|
|
[Route("{id}/claims")]
|
|
|
|
public async virtual Task UpdateClaimAsync(Guid id, IdentityUserClaimUpdateDto input)
|
|
|
|
{
|
|
|
|
await UserAppService.UpdateClaimAsync(id, input);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 删除用户身份声明
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpDelete]
|
|
|
|
[Route("{id}/claims")]
|
|
|
|
public async virtual Task DeleteClaimAsync(Guid id, IdentityUserClaimDeleteDto input)
|
|
|
|
{
|
|
|
|
await UserAppService.DeleteClaimAsync(id, input);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 变更用户双因素验证选项
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPut]
|
|
|
|
[Route("change-two-factor")]
|
|
|
|
public async virtual Task ChangeTwoFactorEnabledAsync(Guid id, TwoFactorEnabledDto input)
|
|
|
|
{
|
|
|
|
await UserAppService.ChangeTwoFactorEnabledAsync(id, input);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 锁定
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id">用户Id</param>
|
|
|
|
/// <param name="seconds">秒</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPut]
|
|
|
|
[Route("{id}/lock/{seconds}")]
|
|
|
|
public async virtual Task LockAsync(Guid id, int seconds)
|
|
|
|
{
|
|
|
|
await UserAppService.LockAsync(id, seconds);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 解锁
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id">用户Id</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPut]
|
|
|
|
[Route("{id}/unlock")]
|
|
|
|
public async virtual Task UnLockAsync(Guid id)
|
|
|
|
{
|
|
|
|
await UserAppService.UnLockAsync(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|