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;
namespace xApi.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 = XPolicies.EnabledAdmin)]
public async Task>> Ban (
[FromBody] XUserNameIdRequest model
) {
//
// Do Action ...
try {
//
// Validate Args ...
await ValidationProvider
.GroupValidationBuilder ()
.AddNotNull (model)
.AddNotZeroChilds (model.Ids)
.ValidateGroupAsync ();
//
var tokens = await RetrieveTokensAsXTokenResponse ();
var result = await identityProvider
.Ban (
tokens,
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 = XPolicies.EnabledAdmin)]
public async Task>> UnBan (
[FromBody] XUserNameIdRequest model
) {
//
// Do Action ...
try {
//
// Validate Args ...
await ValidationProvider
.GroupValidationBuilder ()
.AddNotNull (model)
.AddNotZeroChilds (model.Ids)
.ValidateGroupAsync ();
//
var tokens = await RetrieveTokensAsXTokenResponse ();
var result = await identityProvider
.UnBan (
tokens,
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]
[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 tokens = await RetrieveTokensAsXTokenResponse ();
var result = await identityProvider
.IsBanned (
tokens,
userSelectByParam
);
//
return Ok (result);
} catch (Exception ex) {
//
var exResult = GetExceptionActionResult (ex);
return exResult;
}
}
#endregion
}
}