Initial ...
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
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 ...
|
||||
/// <summary>
|
||||
/// Ban Specific Users
|
||||
/// </summary>
|
||||
/// <param name="model">an instance of <see>XUserNameIdRequest</see> which represents user identifier list to Ban</param>
|
||||
/// <returns>a list of banned users identifiers</returns>
|
||||
[RequireXPowered]
|
||||
[HttpPost ("Ban")]
|
||||
[Authorize (Policy = XPolicies.EnabledAdmin)]
|
||||
public async Task<ActionResult<IEnumerable<string>>> 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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UnBann Specific Users
|
||||
/// </summary>
|
||||
/// <param name="model">an instance of <see>XUserNameIdRequest</see> which represents user identifier list to Ban</param>
|
||||
/// <returns>a list of unbanned users identifiers</returns>
|
||||
[RequireXPowered]
|
||||
[HttpPost ("UnBan")]
|
||||
[Authorize (Policy = XPolicies.EnabledAdmin)]
|
||||
public async Task<ActionResult<IEnumerable<string>>> 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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check Specific User is Banned or not
|
||||
/// </summary>
|
||||
/// <param name="userSelectByParam">specified user's identifier</param>
|
||||
/// <returns>a boolean value which represent user banned or not</returns>
|
||||
[RequireXPowered]
|
||||
[HttpGet ("IsBanned/{userSelectByParam?}")]
|
||||
[Authorize (Policy = XPolicies.EnabledAdmin)]
|
||||
[Authorize (Policy = XPolicies.EnabledAgent)]
|
||||
public async Task<ActionResult<bool>> 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user