using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using xIdentityHelper;
using xCommons.Attributes;
using xCommons.Extensions;
using xIdentityModels.Dtos;
using static IdentityServer4.IdentityServerConstants;
namespace xIds.Controllers
{
public partial class AccountController
{
//
#region Admin Actions ...
///
/// Ban Specific Users
///
/// an instance of XUserNameIdRequest which represents user identifier list to Ban
/// a list of banned users identifiers
[RequireXPowered]
[HttpPost("Ban")]
[Authorize(Policy = LocalApi.PolicyName)]
[Authorize(Policy = XPolicies.EnabledAdmin)]
public async Task>> Ban(
[FromBody] XUserNameIdRequest model
)
{
//
// Do Action ...
try
{
//
// Validate Args ...
await ValidationProvider
.GroupValidationBuilder()
.AddNotNull(model)
.AddNotZeroChilds(model.Ids)
.ValidateGroupAsync();
//
var result = await IdentityManager
.Ban(
User.Identity.Name,
model
);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var exResult = GetExceptionActionResult(ex);
return exResult;
}
}
///
/// UnBann Specific Users
///
/// an instance of XUserNameIdRequest which represents user identifier list to Ban
/// a list of unbanned users identifiers
[RequireXPowered]
[HttpPost("UnBan")]
[Authorize(Policy = LocalApi.PolicyName)]
[Authorize(Policy = XPolicies.EnabledAdmin)]
public async Task>> UnBan(
[FromBody] XUserNameIdRequest model
)
{
//
// Do Action ...
try
{
//
// Validate Args ...
await ValidationProvider
.GroupValidationBuilder()
.AddNotNull(model)
.AddNotZeroChilds(model.Ids)
.ValidateGroupAsync();
//
var result = await IdentityManager
.UnBan(
User.Identity.Name,
model
);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var exResult = GetExceptionActionResult(ex);
return exResult;
}
}
///
/// Check Specific User is Banned or not
///
/// specified user's identifier
/// a boolean value which represent user banned or not
[RequireXPowered]
[Authorize(Policy = LocalApi.PolicyName)]
[HttpGet("IsBanned/{userSelectByParam?}")]
[Authorize(Policy = XPolicies.EnabledAdmin)]
[Authorize(Policy = XPolicies.EnabledAgent)]
public async Task> IsBanned(
[FromRoute] string userSelectByParam = null
)
{
//
// Do Action ...
try
{
//
// Validate Args ...
if (userSelectByParam.IsNullOrEmpty())
{
userSelectByParam = User.Identity.Name;
}
ValidationProvider.NotEmpty(userSelectByParam);
//
var result = await IdentityManager
.IsBanned(
User.Identity.Name,
userSelectByParam
);
//
return Ok(result);
}
catch (Exception ex)
{
//
var exResult = GetExceptionActionResult(ex);
return exResult;
}
}
#endregion
}
}