1981 lines
63 KiB
C#
1981 lines
63 KiB
C#
using System;
|
|
using System.Linq;
|
|
using xModels.Dtos;
|
|
using xCommons.Providers;
|
|
using xCommons.Extensions;
|
|
using xCommons.Attributes;
|
|
using xExceptions.Constants;
|
|
using System.Threading.Tasks;
|
|
using xIdentityModels.Models;
|
|
using xCommons.Configurations;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Collections.Generic;
|
|
using xIdentityService.Interfaces;
|
|
using Microsoft.Extensions.Logging;
|
|
using xIdentityService.Controllers;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using xIdentityModels.Dtos;
|
|
using xIdentityModels.Navigations;
|
|
using xIdentityModels.Constants;
|
|
using Microsoft.AspNetCore.Http;
|
|
using static xIdentityHelper.XApiScopeHelper;
|
|
|
|
namespace xIdentityHelper.Controllers
|
|
{
|
|
public abstract class XAccountControllerBase : XBaseAccountController
|
|
{
|
|
protected XAccountControllerBase(
|
|
ILogger<XAccountControllerBase> logger,
|
|
XAppConfiguration appConfiguration,
|
|
IXIdentityProvider IdentityProvider,
|
|
XValidationProvider validationProvider
|
|
) : base(logger, appConfiguration, IdentityProvider, validationProvider)
|
|
{ }
|
|
|
|
//
|
|
#region Authentication Actions ...
|
|
/// <summary>
|
|
/// Logout User
|
|
/// </summary>
|
|
[RequireXPowered]
|
|
[HttpPost("Logout")]
|
|
[Authorize(Policy = XPolicies.User)]
|
|
public virtual async Task<ActionResult> Logout()
|
|
{
|
|
try
|
|
{
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
await IdentityProvider
|
|
.Logout(tokens);
|
|
|
|
//
|
|
return Ok();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validate a Revision Checksum
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Validate")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<bool>> Validate(
|
|
[FromBody] XValidateRevisionRequest model
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
await ValidationProvider
|
|
.GroupValidationBuilder()
|
|
.AddNotNull(model)
|
|
.AddNotEmpty(model.Revision)
|
|
.ValidateGroupAsync();
|
|
|
|
//
|
|
// Get Request ...
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = tokens.ValidateRevisionChecksum(
|
|
model.Revision,
|
|
IdentityProvider.RevisionSecretKey
|
|
);
|
|
|
|
//
|
|
// Return Result
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Request AccessToken for Specific XApiScope
|
|
/// </summary>
|
|
/// <param name="scope">a member of <see>XApiScope</see></param>
|
|
/// <returns>an instance of <see>XTokenResponse</see></returns>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("RequestScopeAccessToken")]
|
|
public virtual async Task<ActionResult<XTokenResponse>> RequestScopeAccessToken (
|
|
[FromHeader] XApiScope scope
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
var scopeName = string.Empty;
|
|
try {
|
|
scopeName = scope.GetStringValue ();
|
|
} catch { }
|
|
ValidationProvider.NotEmpty (scopeName);
|
|
|
|
//
|
|
var result = await IdentityProvider
|
|
.RequestScopeAccessToken (scopeName);
|
|
|
|
//
|
|
return Ok (result
|
|
.ToDynamicObject ());
|
|
} catch (Exception ex) {
|
|
//
|
|
var result = GetExceptionActionResult (ex);
|
|
return result;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Password Actions ...
|
|
/// <summary>
|
|
/// Change a User's Password ...
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// for this action you have to provide:
|
|
/// - Lang: client device currently used locale, such as: en-US.
|
|
/// - Password: user's current active password.
|
|
/// - NewPassword: user's new password to change.
|
|
/// - Device: user's client device which is an instance of XDevice.
|
|
/// - ReturnUrl: client application Login URL.
|
|
///
|
|
/// Sample request:
|
|
///
|
|
/// {
|
|
/// "lang": "fa-IR",
|
|
/// "password": ""
|
|
/// "newPassword": "",
|
|
/// "returnUrl": "http://localhost/login",
|
|
/// "device": {
|
|
/// "os":"Mac",
|
|
/// "browser":"Chrome",
|
|
/// "osVersion":"mac-os-x-15",
|
|
/// "userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) x-framework-test/0.0.0 Chrome/87.0.4280.141 Electron/11.2.0 Safari/537.36",
|
|
/// "deviceType":3,
|
|
/// "identifier":"[Mac]-[mac-os-x-15]-[3]-[Chrome]-[Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) x-framework-test/0.0.0 Chrome/87.0.4280.141 Electron/11.2.0 Safari/537.36]",
|
|
/// "token":"96f400dd9aa5c57a8cec9d6f4775bad3"
|
|
/// }
|
|
/// }
|
|
///
|
|
/// </remarks>
|
|
/// <param name="model">an instance of <see>XActionRequest</see> class which provider requirement for action</param>
|
|
/// <returns></returns>
|
|
[RequireXPowered]
|
|
[HttpPost("ChangePassword")]
|
|
[Authorize(Policy = XPolicies.User)]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult> ChangePassword(
|
|
[FromBody] XActionRequest model
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
if (!ModelState.IsValid)
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
await ValidationProvider
|
|
.GroupValidationBuilder()
|
|
.AddNotNull(
|
|
model,
|
|
model.Device
|
|
)
|
|
.AddNotEmpty(
|
|
model.Lang,
|
|
model.Password,
|
|
model.NewPassword,
|
|
model.ReturnUrl
|
|
)
|
|
.ValidateGroupAsync();
|
|
|
|
//
|
|
// Get User Select By ...
|
|
var userSelectByParam = GetUserSelectByParam(
|
|
model,
|
|
forceNotNull: false
|
|
);
|
|
if (userSelectByParam.IsNullOrEmpty())
|
|
{
|
|
userSelectByParam = User.Identity.Name;
|
|
}
|
|
ValidationProvider.NotEmpty(userSelectByParam);
|
|
|
|
//
|
|
// Get Request ...
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
await IdentityProvider
|
|
.ChangePassword(tokens, model);
|
|
|
|
//
|
|
return Ok();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#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 virtual 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 virtual 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 virtual 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
|
|
|
|
//
|
|
#region Friendship Actions ...
|
|
/// <summary>
|
|
/// Follow a User
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipFollowing</see></returns>
|
|
[RequireXPowered]
|
|
[HttpPost("Friendship/{destUser}/Follow")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<XFriendshipFollowing>> Follow(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.Follow(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Cancel Following Request
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>a boolean value</returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Friendship/{destUser}/Cancel")]
|
|
public virtual async Task<ActionResult<bool>> Cancel(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.Cancel(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Unfollow a Follower
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns></returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Friendship/{destUser}/UnFollowFollower")]
|
|
public virtual async Task<ActionResult> UnFollowFollower(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
await IdentityProvider
|
|
.UnFollowFollower(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Unfollow Following
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns></returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Friendship/{destUser}/UnFollowFollowing")]
|
|
public virtual async Task<ActionResult> UnFollowFollowing(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
await IdentityProvider
|
|
.UnFollowFollowing(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Block a Follower
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipFollowing</see></returns>
|
|
[RequireXPowered]
|
|
[HttpPost("Friendship/{destUser}/Block")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<XFriendshipFollowing>> Block(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.Block(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
|
|
//
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Unblock a Blocked User
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipFollowing</see></returns>
|
|
[RequireXPowered]
|
|
[HttpPost("Friendship/{destUser}/UnBlock")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<XFriendshipFollowing>> UnBlock(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.UnBlock(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Accept a Following Request
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipFollower</see></returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Friendship/{destUser}/AcceptRequest")]
|
|
public virtual async Task<ActionResult<XFriendshipFollower>> AcceptRequest(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.AcceptRequest(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reject a Following Request
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipFollower</see></returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Friendship/{destUser}/RejectRequest")]
|
|
public virtual async Task<ActionResult<XFriendshipFollower>> RejectRequest(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.RejectRequest(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Friendship Getters ...
|
|
/// <summary>
|
|
/// Get Friendship Info Model between Specific User and Current User
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipInfoDto</see></returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/FriendshipInfo")]
|
|
public virtual async Task<ActionResult<XFriendshipInfoDto>> FriendshipInfo(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.GetFriendshipInfo(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check a User IsFollower of Requested User
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>a boolean value</returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/IsFollower")]
|
|
public virtual async Task<ActionResult<bool>> IsFollower(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.IsFollower(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Follower State of a User
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipState</see></returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/FollowerState")]
|
|
public virtual async Task<ActionResult<XFriendshipState>> FollowerState(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.GetFollowerState(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Specific Follower
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipFollower</see></returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/Follower")]
|
|
public virtual async Task<ActionResult<XFriendshipFollower>> Follower(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.GetFollower(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Followers List Of Current User
|
|
/// </summary>
|
|
/// <returns>a collection of <see>XFriendshipFollower</see></returns>
|
|
[RequireXPowered]
|
|
[HttpGet("Friendship/Followers")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<IEnumerable<XFriendshipFollower>>> Followers()
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.GetFollowers(tokens);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
|
|
//
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Followers List Includes Blocked, Requested and etc
|
|
/// of Current User
|
|
/// </summary>
|
|
/// <returns>a collection of <see>XFriendshipFollower</see></returns>
|
|
[RequireXPowered]
|
|
[HttpGet("Friendship/AllFollowers")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<IEnumerable<XFriendshipFollower>>> AllFollowers()
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.GetAllFollowers(tokens);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Followers List Includes Blocked, Requested and etc
|
|
/// of Current User based On Query Model ...
|
|
/// </summary>
|
|
/// <returns>a Query Result of <see>XFriendDto</see></returns>
|
|
[RequireXPowered]
|
|
[HttpGet("Friendship/QueryFollowers")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<XQueryResult<XFriendDto>>> QueryFollowers(
|
|
[FromQuery] XQuery query,
|
|
[FromQuery] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Normalizing Dest User ...
|
|
var userInfo = await GetUserInfo();
|
|
bool isAdmin = userInfo.Roles.Contains(XUserRoles.ADMIN);
|
|
if (destUser.IsNullOrEmpty())
|
|
{
|
|
destUser = userInfo.UserName;
|
|
}
|
|
bool isDestUserValid = isAdmin || destUser == userInfo.UserId || destUser == userInfo.Email || destUser == userInfo.PhoneNumber || destUser == userInfo.UserName;
|
|
if (!isDestUserValid)
|
|
{
|
|
XException.NotAllowed.Throw();
|
|
}
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.QueryFollowers(
|
|
query: query,
|
|
tokens: tokens,
|
|
destUser: destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check a User is in Followings of Current User
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>a boolean value</returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/IsFollowing")]
|
|
public virtual async Task<ActionResult<bool>> IsFollowing(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.IsFollowing(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Following State Relation between Specific User
|
|
/// and Current User
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipState</see></returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/FollowingState")]
|
|
public virtual async Task<ActionResult<XFriendshipState>> FollowingState(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.GetFollowingState(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Specific Following Model
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipFollowing</see></returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/Following")]
|
|
public virtual async Task<ActionResult<XFriendshipFollowing>> Following(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.GetFollowing(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Followings of Current User
|
|
/// </summary>
|
|
/// <returns>a collection of <see>XFriendshipFollowing</see></returns>
|
|
[RequireXPowered]
|
|
[HttpGet("Friendship/Followings")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<IEnumerable<XFriendshipFollowing>>> Followings()
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.GetFollowings(tokens);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Following List Includes Blocked, Requested and etc
|
|
/// of Current User
|
|
/// </summary>
|
|
/// <returns>a collection of <see>XFriendshipFollowing</see></returns>
|
|
[RequireXPowered]
|
|
[HttpGet("Friendship/AllFollowings")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<IEnumerable<XFriendshipFollowing>>> AllFollowings()
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.GetAllFollowings(tokens);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return Following UserName's List of Current User
|
|
/// </summary>
|
|
/// <returns>a collection of UserNames</returns>
|
|
[RequireXPowered]
|
|
[HttpGet("Friendship/FollowingsList")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<IEnumerable<string>>> FollowingsList()
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.GetFollowingList(tokens);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return Followers UserName's List of Current User
|
|
/// </summary>
|
|
/// <returns>a collection of UserNames</returns>
|
|
[RequireXPowered]
|
|
[HttpGet("Friendship/FollowersList")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<IEnumerable<string>>> FollowersList()
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.GetFollowersList(tokens);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Followings List Includes Blocked, Requested and etc
|
|
/// of Current User based On Query Model ...
|
|
/// </summary>
|
|
/// <returns>a Query Result of <see>XFriendDto</see></returns>
|
|
[RequireXPowered]
|
|
[HttpGet("Friendship/QueryFollowings")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<XQueryResult<XFriendDto>>> QueryFollowings(
|
|
[FromQuery] XQuery query,
|
|
[FromQuery] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Normalizing Dest User ...
|
|
var userInfo = await GetUserInfo();
|
|
bool isAdmin = userInfo.Roles.Contains(XUserRoles.ADMIN);
|
|
if (destUser.IsNullOrEmpty())
|
|
{
|
|
destUser = userInfo.UserName;
|
|
}
|
|
bool isDestUserValid = isAdmin || destUser == userInfo.UserId || destUser == userInfo.Email || destUser == userInfo.PhoneNumber || destUser == userInfo.UserName;
|
|
if (!isDestUserValid)
|
|
{
|
|
XException.NotAllowed.Throw();
|
|
}
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.QueryFollowings(
|
|
query: query,
|
|
tokens: tokens,
|
|
destUser: destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Profile Actions ...
|
|
//
|
|
#region Retrieve Actions ...
|
|
/// <summary>
|
|
/// Retrieve User Names based on UserIds
|
|
/// </summary>
|
|
/// <param name="ids">a comma seperated list of UserIds</param>
|
|
/// <returns>a collection of UserNames</returns>
|
|
[RequireXPowered]
|
|
[HttpGet("Profile/{ids}/GetNames")]
|
|
[Authorize(Policy = XPolicies.User)]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<IEnumerable<string>>> GetNames(
|
|
[FromRoute] string ids
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
ValidationProvider.NotEmpty(ids);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider.GetUserNames(
|
|
tokens,
|
|
ids
|
|
);
|
|
|
|
//
|
|
// Return Result
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// get user ids and retrieve corresponding user names
|
|
/// </summary>
|
|
/// <param name="model">an instance of <see>XUserNameIdRequest</see> which represent required UserIds collection</param>
|
|
/// <returns>a collection of <see>XUserNameIdResponse</see> instance</returns>
|
|
[RequireXPowered]
|
|
[HttpPost("Profile/GetNameIds")]
|
|
[Authorize(Policy = XPolicies.User)]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<IEnumerable<XUserNameIdResponse>>> GetNameIds(
|
|
[FromBody] XUserNameIdRequest model
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
ValidationProvider.NotNull(model);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider.GetUserNameIds(
|
|
tokens,
|
|
model
|
|
);
|
|
|
|
//
|
|
// Return Result
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Profile Object of Specific User
|
|
/// </summary>
|
|
/// <param name="userSelectByParam">determine's which user profile must be retrieved</param>
|
|
/// <returns>an instance of <see>XUserProfileDto</see></returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.User)]
|
|
[HttpGet("Profile/{userSelectByParam?}")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<XUserProfileDto>> GetProfile(
|
|
[FromRoute] string userSelectByParam = ""
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
if (userSelectByParam.IsNullOrEmpty())
|
|
{
|
|
userSelectByParam = User.Identity.Name;
|
|
}
|
|
ValidationProvider.NotEmpty(userSelectByParam);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.GetUserProfile(
|
|
tokens,
|
|
userSelectByParam
|
|
);
|
|
|
|
//
|
|
// Return Result
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query Users
|
|
/// for specifiy users role for query user 'role: string' and 'forceRole: boolean' in header
|
|
/// </summary>
|
|
/// <param name="query">how to filter results based on <see>XQuery</see> structure</param>
|
|
/// <param name="role">an string which represent user role</param>
|
|
/// <param name="forceRole">if it's true the user must has exact role, otherwise top level users also listed</param>
|
|
/// <returns>an instance of <see>XQueryResult</see> of <see>XUserProfileDto</see></returns>
|
|
[RequireXPowered]
|
|
[HttpGet("Profile/Query")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
[Authorize(Policy = XPolicies.EnabledAgent)]
|
|
public virtual async Task<ActionResult<XQueryResult<XUserProfileDto>>> QueryProfiles(
|
|
[FromQuery] XQuery query, [FromHeader] string role, [FromHeader] bool forceRole = false
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = new XQueryResult<XUserProfileDto>();
|
|
if (role.IsNullOrEmpty())
|
|
{
|
|
//
|
|
result = await IdentityProvider.QueryUsers(
|
|
tokens,
|
|
query
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
result = await IdentityProvider.QueryInRoleUsers(
|
|
tokens,
|
|
role,
|
|
query,
|
|
forceRole
|
|
);
|
|
}
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exception = GetExceptionActionResult(ex);
|
|
return exception;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query Specified User's Profile Images
|
|
/// </summary>
|
|
/// <param name="userSelectByParam">determine's which user profile must be retrieved</param>
|
|
/// <param name="query">how to filter results based on <see>XQuery</see> structure</param>
|
|
/// <returns>an instance of <see>XQueryResult</see> of <see>XProfileImage</see></returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.User)]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
[HttpGet("Profile/Avatars/Query/{userSelectByParam?}")]
|
|
public virtual async Task<ActionResult<XQueryResult<XProfileImageDto>>> QueryAvatars(
|
|
[FromQuery] XQuery query, [FromRoute] string userSelectByParam = null
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
if (userSelectByParam.IsNullOrEmpty())
|
|
{
|
|
userSelectByParam = User.Identity.Name;
|
|
}
|
|
ValidationProvider.NotEmpty(userSelectByParam);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider.QueryAvatars(
|
|
tokens,
|
|
userSelectByParam,
|
|
query
|
|
);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exception = GetExceptionActionResult(ex);
|
|
return exception;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Update Actions ...
|
|
/// <summary>
|
|
/// Update User Profile based on <see>XProfileUpdateRequest</see> (FirstName/LastName/DateOfBirth)
|
|
/// </summary>
|
|
/// <param name="model">user update info, an instance of <see>XProfileUpdateRequest</see></param>
|
|
/// <param name="userSelectByParam">determine's which user profile must be retrieved</param>
|
|
/// <returns>an instance of <see>XUserProfileDto</see></returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Profile/Update/{userSelectByParam?}")]
|
|
public virtual async Task<ActionResult<XUserProfileDto>> UpdateProfile(
|
|
[FromBody] XProfileUpdateRequest model, [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.ProfileUpdateAsync(
|
|
tokens,
|
|
userSelectByParam,
|
|
model
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
// Return Result
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update a User Profile based on <see>XProfileUpdateRequest</see> Full
|
|
/// </summary>
|
|
/// <param name="model">user update info, an instance of <see>XProfileUpdateRequest</see></param>
|
|
/// <param name="userSelectByParam">determine's which user profile must be retrieved</param>
|
|
/// <returns>an instance of <see>XUserProfileDto</see></returns>
|
|
[RequireXPowered]
|
|
[HttpPost("Profile/{userSelectByParam?}")]
|
|
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
public virtual async Task<ActionResult<XUserProfileDto>> FullUpdateProfile(
|
|
[FromBody] XProfileUpdateRequest model, [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.FullProfileUpdateAsync(
|
|
tokens,
|
|
userSelectByParam,
|
|
model
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
// Return Result
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Avatar Actions ...
|
|
/// <summary>
|
|
/// Add a New Profile Image
|
|
/// </summary>
|
|
/// <param name="file">an specific File to upload, <see>IFormFile</see></param>
|
|
/// <returns>an instance of <see>XUserProfileDto</see></returns>
|
|
[RequireXPowered]
|
|
[HttpPost("Profile/Avatar")]
|
|
[RequestSizeLimit(966_367_641)]
|
|
[Authorize(Policy = XPolicies.User)]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<XUserProfileDto>> AddAvatar(
|
|
[FromForm] IFormFile file
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotNull(file);
|
|
|
|
//
|
|
// Get Request ...
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.AddAvatar(
|
|
tokens,
|
|
file
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a New Collection of Profile Images
|
|
/// </summary>
|
|
/// <param name="files">a collection of Files to upload, <see>IFormFileCollection</see></param>
|
|
/// <returns>an instance of <see>XUserProfileDto</see></returns>
|
|
[RequireXPowered]
|
|
[HttpPost("Profile/Avatars")]
|
|
[RequestSizeLimit(966_367_641)]
|
|
[Authorize(Policy = XPolicies.User)]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<XUserProfileDto>> AddAvatars(
|
|
[FromForm] IFormFileCollection files
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotZeroChilds(files);
|
|
|
|
//
|
|
// Get Request ...
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider.AddAvatars(
|
|
tokens,
|
|
files
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// set Specified Profile Image as Avatar
|
|
/// </summary>
|
|
/// <param name="id">an integer which reperesent AvatarId to set as current Avatar</param>
|
|
/// <returns>an instance of <see>XUserProfileDto</see></returns>
|
|
[RequireXPowered]
|
|
[HttpPost("Profile/Avatars/{id:int}/Set")]
|
|
[Authorize(Policy = XPolicies.User)]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<XUserProfileDto>> SetAvatar(
|
|
[FromRoute] int id
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Get Request ...
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.SetAvatar(
|
|
tokens,
|
|
id
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exception = GetExceptionActionResult(ex);
|
|
return exception;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove Profile Images
|
|
/// </summary>
|
|
/// <param name="ids">a comma seperated list of avatarIds to remove</param>
|
|
/// <returns>an instance of <see>XUserProfileDto</see></returns>
|
|
[RequireXPowered]
|
|
[Authorize(Policy = XPolicies.User)]
|
|
[HttpDelete("Profile/Avatars/{ids}")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<XUserProfileDto>> RemoveAvatars(
|
|
[FromRoute] string ids
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(ids);
|
|
|
|
//
|
|
// Get Request ...
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider
|
|
.RemoveAvatars(
|
|
tokens,
|
|
ids
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
#endregion
|
|
#endregion
|
|
|
|
//
|
|
#region Registration ...
|
|
/// <summary>
|
|
/// Invite a User to Register on Dashboard
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// for this action you have to provide:
|
|
/// - Lang: client device currently used locale, such as: en-US.
|
|
/// - Email: which email address is going to invite.
|
|
/// - Device: user's client device which is an instance of XDevice.
|
|
/// - ReturnUrl: client application Registration URL.
|
|
/// notice in this step you had to provide all this informations as FormData
|
|
///
|
|
/// Sample request:
|
|
///
|
|
/// {
|
|
/// "lang": "fa-IR",
|
|
/// "email": "",
|
|
/// "returnUrl": "",
|
|
/// "device": {
|
|
/// "os":"Mac",
|
|
/// "browser":"Chrome",
|
|
/// "osVersion":"mac-os-x-15",
|
|
/// "userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) x-framework-test/0.0.0 Chrome/87.0.4280.141 Electron/11.2.0 Safari/537.36",
|
|
/// "deviceType":3,
|
|
/// "identifier":"[Mac]-[mac-os-x-15]-[3]-[Chrome]-[Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) x-framework-test/0.0.0 Chrome/87.0.4280.141 Electron/11.2.0 Safari/537.36]",
|
|
/// "token":"96f400dd9aa5c57a8cec9d6f4775bad3"
|
|
/// }
|
|
/// }
|
|
///
|
|
/// </remarks>
|
|
/// <param name="model">an instance of <see>XActionRequest</see> class which provider requirement for action</param>
|
|
/// <returns>an instance of <see>XActionResponse</see></returns>
|
|
[RequireXPowered]
|
|
[HttpPost ("InviteUser")]
|
|
[Authorize (Policy = XPolicies.EnabledAdmin)]
|
|
[Authorize (Policy = XPolicies.EnabledAgent)]
|
|
public virtual async Task<ActionResult<XActionResponse>> InviteUser (
|
|
[FromBody] XActionRequest model
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
if (!ModelState.IsValid) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
|
|
//
|
|
await ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotEmpty (
|
|
model.Lang,
|
|
model.Email,
|
|
model.ReturnUrl)
|
|
.AddEmailAddress (model.Email)
|
|
.AddNotNull (model.Device)
|
|
.ValidateGroupAsync ();
|
|
|
|
//
|
|
// Get Request ...
|
|
var tokens = await RetrieveTokensAsXTokenResponse ();
|
|
var result = await IdentityProvider
|
|
.InviteUser (
|
|
tokens,
|
|
model
|
|
);
|
|
|
|
//
|
|
return Ok (result
|
|
.ToDynamicObject ());
|
|
} catch (Exception ex) {
|
|
//
|
|
var result = GetExceptionActionResult (ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check User is Confirmed Email or not
|
|
/// </summary>
|
|
/// <returns>a boolean value</returns>
|
|
[RequireXPowered]
|
|
[HttpGet ("IsConfirmedEmail")]
|
|
[Authorize (Policy = XPolicies.User)]
|
|
public virtual async Task<ActionResult<bool>> IsConfirmedEmail () {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Get Result ...
|
|
var tokens = await RetrieveTokensAsXTokenResponse ();
|
|
var result = await IdentityProvider
|
|
.IsConfirmedEmail (
|
|
tokens,
|
|
User.Identity.Name
|
|
);
|
|
|
|
//
|
|
// Return Result
|
|
return Ok (result);
|
|
} catch (Exception ex) {
|
|
//
|
|
var result = GetExceptionActionResult (ex);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check User is Confirmed Mobile or not
|
|
/// </summary>
|
|
/// <returns>a boolean value</returns>
|
|
[RequireXPowered]
|
|
[HttpGet ("IsConfirmedMobile")]
|
|
[Authorize (Policy = XPolicies.User)]
|
|
public virtual async Task<ActionResult<bool>> IsConfirmedMobile () {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Get Result ...
|
|
var tokens = await RetrieveTokensAsXTokenResponse ();
|
|
var result = await IdentityProvider
|
|
.IsConfirmedMobile (
|
|
tokens,
|
|
User.Identity.Name
|
|
);
|
|
|
|
//
|
|
// Return Result
|
|
return Ok (result);
|
|
} catch (Exception ex) {
|
|
//
|
|
var result = GetExceptionActionResult (ex);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Search ...
|
|
/// <summary>
|
|
/// Query Open To Search Users Profiles ...
|
|
/// Query all Users Which their Profiles is Open To Search ...
|
|
/// </summary>
|
|
/// <param name="query">how to filter results based on <see>XQuery</see> structure</param>
|
|
/// <returns>an instance of <see>XQueryResult</see> of <see>XUserProfileDto</see></returns>
|
|
[RequireXPowered]
|
|
[HttpGet("OpenToSearch/Query")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<XQueryResult<XUserProfileDto>>> QueryOpenToSearchProfiles(
|
|
[FromQuery] XQuery query
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await IdentityProvider.QueryOpenToSearchUsers(
|
|
tokens,
|
|
query
|
|
);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exception = GetExceptionActionResult(ex);
|
|
return exception;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |