4672 lines
157 KiB
Plaintext
4672 lines
157 KiB
Plaintext
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Program.cs
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
namespace xApi
|
|
{
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
CreateHostBuilder(args).Build().Run();
|
|
}
|
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
Host.CreateDefaultBuilder(args)
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
{
|
|
webBuilder.UseStartup<Startup>();
|
|
});
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Startup.cs
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Net.Http;
|
|
using System.Reflection;
|
|
using IdentityModel.AspNetCore.OAuth2Introspection;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Serialization;
|
|
using xApi.Extensions;
|
|
using xCommons.Configurations;
|
|
using xCommons.Extensions;
|
|
using xDataService.Models;
|
|
using xHttpService.DI;
|
|
using xIdentityService.DI;
|
|
using xServices.Databases;
|
|
using xServices.DI;
|
|
|
|
namespace xApi
|
|
{
|
|
public class Startup
|
|
{
|
|
//
|
|
public IConfiguration Configuration { get; }
|
|
private readonly XApiDatabaseDescriptor apiDatabaseDescriptor;
|
|
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
//
|
|
Configuration = configuration;
|
|
|
|
//
|
|
// Create an Api Descriptor Class Instance ...
|
|
apiDatabaseDescriptor = new XApiDatabaseDescriptor();
|
|
}
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
//
|
|
// Register Validation Provider and all XCommons Module Services ...
|
|
services.AddXCommons();
|
|
|
|
//
|
|
// Register App Configuration ...
|
|
services.AddXAppConfiguration(Configuration);
|
|
var appConfiguration = services.GetRegisteredService<XAppConfiguration>();
|
|
|
|
//
|
|
// Register Allowed Origins ...
|
|
services.AddXCors(appConfiguration.AllowedOrigins);
|
|
|
|
//
|
|
// Register Swagger ...
|
|
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
|
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
|
services.AddXSwagger(Configuration, xmlFilePath: xmlPath);
|
|
|
|
//
|
|
// Register HttpService ...
|
|
services.AddXHttpService(Configuration);
|
|
|
|
//
|
|
// Add Api V1 Versioning ...
|
|
services.AddXApiV1Versioning();
|
|
|
|
//
|
|
// OAuthIntrospectin Http Client Handler ...
|
|
// this is for handling SSLErrors ...
|
|
services.AddHttpClient(OAuth2IntrospectionDefaults.BackChannelHttpClientName)
|
|
.ConfigurePrimaryHttpMessageHandler(() =>
|
|
{
|
|
return new HttpClientHandler
|
|
{
|
|
ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true
|
|
};
|
|
});
|
|
|
|
//
|
|
// Register Authorizations ...
|
|
services.AddXAuthorization();
|
|
|
|
//
|
|
services.AddControllers()
|
|
.AddNewtonsoftJson(x =>
|
|
{
|
|
x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
|
x.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
|
|
});
|
|
|
|
//
|
|
// Custom ...
|
|
|
|
//
|
|
services.Configure<IISServerOptions>(options =>
|
|
{
|
|
options.AllowSynchronousIO = true;
|
|
});
|
|
|
|
//
|
|
services.Configure<KestrelServerOptions>(options =>
|
|
{
|
|
options.AllowSynchronousIO = true;
|
|
});
|
|
|
|
//
|
|
// Register Services ...
|
|
services.AddXServices(
|
|
configuration: Configuration,
|
|
databases: new List<XDatabaseDescriptor>
|
|
{
|
|
apiDatabaseDescriptor
|
|
},
|
|
lifeTime: ServiceLifetime.Scoped
|
|
);
|
|
}
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
//
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
|
|
//
|
|
// Use Swagger Middleware ...
|
|
app.UseXSwagger();
|
|
|
|
//
|
|
app.UseHttpsRedirection();
|
|
|
|
//
|
|
// Using Cors ...
|
|
app.UseXCors();
|
|
|
|
//
|
|
app.UseRouting();
|
|
|
|
//
|
|
// Use xIdentityService ...
|
|
app.UseXIdentityService();
|
|
|
|
//
|
|
app.UseAuthorization();
|
|
|
|
//
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllers();
|
|
});
|
|
|
|
//
|
|
// Use xDataService Middleware ...
|
|
app.UseXServices(
|
|
databases: new List<XDatabaseDescriptor>
|
|
{
|
|
apiDatabaseDescriptor
|
|
},
|
|
isDevelopmentEnvironment: env.IsDevelopment()
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Controllers\AccountController.cs
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.Extensions.Logging;
|
|
using xCommons.Attributes;
|
|
using xCommons.Configurations;
|
|
using xCommons.Providers;
|
|
using xIdentityService.Controllers;
|
|
using xIdentityService.Interfaces;
|
|
|
|
namespace xApi.Controllers
|
|
{
|
|
/// <summary>
|
|
/// Handle all Account Related Actions ...
|
|
/// </summary>
|
|
[AllowAnonymous]
|
|
[RequireXPowered(true)]
|
|
public partial class AccountController : XBaseIdentityController
|
|
{
|
|
//
|
|
#region Props ...
|
|
private readonly IXIdentityProvider identityProvider;
|
|
#endregion
|
|
|
|
//
|
|
#region Constructor ...
|
|
public AccountController(
|
|
ILogger<AccountController> logger,
|
|
XAppConfiguration appConfiguration,
|
|
IXIdentityProvider identityProvider,
|
|
XValidationProvider validationProvider
|
|
) : base(
|
|
logger,
|
|
appConfiguration,
|
|
identityProvider,
|
|
validationProvider
|
|
)
|
|
{
|
|
//
|
|
this.identityProvider = identityProvider;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Controllers\StartupController.cs
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using xCommons.Configurations;
|
|
using xCommons.Controllers;
|
|
using xCommons.Providers;
|
|
|
|
namespace xApi.Controllers {
|
|
/// <summary>
|
|
/// Runing when application start ...
|
|
/// </summary>
|
|
[Route ("")]
|
|
[AllowAnonymous]
|
|
public class StartupController : XBaseController {
|
|
|
|
public StartupController (
|
|
ILogger<StartupController> logger,
|
|
XAppConfiguration appConfiguration,
|
|
XValidationProvider validationProvider
|
|
) : base (
|
|
logger,
|
|
appConfiguration,
|
|
validationProvider
|
|
) { }
|
|
|
|
/// <summary>
|
|
/// Show Configured Welcome Message
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet ("")]
|
|
[AllowAnonymous]
|
|
public virtual ActionResult<string> Index () {
|
|
//
|
|
var controllerName = GetControllerName ();
|
|
var message = $"{AppConfiguration.WelcomeMessage}";
|
|
|
|
//
|
|
return Ok (message);
|
|
}
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Controllers\TestFeaturesController.cs
|
|
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using xCategoryService.Interfaces;
|
|
using xCommons.Configurations;
|
|
using xCommons.Controllers;
|
|
using xCommons.Providers;
|
|
|
|
namespace xApi.Controllers
|
|
{
|
|
[AllowAnonymous]
|
|
public class TestFeaturesController : XBaseApiController
|
|
{
|
|
private readonly IXSubCategoryTitleResourceProvider subCategoryTitleResourceProvider;
|
|
|
|
public TestFeaturesController(
|
|
ILogger<TestFeaturesController> logger,
|
|
XAppConfiguration appConfiguration,
|
|
XValidationProvider validationProvider,
|
|
IXSubCategoryTitleResourceProvider subCategoryTitleResourceProvider
|
|
) : base(
|
|
logger,
|
|
appConfiguration,
|
|
validationProvider
|
|
)
|
|
{
|
|
this.subCategoryTitleResourceProvider = subCategoryTitleResourceProvider;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<ActionResult> TestFeature()
|
|
{
|
|
//
|
|
var result = await subCategoryTitleResourceProvider.GetLanguages(
|
|
identifier: "SSSSAAALLLAAAM"
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Controllers\TestIdentity.cs
|
|
|
|
using System.Linq;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using xCommons.Attributes;
|
|
using xCommons.Configurations;
|
|
using xCommons.Providers;
|
|
using xIdentityHelper;
|
|
using xIdentityService.Controllers;
|
|
using xIdentityService.Interfaces;
|
|
|
|
namespace xApi.Controllers {
|
|
/// <summary>
|
|
/// Test all Authentication Policies ...
|
|
/// </summary>
|
|
[RequireXPowered (false)]
|
|
public class TestIdentity : XBaseIdentityController {
|
|
public TestIdentity (
|
|
ILogger<TestIdentity> logger,
|
|
XAppConfiguration appConfiguration,
|
|
IXIdentityProvider identityProvider,
|
|
XValidationProvider validationProvider
|
|
) : base (
|
|
logger,
|
|
appConfiguration,
|
|
identityProvider,
|
|
validationProvider
|
|
) { }
|
|
|
|
//
|
|
#region Test Actions ...
|
|
/// <summary>
|
|
/// API Read Scope
|
|
/// </summary>
|
|
/// <returns>string message</returns>
|
|
[HttpGet ("PassReadAccess")]
|
|
[Authorize (Policy = XPolicies.ReadAccess)]
|
|
public ActionResult<string> PassReadAccess () {
|
|
return Ok ("Read Access Passed ...");
|
|
}
|
|
|
|
/// <summary>
|
|
/// API Write Scope
|
|
/// </summary>
|
|
/// <returns>string message</returns>
|
|
[HttpGet ("PassWriteAccess")]
|
|
[Authorize (Policy = XPolicies.WriteAccess)]
|
|
public ActionResult<string> PassWriteAccess () {
|
|
return Ok ("Write Access Passed ...");
|
|
}
|
|
|
|
/// <summary>
|
|
/// API Admin Scope
|
|
/// </summary>
|
|
/// <returns>string message</returns>
|
|
[HttpGet ("PassAdminAccess")]
|
|
[Authorize (Policy = XPolicies.AdminAccess)]
|
|
public ActionResult<string> PassAdminAccess () {
|
|
return Ok ("Admin Access Passed ...");
|
|
}
|
|
|
|
/// <summary>
|
|
/// API Manage Scop
|
|
/// </summary>
|
|
/// <returns>string message</returns>
|
|
[HttpGet ("PassManageAccess")]
|
|
[Authorize (Policy = XPolicies.ManageAccess)]
|
|
public ActionResult<string> PassManageAccess () {
|
|
return Ok ("Manage Access Passed ...");
|
|
}
|
|
|
|
/// <summary>
|
|
/// a simple Action which returns a List of Authenticated User Claims
|
|
/// </summary>
|
|
/// <returns>string message which represent current user's claims</returns>
|
|
[HttpGet ("HiClaims")]
|
|
[Authorize (Policy = XPolicies.User)]
|
|
public ActionResult<string> HiClaims () {
|
|
//
|
|
var result = new {
|
|
name = User.Identity.Name,
|
|
claims = User.Claims.Select (c => new {
|
|
c.Type, c.Value
|
|
})
|
|
};
|
|
|
|
//
|
|
return Ok (result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// a simple Hello User for Checking Authentication and Policy
|
|
/// </summary>
|
|
/// <returns>string message which contains authenticated user name</returns>
|
|
[HttpGet ("HiUser")]
|
|
[Authorize (Policy = XPolicies.User)]
|
|
public ActionResult<string> HiUser () {
|
|
//
|
|
var result = $"Hi User: {User.Identity.Name} ...";
|
|
|
|
//
|
|
return Ok (result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// a simple Hello User for Checking Authentication and Policy
|
|
/// </summary>
|
|
/// <returns>string message which contains authenticated user name</returns>
|
|
[HttpGet ("HiEnabledUser")]
|
|
[Authorize (Policy = XPolicies.EnabledUser)]
|
|
public ActionResult<string> HiEnabledUser () {
|
|
//
|
|
var result = $"Hi User: {User.Identity.Name} is Enabled ...";
|
|
|
|
//
|
|
return Ok (result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// a simple Hello User for Checking Authentication and Policy
|
|
/// </summary>
|
|
/// <returns>string message which contains authenticated user name</returns>
|
|
[HttpGet ("HiAgent")]
|
|
[Authorize (Policy = XPolicies.Agent)]
|
|
public ActionResult<string> HiAgent () {
|
|
//
|
|
var result = $"Hi Agent: {User.Identity.Name} ...";
|
|
|
|
//
|
|
return Ok (result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// a simple Hello User for Checking Authentication and Policy
|
|
/// </summary>
|
|
/// <returns>string message which contains authenticated user name</returns>
|
|
[HttpGet ("HiEnabledAgent")]
|
|
[Authorize (Policy = XPolicies.EnabledAgent)]
|
|
public ActionResult<string> HiEnabledAgent () {
|
|
//
|
|
var result = $"Hi Agent: {User.Identity.Name} is Enabled ...";
|
|
|
|
//
|
|
return Ok (result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// a simple Hello User for Checking Authentication and Policy
|
|
/// </summary>
|
|
/// <returns>string message which contains authenticated user name</returns>
|
|
[HttpGet ("HiAdmin")]
|
|
[Authorize (Policy = XPolicies.Admin)]
|
|
public ActionResult<string> HiAdmin () {
|
|
//
|
|
var result = $"Hi Admin: {User.Identity.Name} ...";
|
|
|
|
//
|
|
return Ok (result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// a simple Hello User for Checking Authentication and Policy
|
|
/// </summary>
|
|
/// <returns>string message which contains authenticated user name</returns>
|
|
[HttpGet ("HiEnabledAdmin")]
|
|
[Authorize (Policy = XPolicies.EnabledAdmin)]
|
|
public ActionResult<string> HiEnabledAdmin () {
|
|
//
|
|
var result = $"Hi Admin: {User.Identity.Name} is Enabled ...";
|
|
|
|
//
|
|
return Ok (result);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Controllers\Account\AccountController+Admin.cs
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Controllers\Account\AccountController+Authentication.cs
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using IdentityModel.Client;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using xIdentityHelper;
|
|
using xCommons.Attributes;
|
|
using xCommons.Extensions;
|
|
using xExceptions.Constants;
|
|
using xIdentityModels.Models;
|
|
using xModels.Dtos;
|
|
using static xIdentityHelper.XApiScopeHelper;
|
|
|
|
namespace xApi.Controllers {
|
|
public partial class AccountController {
|
|
//
|
|
#region Authentication Actions ...
|
|
/// <summary>
|
|
/// Retrieve OAuth Discovery Document
|
|
/// </summary>
|
|
/// <returns>an instance of <see>DiscoveryDocumentResponse</see></returns>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpGet ("DiscoveryDocument")]
|
|
public async Task<ActionResult<DiscoveryDocumentResponse>> GetDiscoveryDocument () {
|
|
//
|
|
try {
|
|
//
|
|
var result = await identityProvider
|
|
.RequestDiscoveryDocument ();
|
|
|
|
//
|
|
// Ceck Response Result ...
|
|
if (result.IsError) {
|
|
XException.InvalidConfiguration.Throw ();
|
|
}
|
|
|
|
//
|
|
return Ok (result
|
|
.ToDynamicObject ());
|
|
} 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 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Authenticate User
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sample request:
|
|
///
|
|
/// {
|
|
/// "password": "",
|
|
/// "userSelectBy": "",
|
|
/// }
|
|
///
|
|
/// </remarks>
|
|
/// <param name="model">User Login Required Info, an instance of <see>XLoginRequest</see></param>
|
|
/// <returns>an instance of <see>XTokenResponse</see></returns>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("Authenticate")]
|
|
public async Task<ActionResult<XTokenResponse>> Authenticate (
|
|
[FromBody] XLoginRequest model
|
|
) {
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
if (!ModelState.IsValid) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
await ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotNull (model)
|
|
.AddNotEmpty (
|
|
model.UserSelectBy,
|
|
model.Password
|
|
)
|
|
.ValidateGroupAsync ();
|
|
|
|
//
|
|
var result = await identityProvider
|
|
.Authenticate (model);
|
|
|
|
//
|
|
return Ok (result
|
|
.ToDynamicObject ());
|
|
} catch (Exception ex) {
|
|
//
|
|
var result = GetExceptionActionResult (ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Authenticate User
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sample request:
|
|
///
|
|
/// {
|
|
/// "language": "fa-IR"
|
|
/// "password": "",
|
|
/// "userSelectBy": "",
|
|
/// "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">User Login Required Info, an instance of <see>XLoginRequest</see></param>
|
|
/// <returns>an instance of <see>XLoginResponse</see></returns>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("Login")]
|
|
public async Task<ActionResult<XLoginResponse>> Login (
|
|
[FromBody] XLoginRequest model
|
|
) {
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
if (!ModelState.IsValid) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
await ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotNull (
|
|
model,
|
|
model.Device)
|
|
.AddNotEmpty (
|
|
model.Language,
|
|
model.UserSelectBy,
|
|
model.Password
|
|
)
|
|
.ValidateGroupAsync ();
|
|
|
|
//
|
|
var result = await identityProvider
|
|
.Login (model);
|
|
|
|
//
|
|
return Ok (result
|
|
.ToDynamicObject ());
|
|
} catch (Exception ex) {
|
|
//
|
|
var result = GetExceptionActionResult (ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Logout User
|
|
/// </summary>
|
|
[RequireXPowered]
|
|
[HttpPost ("Logout")]
|
|
[Authorize (Policy = XPolicies.User)]
|
|
public 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>
|
|
/// Refresh Expired Tokens
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// in addition to AccessToken, you had to pass RefreshToken due to Headers
|
|
/// </remarks>
|
|
/// <returns>an instance of <see>XTokenResponse</see></returns>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("RefreshTokens")]
|
|
public async Task<ActionResult<XTokenResponse>> RefreshTokens () {
|
|
//
|
|
try {
|
|
//
|
|
// Retrieve Toke Response ...
|
|
var model = await RetrieveTokensAsXTokenResponse ();
|
|
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotNull (model)
|
|
.AddNotEmpty (
|
|
model.AccessToken,
|
|
model.RefreshToken)
|
|
.ValidateGroup ();
|
|
|
|
//
|
|
var result = await identityProvider
|
|
.RefreshTokens (model);
|
|
|
|
//
|
|
return Ok (result
|
|
.ToDynamicObject ());
|
|
} 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 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;
|
|
}
|
|
}
|
|
#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 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
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Controllers\Account\AccountController+Friendship.cs
|
|
|
|
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.Constants;
|
|
using xIdentityModels.Dtos;
|
|
using xIdentityModels.Navigations;
|
|
using xModels.Dtos;
|
|
using System.Linq;
|
|
using xExceptions.Constants;
|
|
|
|
namespace xApi.Controllers
|
|
{
|
|
public partial class AccountController
|
|
{
|
|
//
|
|
#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 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>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Friendship/{destUser}/Cancel")]
|
|
public 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>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Friendship/{destUser}/UnFollowFollower")]
|
|
public 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>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Friendship/{destUser}/UnFollowFollowing")]
|
|
public 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>
|
|
[HttpPost("Friendship/{destUser}/Block")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public 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>
|
|
[HttpPost("Friendship/{destUser}/UnBlock")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public 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>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Friendship/{destUser}/AcceptRequest")]
|
|
public 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>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Friendship/{destUser}/RejectRequest")]
|
|
public 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>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/FriendshipInfo")]
|
|
public 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>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/IsFollower")]
|
|
public 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>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/FollowerState")]
|
|
public 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>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/Follower")]
|
|
public 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>
|
|
[HttpGet("Friendship/Followers")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public 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>
|
|
[HttpGet("Friendship/AllFollowers")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public 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>
|
|
[HttpGet("Friendship/QueryFollowers")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public 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>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/IsFollowing")]
|
|
public 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>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/FollowingState")]
|
|
public 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>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/Following")]
|
|
public 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>
|
|
[HttpGet("Friendship/Followings")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public 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>
|
|
[HttpGet("Friendship/AllFollowings")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public 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>
|
|
[HttpGet("Friendship/FollowingsList")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public 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>
|
|
[HttpGet("Friendship/FollowersList")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public 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>
|
|
[HttpGet("Friendship/QueryFollowings")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public 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
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Controllers\Account\AccountController+Open.cs
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using xCommons.Attributes;
|
|
using xCommons.Extensions;
|
|
using xModels.Dtos;
|
|
|
|
namespace xApi.Controllers
|
|
{
|
|
public partial class AccountController
|
|
{
|
|
#region Open Actions ...
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpGet("GetUserInfo")]
|
|
public async Task<ActionResult<string>> GetUserInfo(
|
|
[FromHeader] string token,
|
|
[FromQuery] string request
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
await ValidationProvider
|
|
.GroupValidationBuilder()
|
|
.AddNotEmpty(token)
|
|
.AddNotEmpty(request)
|
|
.ValidateGroupAsync();
|
|
|
|
//
|
|
var result = await identityProvider.GetUserInfo(
|
|
token: token,
|
|
request: request
|
|
);
|
|
|
|
//
|
|
// Return Result
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpGet("GetUserInfoByDevice")]
|
|
public async Task<ActionResult<string>> GetUserInfoByDevice(
|
|
[FromQuery] string userSelectByParam,
|
|
[FromBody] XDeviceDto device
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
await ValidationProvider
|
|
.GroupValidationBuilder()
|
|
.AddNotEmpty(userSelectByParam)
|
|
.AddNotNull(device)
|
|
.ValidateGroupAsync();
|
|
|
|
//
|
|
var result = await identityProvider.GetUserInfo(
|
|
userSelectByParam: userSelectByParam,
|
|
device: device
|
|
);
|
|
|
|
//
|
|
// Return Result
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Controllers\Account\AccountController+Profile.cs
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using xIdentityHelper;
|
|
using xCommons.Attributes;
|
|
using xCommons.Extensions;
|
|
using xIdentityModels.Dtos;
|
|
using xIdentityModels.Models;
|
|
using xModels.Dtos;
|
|
|
|
namespace xApi.Controllers
|
|
{
|
|
public partial class AccountController
|
|
{
|
|
//
|
|
#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 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 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 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 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 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 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 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 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 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 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 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
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Controllers\Account\AccountController+Registration.cs
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using xIdentityHelper;
|
|
using xCommons.Attributes;
|
|
using xCommons.Extensions;
|
|
using xExceptions.Constants;
|
|
using xIdentityModels.Constants;
|
|
using xIdentityModels.Extensions;
|
|
using xIdentityModels.Models;
|
|
|
|
namespace xApi.Controllers {
|
|
public partial class AccountController {
|
|
//
|
|
#region Registration ...
|
|
/// <summary>
|
|
/// Check a UserName is Available For Registration or not
|
|
/// </summary>
|
|
/// <param name="userName">an string value which represent desired username</param>
|
|
/// <returns>a boolean value</returns>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpGet ("CanRegisterUserName/{userName?}")]
|
|
public async Task<ActionResult<bool>> CanRegisterUserName (
|
|
[FromRoute] string userName
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty (userName);
|
|
|
|
//
|
|
// Validate Type ...
|
|
var type = userName.GetUserSelectByType ();
|
|
if (type != XUserSelectBy.Username) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
|
|
//
|
|
var result = await identityProvider
|
|
.CanRegister (userName);
|
|
|
|
//
|
|
// Return Result
|
|
return Ok (result);
|
|
} catch (Exception ex) {
|
|
//
|
|
var result = GetExceptionActionResult (ex);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check a Mobile Number is Available For Registration or not
|
|
/// </summary>
|
|
/// <param name="mobileNumber">an string value which represent desired mobile number</param>
|
|
/// <returns>a boolean value</returns>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpGet ("CanRegisterMobileNumber/{mobileNumber?}")]
|
|
public async Task<ActionResult<bool>> CanRegisterMobileNumber (
|
|
[FromRoute] string mobileNumber
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty (mobileNumber);
|
|
|
|
//
|
|
// Validate Type ...
|
|
var type = mobileNumber.GetUserSelectByType ();
|
|
if (type != XUserSelectBy.MobileNumber) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
|
|
//
|
|
var result = await identityProvider
|
|
.CanRegister (mobileNumber);
|
|
|
|
//
|
|
// Return Result
|
|
return Ok (result);
|
|
} catch (Exception ex) {
|
|
//
|
|
var result = GetExceptionActionResult (ex);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check a Email Address is Available For Registration or not
|
|
/// </summary>
|
|
/// <param name="email">an string value which represent desired email address</param>
|
|
/// <returns>a boolean value</returns>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpGet ("CanRegisterEmail/{email?}")]
|
|
public async Task<ActionResult<bool>> CanRegisterEmail (
|
|
[FromRoute] string email
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty (email);
|
|
|
|
//
|
|
// Validate Type ...
|
|
var type = email.GetUserSelectByType ();
|
|
if (type != XUserSelectBy.Email) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
|
|
//
|
|
var result = await identityProvider
|
|
.CanRegister (email);
|
|
|
|
//
|
|
// Return Result
|
|
return Ok (result);
|
|
} catch (Exception ex) {
|
|
//
|
|
var result = GetExceptionActionResult (ex);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <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 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>
|
|
/// Recieve some Basic Informations and Start Registration Proccess
|
|
/// if they Valid
|
|
///
|
|
/// Registration Proccess Starts with Invoking this Action
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// for this action you have to provide:
|
|
/// - Lang: client device currently used locale, such as: en-US.
|
|
/// - FirstName: user's FirstName.
|
|
/// - LastName: user's LastName.
|
|
/// - DateOfBirth: user's dob date.
|
|
/// - MobileNumber: user's MobileNumber optional.
|
|
/// - Email: user's Email optional.
|
|
/// - ActionToken: user's requested action token for this action (if user invited).
|
|
/// - Device: user's client device which is an instance of XDevice.
|
|
///
|
|
/// Sample request:
|
|
///
|
|
/// {
|
|
/// "lang": "fa-IR",
|
|
/// "firstName": "",
|
|
/// "lastName": "",
|
|
/// "dateOfBirth": "",
|
|
/// "email": "",
|
|
/// "mobileNumber": "",
|
|
/// "actionToken": "",
|
|
/// "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>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("RequestRegistration")]
|
|
public async Task<ActionResult<XActionResponse>> RequestRegistration (
|
|
[FromBody] XActionRequest model
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
if (!ModelState.IsValid) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
await ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotEmpty (
|
|
model.Lang,
|
|
model.FirstName,
|
|
model.LastName)
|
|
.AddNotNull (
|
|
model.Device,
|
|
model.DateOfBirth)
|
|
.ValidateGroupAsync ();
|
|
|
|
//
|
|
// Get Request ...
|
|
var result = await identityProvider
|
|
.RequestRegistration (
|
|
model
|
|
);
|
|
|
|
//
|
|
return Ok (result
|
|
.ToDynamicObject ());
|
|
} catch (Exception ex) {
|
|
//
|
|
var exResult = GetExceptionActionResult (ex);
|
|
|
|
//
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add User Account Informations
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// for this action you have to provide:
|
|
/// - Lang: client device currently used locale, such as: en-US.
|
|
/// - ActionToken: user's requested action token for this action.
|
|
/// - UserName: user name.
|
|
/// - Password: assigne password.
|
|
/// - Device: user's client device which is an instance of XDevice.
|
|
///
|
|
/// Sample request:
|
|
///
|
|
/// {
|
|
/// "lang": "fa-IR",
|
|
/// "userName": "",
|
|
/// "password": "",
|
|
/// "actionToken": "",
|
|
/// "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>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("AddAccountInfo")]
|
|
public async Task<ActionResult<XActionResponse>> AddAccountInfo (
|
|
[FromBody] XActionRequest model
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
if (!ModelState.IsValid) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
await ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotEmpty (
|
|
model.Lang,
|
|
model.ActionToken,
|
|
model.UserName,
|
|
model.Password)
|
|
.AddNotNull (model.Device)
|
|
.ValidateGroupAsync ();
|
|
|
|
//
|
|
// Get Request ...
|
|
var result = await identityProvider
|
|
.AddAccountInfo (
|
|
model
|
|
);
|
|
|
|
//
|
|
return Ok (result
|
|
.ToDynamicObject ());
|
|
} catch (Exception ex) {
|
|
//
|
|
var exResult = GetExceptionActionResult (ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Upload and Attach a Profile Image for User. this is an Optional Step
|
|
/// </summary>
|
|
/// <param name="actionToken">user's requested action token</param>
|
|
/// <param name="file">an instance of <see>IFormFile</see> for user's Avatar</param>
|
|
/// <returns>an instance of <see>XActionResponse</see></returns>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("AttachProfileImage")]
|
|
public async Task<ActionResult<XActionResponse>> AttachProfileImage (
|
|
[FromForm] string actionToken, [FromForm] IFormFile file
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
await ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotEmpty (actionToken)
|
|
.AddNotNull (file)
|
|
.ValidateGroupAsync ();
|
|
|
|
//
|
|
var result = await identityProvider
|
|
.AttachProfileImage (
|
|
actionToken,
|
|
file
|
|
);
|
|
|
|
//
|
|
return Ok (result
|
|
.ToDynamicObject ());
|
|
} catch (Exception ex) {
|
|
//
|
|
var exResult = GetExceptionActionResult (ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Finish Registrationn Proccess
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// for this action you have to provide:
|
|
/// - a proper User Identifier such as: (UserId, UserName, Email or MobileNumber).
|
|
/// - Lang: client device currently used locale, such as: en-US.
|
|
/// - ActionToken: user's requested action token for this action.
|
|
/// - Password: assigne password.
|
|
/// - Device: user's client device which is an instance of XDevice.
|
|
/// - ReturnUrl: client application Login URL.
|
|
///
|
|
/// Sample request:
|
|
///
|
|
/// {
|
|
/// "lang": "fa-IR",
|
|
/// "userName": "",
|
|
/// "password": "",
|
|
/// "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></returns>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("FinishRegistration")]
|
|
public async Task<ActionResult> FinishRegistration (
|
|
[FromBody] XActionRequest model
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
if (!ModelState.IsValid) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
await ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotEmpty (
|
|
model.Lang,
|
|
model.Password,
|
|
model.ReturnUrl)
|
|
.AddNotNull (model.Device)
|
|
.AddUrl (model.ReturnUrl)
|
|
.ValidateGroupAsync ();
|
|
|
|
//
|
|
var userSelectByParam = identityProvider
|
|
.GetUserSelectByParam (model);
|
|
ValidationProvider
|
|
.NotEmpty (userSelectByParam);
|
|
|
|
//
|
|
// Get Request ...
|
|
await identityProvider
|
|
.FinishRegistration (model);
|
|
|
|
//
|
|
return Ok ();
|
|
} catch (Exception ex) {
|
|
//
|
|
var exResult = GetExceptionActionResult (ex);
|
|
|
|
//
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check User is Confirmed Email or not
|
|
/// </summary>
|
|
/// <returns>a boolean value</returns>
|
|
[RequireXPowered]
|
|
[HttpGet ("IsConfirmedEmail")]
|
|
[Authorize (Policy = XPolicies.User)]
|
|
public 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 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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Request Registration Confirm
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// for this action you have to provide:
|
|
/// - a UserSelectedBy identifier which represet User.
|
|
/// - Lang: client device currently used locale, such as: en-US.
|
|
/// - Password: user's current active password.
|
|
/// - Device: user's client device which is an instance of XDevice.
|
|
/// - ReturnUrl: client application Confirm Registration URL.
|
|
///
|
|
/// Sample request:
|
|
///
|
|
/// {
|
|
/// "lang": "fa-IR",
|
|
/// "userId": ""
|
|
/// "password": "",
|
|
/// "returnUrl": "http://localhost/confirm",
|
|
/// "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>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("RequestConfirmRegistration")]
|
|
public async Task<ActionResult> RequestConfirmRegistration (
|
|
[FromBody] XActionRequest model
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
if (!ModelState.IsValid) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
await ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotEmpty (
|
|
model.Lang,
|
|
model.Password,
|
|
model.ReturnUrl)
|
|
.AddNotNull (model.Device)
|
|
.AddUrl (model.ReturnUrl)
|
|
.ValidateGroupAsync ();
|
|
|
|
//
|
|
// Get UserSelect By Param ...
|
|
var userSelectByParam = model.GetUserSelectByParam ();
|
|
ValidationProvider.NotEmpty (userSelectByParam);
|
|
|
|
//
|
|
await identityProvider
|
|
.RequestConfirmRegistration (model);
|
|
|
|
//
|
|
return Ok ();
|
|
} catch (Exception ex) {
|
|
//
|
|
var exResult = GetExceptionActionResult (ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Confirm Registration
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// for this action you have to provide:
|
|
/// - Lang: client device currently used locale, such as: en-US.
|
|
/// - ActionToken: user's requested action token for this action.
|
|
/// - Device: user's client device which is an instance of XDevice.
|
|
/// - ReturnUrl: client application Login URL.
|
|
///
|
|
/// Sample request:
|
|
///
|
|
/// {
|
|
/// "lang": "fa-IR",
|
|
/// "actionToken": ""
|
|
/// "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>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("ConfirmRegistration")]
|
|
public async Task<ActionResult> ConfirmRegistration (
|
|
[FromBody] XActionRequest model
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
if (!ModelState.IsValid) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
await ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotEmpty (
|
|
model.Lang,
|
|
model.ActionToken,
|
|
model.ReturnUrl
|
|
)
|
|
.AddNotNull (model.Device)
|
|
.ValidateGroupAsync ();
|
|
|
|
//
|
|
// Get Request ...
|
|
await identityProvider
|
|
.ConfirmRegistration (model);
|
|
|
|
//
|
|
return Ok ();
|
|
} catch (Exception ex) {
|
|
//
|
|
var exResult = GetExceptionActionResult (ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Request For Mobile Number Change/Confirm
|
|
/// </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.
|
|
/// - MobileNumber: which phone number is going to confirm.
|
|
/// - Device: user's client device which is an instance of XDevice.
|
|
///
|
|
/// Sample request:
|
|
///
|
|
/// {
|
|
/// "lang": "fa-IR",
|
|
/// "password": "",
|
|
/// "mobileNumber": "",
|
|
/// "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>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("RequestConfirmMobile")]
|
|
public async Task<ActionResult<XActionResponse>> RequestConfirmMobile (
|
|
[FromBody] XActionRequest model
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
if (!ModelState.IsValid) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
await ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotEmpty (
|
|
model.Lang,
|
|
model.Password,
|
|
model.MobileNumber)
|
|
.AddNotNull (model.Device)
|
|
.AddMobileNumber (model.MobileNumber)
|
|
.ValidateGroupAsync ();
|
|
|
|
//
|
|
// Get UserSelect By Param ...
|
|
var userSelectByParam = GetUserSelectByParam (
|
|
model,
|
|
excludes : new List<XUserSelectBy> {
|
|
XUserSelectBy.Email,
|
|
XUserSelectBy.MobileNumber
|
|
});
|
|
|
|
//
|
|
// Get Request ...
|
|
var result = await identityProvider
|
|
.RequestConfirmMobile (model);
|
|
|
|
//
|
|
return Ok (result
|
|
.ToDynamicObject ());
|
|
} catch (Exception ex) {
|
|
//
|
|
var exResult = GetExceptionActionResult (ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Confirm Requested Mobile Number
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// for this action you have to provide:
|
|
/// - Lang: client device currently used locale, such as: en-US.
|
|
/// - ActionToken: user's requested action token for this action.
|
|
/// - Device: user's client device which is an instance of XDevice.
|
|
/// - MobileVerificationCode: a verification code which produced due Request Action.
|
|
///
|
|
/// Sample request:
|
|
///
|
|
/// {
|
|
/// "lang": "fa-IR",
|
|
/// "actionToken": ""
|
|
/// "mobileVerificationCode": "",
|
|
/// "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>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("ConfirmMobileNumber")]
|
|
public async Task<ActionResult<XActionResponse>> ConfirmMobileNumber (
|
|
[FromBody] XActionRequest model
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
if (!ModelState.IsValid) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
await ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotEmpty (
|
|
model.Lang,
|
|
model.MobileVerificationCode,
|
|
model.ActionToken
|
|
)
|
|
.AddNotNull (model.Device)
|
|
.ValidateGroupAsync ();
|
|
|
|
//
|
|
// Get Request ...
|
|
var result = await identityProvider
|
|
.ConfirmMobileNumber (model);
|
|
|
|
//
|
|
return Ok (result
|
|
.ToDynamicObject ());
|
|
} catch (Exception ex) {
|
|
//
|
|
var exResult = GetExceptionActionResult (ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Request For Email Address Change/Confirm
|
|
/// </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.
|
|
/// - Email: which email address is going to confirm.
|
|
/// - Device: user's client device which is an instance of XDevice.
|
|
///
|
|
/// Sample request:
|
|
///
|
|
/// {
|
|
/// "lang": "fa-IR",
|
|
/// "password": "",
|
|
/// "email": "",
|
|
/// "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>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("RequestConfirmEmail")]
|
|
public async Task<ActionResult<XActionResponse>> RequestConfirmEmail (
|
|
[FromBody] XActionRequest model
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
if (!ModelState.IsValid) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
await ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotEmpty (
|
|
model.Lang,
|
|
model.Email,
|
|
model.Password)
|
|
.AddNotNull (model.Device)
|
|
.AddEmailAddress (model.Email)
|
|
.ValidateGroupAsync ();
|
|
|
|
//
|
|
// Get UserSelect By Param ...
|
|
var userSelectByParam = GetUserSelectByParam (
|
|
model,
|
|
excludes : new List<XUserSelectBy> {
|
|
XUserSelectBy.Email,
|
|
XUserSelectBy.MobileNumber
|
|
});
|
|
|
|
//
|
|
// Get Request ...
|
|
var result = await identityProvider
|
|
.RequestConfirmEmail (model);
|
|
|
|
//
|
|
return Ok (result
|
|
.ToDynamicObject ());
|
|
} catch (Exception ex) {
|
|
//
|
|
var exResult = GetExceptionActionResult (ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Confirm Requested Email Address
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// for this action you have to provide:
|
|
/// - Lang: client device currently used locale, such as: en-US.
|
|
/// - ActionToken: user's requested action token for this action.
|
|
/// - Device: user's client device which is an instance of XDevice.
|
|
/// - EmailVerificationCode: a verification code which produced due Request Action.
|
|
///
|
|
/// Sample request:
|
|
///
|
|
/// {
|
|
/// "lang": "fa-IR",
|
|
/// "actionToken": ""
|
|
/// "emailVerificationCode": "",
|
|
/// "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>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("ConfirmEmailAddress")]
|
|
public async Task<ActionResult<XActionResponse>> ConfirmEmailAddress (
|
|
[FromBody] XActionRequest model
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
if (!ModelState.IsValid) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
await ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotEmpty (
|
|
model.Lang,
|
|
model.EmailVerificationCode,
|
|
model.ActionToken
|
|
)
|
|
.AddNotNull (model.Device)
|
|
.ValidateGroupAsync ();
|
|
|
|
//
|
|
// Get Request ...
|
|
var result = await identityProvider
|
|
.ConfirmEmailAddress (model);
|
|
|
|
//
|
|
return Ok (result
|
|
.ToDynamicObject ());
|
|
} catch (Exception ex) {
|
|
//
|
|
var exResult = GetExceptionActionResult (ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Request Reset Password Action
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// for this action you have to provide:
|
|
/// - Lang: client device currently used locale, such as: en-US.
|
|
/// - Device: user's client device which is an instance of XDevice.
|
|
/// - ReturnUrl: client application ResetPassword URL.
|
|
///
|
|
/// Sample request:
|
|
///
|
|
/// {
|
|
/// "lang": "fa-IR",
|
|
/// "returnUrl": "http://localhost/reset-password",
|
|
/// "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>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("RequestResetPassword")]
|
|
public async Task<ActionResult<XActionResponse>> RequestResetPassword (
|
|
[FromBody] XActionRequest model
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
if (!ModelState.IsValid) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
await ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotEmpty (
|
|
model.Lang,
|
|
model.ReturnUrl)
|
|
.AddNotNull (model.Device)
|
|
.AddUrl (model.ReturnUrl)
|
|
.ValidateGroupAsync ();
|
|
|
|
//
|
|
// Get UserSelect By Param ...
|
|
var userSelectByParam = GetUserSelectByParam (
|
|
model,
|
|
excludes : new List<XUserSelectBy> {
|
|
XUserSelectBy.Email,
|
|
XUserSelectBy.MobileNumber
|
|
});
|
|
|
|
//
|
|
// Get Request ...
|
|
var result = await identityProvider
|
|
.RequestResetPassword (model);
|
|
|
|
//
|
|
return Ok (result
|
|
.ToDynamicObject ());
|
|
} catch (Exception ex) {
|
|
//
|
|
var exResult = GetExceptionActionResult (ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset a User's Password
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// for this action you have to provide:
|
|
/// - Lang: client device currently used locale, such as: en-US.
|
|
/// - ActionToken: user's requested action token for this action.
|
|
/// - 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",
|
|
/// "actionToken": "",
|
|
/// "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>
|
|
[AllowAnonymous]
|
|
[RequireXPowered]
|
|
[HttpPost ("ResetPassword")]
|
|
public async Task<ActionResult> ResetPassword (
|
|
[FromBody] XActionRequest model
|
|
) {
|
|
//
|
|
// Do Action ...
|
|
try {
|
|
//
|
|
// Validate Args ...
|
|
if (!ModelState.IsValid) {
|
|
XException.InvalidArgs.Throw ();
|
|
}
|
|
await ValidationProvider
|
|
.GroupValidationBuilder ()
|
|
.AddNotEmpty (
|
|
model.Lang,
|
|
model.ActionToken,
|
|
model.NewPassword,
|
|
model.ReturnUrl)
|
|
.AddNotNull (model.Device)
|
|
.ValidateGroupAsync ();
|
|
|
|
//
|
|
// Get Request ...
|
|
await identityProvider
|
|
.ResetPassword (model);
|
|
|
|
//
|
|
return Ok ();
|
|
} catch (Exception ex) {
|
|
//
|
|
var exResult = GetExceptionActionResult (ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Controllers\Account\AccountController+Search.cs
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using xCommons.Attributes;
|
|
using xCommons.Extensions;
|
|
using xIdentityHelper;
|
|
using xIdentityModels.Dtos;
|
|
using xModels.Dtos;
|
|
|
|
namespace xApi.Controllers
|
|
{
|
|
public partial class AccountController
|
|
{
|
|
//
|
|
#region Actions ...
|
|
/// <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 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
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Extensions\XStartupExtensions.cs
|
|
|
|
using System.Collections.Generic;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using xIdentityHelper;
|
|
using xCommons.Authorization;
|
|
using xCommons.Extensions;
|
|
|
|
namespace xApi.Extensions {
|
|
public static class XStartupExtensions {
|
|
/// <summary>
|
|
/// Register Authorization Policies
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <param name="policies"></param>
|
|
public static void AddXAuthorization (
|
|
this IServiceCollection services,
|
|
IDictionary<string, AuthorizationPolicy> policies = null
|
|
) {
|
|
//
|
|
services.AddAuthorization (options => {
|
|
//
|
|
if (!policies.IsNull ()) {
|
|
//
|
|
// Fill Policies ...
|
|
using (var policiesEnumerator = policies.GetEnumerator ()) {
|
|
while (policiesEnumerator.MoveNext ()) {
|
|
var policyDescriptor = policiesEnumerator.Current;
|
|
options.AddPolicy (policyDescriptor.Key, policyDescriptor.Value);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
var xPolicies = XAuthorizationHelper.GetXAuthorizationPolicies ();
|
|
if (!xPolicies.IsNull ()) {
|
|
//
|
|
// Fill Policies ...
|
|
using (var policiesEnumerator = xPolicies.GetEnumerator ()) {
|
|
while (policiesEnumerator.MoveNext ()) {
|
|
var policyDescriptor = policiesEnumerator.Current;
|
|
options.AddPolicy (policyDescriptor.Key, policyDescriptor.Value);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
//
|
|
services.AddSingleton<IAuthorizationHandler, RequiredRolesHandler> ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Use Forward Headers Options for resolving behind a proxy issues ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <returns></returns>
|
|
public static void UseXForwardOptions (this IApplicationBuilder source) {
|
|
//
|
|
var forwardOptions = new ForwardedHeadersOptions {
|
|
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto,
|
|
RequireHeaderSymmetry = false
|
|
};
|
|
|
|
//
|
|
forwardOptions.KnownNetworks.Clear ();
|
|
forwardOptions.KnownProxies.Clear ();
|
|
|
|
//
|
|
// ref: https://github.com/aspnet/Docs/issues/2384
|
|
source.UseForwardedHeaders (forwardOptions);
|
|
}
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Extensions\XUserClaimsInfoDtoExtensions.cs
|
|
|
|
using xCommons.Extensions;
|
|
using xIdentityModels.Constants;
|
|
using xIdentityModels.Models;
|
|
|
|
namespace xApi.Extensions {
|
|
public static class XUserClaimsInfoDtoExtensions {
|
|
public static string GetUserSelectByParam (
|
|
this XUserClaimsInfoDto source,
|
|
XUserSelectBy userSelectBy = XUserSelectBy.Username
|
|
) {
|
|
//
|
|
var result = "";
|
|
|
|
//
|
|
switch (userSelectBy) {
|
|
//
|
|
case XUserSelectBy.ID:
|
|
result = source.UserId;
|
|
break;
|
|
|
|
//
|
|
case XUserSelectBy.Username:
|
|
result = source.UserName;
|
|
break;
|
|
|
|
//
|
|
case XUserSelectBy.Email:
|
|
result = source.Email;
|
|
break;
|
|
|
|
//
|
|
case XUserSelectBy.MobileNumber:
|
|
result = source.PhoneNumber;
|
|
break;
|
|
}
|
|
|
|
//
|
|
if (result.IsNullOrEmpty ()) {
|
|
//
|
|
if (!source.UserId.IsNullOrEmpty ()) {
|
|
result = source.UserId;
|
|
} else if (!source.UserName.IsNullOrEmpty ()) {
|
|
result = source.UserName;
|
|
} else if (!source.Email.IsNullOrEmpty ()) {
|
|
result = source.Email;
|
|
} else if (!source.PhoneNumber.IsNullOrEmpty ()) {
|
|
result = source.PhoneNumber;
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Migrations\20260906032546_InitialMigration.cs
|
|
|
|
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
namespace xApi.Migrations
|
|
{
|
|
public partial class InitialMigration : Migration
|
|
{
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "Categories",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(nullable: false)
|
|
.Annotation("Sqlite:Autoincrement", true),
|
|
Deleted = table.Column<bool>(nullable: false),
|
|
Title = table.Column<string>(nullable: true),
|
|
Description = table.Column<string>(nullable: true),
|
|
References = table.Column<string>(nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Categories", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Contents",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(nullable: false),
|
|
Deleted = table.Column<bool>(nullable: false),
|
|
OwnerId = table.Column<string>(maxLength: 255, nullable: false),
|
|
Title = table.Column<string>(maxLength: 255, nullable: false),
|
|
Description = table.Column<string>(maxLength: 255, nullable: true),
|
|
CreatedOn = table.Column<DateTime>(nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Contents", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Files",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(nullable: false),
|
|
Deleted = table.Column<bool>(nullable: false),
|
|
Type = table.Column<int>(nullable: false),
|
|
OwnerId = table.Column<string>(maxLength: 255, nullable: false),
|
|
Name = table.Column<string>(maxLength: 255, nullable: false),
|
|
Path = table.Column<string>(nullable: false),
|
|
Thumb = table.Column<string>(nullable: true),
|
|
ThumbPath = table.Column<string>(nullable: true),
|
|
UploadedOn = table.Column<DateTime>(nullable: false),
|
|
FileName = table.Column<string>(nullable: true),
|
|
References = table.Column<string>(nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Files", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Strings",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(nullable: false)
|
|
.Annotation("Sqlite:Autoincrement", true),
|
|
Deleted = table.Column<bool>(nullable: false),
|
|
Language = table.Column<string>(maxLength: 10, nullable: false),
|
|
ResourceTitle = table.Column<string>(maxLength: 255, nullable: false),
|
|
TranslatedValue = table.Column<string>(nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Strings", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "SubCategories",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(nullable: false)
|
|
.Annotation("Sqlite:Autoincrement", true),
|
|
Deleted = table.Column<bool>(nullable: false),
|
|
Title = table.Column<string>(nullable: true),
|
|
Description = table.Column<string>(nullable: true),
|
|
References = table.Column<string>(nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_SubCategories", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Tags",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(nullable: false)
|
|
.Annotation("Sqlite:Autoincrement", true),
|
|
Deleted = table.Column<bool>(nullable: false),
|
|
Tag = table.Column<string>(maxLength: 255, nullable: false),
|
|
References = table.Column<string>(nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Tags", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Tests",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(nullable: false),
|
|
Deleted = table.Column<bool>(nullable: false),
|
|
Firstname = table.Column<string>(nullable: true),
|
|
Lastname = table.Column<string>(nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Tests", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Webinars",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(nullable: false),
|
|
Deleted = table.Column<bool>(nullable: false),
|
|
Title = table.Column<string>(maxLength: 255, nullable: false),
|
|
Description = table.Column<string>(maxLength: 255, nullable: false),
|
|
OwnerId = table.Column<string>(nullable: false),
|
|
Type = table.Column<int>(nullable: false),
|
|
CreatedOn = table.Column<DateTime>(nullable: false),
|
|
Enabled = table.Column<bool>(nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Webinars", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "WebinarSubscribers",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(nullable: false)
|
|
.Annotation("Sqlite:Autoincrement", true),
|
|
Deleted = table.Column<bool>(nullable: false),
|
|
SubscriberId = table.Column<string>(nullable: false),
|
|
WebinarId = table.Column<Guid>(nullable: false),
|
|
SubscribedOn = table.Column<DateTime>(nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_WebinarSubscribers", x => x.Id);
|
|
});
|
|
}
|
|
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "Categories");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Contents");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Files");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Strings");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "SubCategories");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Tags");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Tests");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Webinars");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "WebinarSubscribers");
|
|
}
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Migrations\20260906032546_InitialMigration.Designer.cs
|
|
|
|
// <auto-generated />
|
|
using System;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
using xServices.Databases;
|
|
|
|
namespace xApi.Migrations
|
|
{
|
|
[DbContext(typeof(XApiDbContext))]
|
|
[Migration("20260906032546_InitialMigration")]
|
|
partial class InitialMigration
|
|
{
|
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|
{
|
|
#pragma warning disable 612, 618
|
|
modelBuilder
|
|
.HasAnnotation("ProductVersion", "3.1.14");
|
|
|
|
modelBuilder.Entity("xCategoryService.Models.Entities.XCategory", b =>
|
|
{
|
|
b.Property<int>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("Description")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("References")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("Title")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("Categories");
|
|
});
|
|
|
|
modelBuilder.Entity("xCategoryService.Models.Entities.XSubCategory", b =>
|
|
{
|
|
b.Property<int>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("Description")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("References")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("Title")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("SubCategories");
|
|
});
|
|
|
|
modelBuilder.Entity("xContentService.Models.Entities.XContent", b =>
|
|
{
|
|
b.Property<Guid>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<DateTime>("CreatedOn")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("Description")
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<string>("OwnerId")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<string>("Title")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<DateTime>("UpdatedAt")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("Contents");
|
|
});
|
|
|
|
modelBuilder.Entity("xFileService.Models.Entities.XFile", b =>
|
|
{
|
|
b.Property<Guid>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("FileName")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("Name")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<string>("OwnerId")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<string>("Path")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("References")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("Thumb")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("ThumbPath")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<int>("Type")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<DateTime>("UploadedOn")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("Files");
|
|
});
|
|
|
|
modelBuilder.Entity("xServices.Models.Entities.XTest", b =>
|
|
{
|
|
b.Property<Guid>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("Firstname")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("Lastname")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("Tests");
|
|
});
|
|
|
|
modelBuilder.Entity("xStringService.Models.Entities.XString", b =>
|
|
{
|
|
b.Property<int>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("Language")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(10);
|
|
|
|
b.Property<string>("ResourceTitle")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<string>("TranslatedValue")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("Strings");
|
|
});
|
|
|
|
modelBuilder.Entity("xTagService.Models.Entities.XTag", b =>
|
|
{
|
|
b.Property<int>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("References")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("Tag")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("Tags");
|
|
});
|
|
|
|
modelBuilder.Entity("xWebinarService.Models.Entities.XWebinar", b =>
|
|
{
|
|
b.Property<Guid>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<DateTime>("CreatedOn")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("Description")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<bool>("Enabled")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("OwnerId")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("Title")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<int>("Type")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("Webinars");
|
|
});
|
|
|
|
modelBuilder.Entity("xWebinarService.Models.Entities.XWebinarSubscriber", b =>
|
|
{
|
|
b.Property<int>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<DateTime>("SubscribedOn")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("SubscriberId")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<Guid>("WebinarId")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("WebinarSubscribers");
|
|
});
|
|
#pragma warning restore 612, 618
|
|
}
|
|
}
|
|
}
|
|
|
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xApi\Migrations\XApiDbContextModelSnapshot.cs
|
|
|
|
// <auto-generated />
|
|
using System;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
using xServices.Databases;
|
|
|
|
namespace xApi.Migrations
|
|
{
|
|
[DbContext(typeof(XApiDbContext))]
|
|
partial class XApiDbContextModelSnapshot : ModelSnapshot
|
|
{
|
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
|
{
|
|
#pragma warning disable 612, 618
|
|
modelBuilder
|
|
.HasAnnotation("ProductVersion", "3.1.14");
|
|
|
|
modelBuilder.Entity("xCategoryService.Models.Entities.XCategory", b =>
|
|
{
|
|
b.Property<int>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("Description")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("References")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("Title")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("Categories");
|
|
});
|
|
|
|
modelBuilder.Entity("xCategoryService.Models.Entities.XSubCategory", b =>
|
|
{
|
|
b.Property<int>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("Description")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("References")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("Title")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("SubCategories");
|
|
});
|
|
|
|
modelBuilder.Entity("xContentService.Models.Entities.XContent", b =>
|
|
{
|
|
b.Property<Guid>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<DateTime>("CreatedOn")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("Description")
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<string>("OwnerId")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<string>("Title")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<DateTime>("UpdatedAt")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("Contents");
|
|
});
|
|
|
|
modelBuilder.Entity("xFileService.Models.Entities.XFile", b =>
|
|
{
|
|
b.Property<Guid>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("FileName")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("Name")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<string>("OwnerId")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<string>("Path")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("References")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("Thumb")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("ThumbPath")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<int>("Type")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<DateTime>("UploadedOn")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("Files");
|
|
});
|
|
|
|
modelBuilder.Entity("xServices.Models.Entities.XTest", b =>
|
|
{
|
|
b.Property<Guid>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("Firstname")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("Lastname")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("Tests");
|
|
});
|
|
|
|
modelBuilder.Entity("xStringService.Models.Entities.XString", b =>
|
|
{
|
|
b.Property<int>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("Language")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(10);
|
|
|
|
b.Property<string>("ResourceTitle")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<string>("TranslatedValue")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("Strings");
|
|
});
|
|
|
|
modelBuilder.Entity("xTagService.Models.Entities.XTag", b =>
|
|
{
|
|
b.Property<int>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("References")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("Tag")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("Tags");
|
|
});
|
|
|
|
modelBuilder.Entity("xWebinarService.Models.Entities.XWebinar", b =>
|
|
{
|
|
b.Property<Guid>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<DateTime>("CreatedOn")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("Description")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<bool>("Enabled")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<string>("OwnerId")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("Title")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT")
|
|
.HasMaxLength(255);
|
|
|
|
b.Property<int>("Type")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("Webinars");
|
|
});
|
|
|
|
modelBuilder.Entity("xWebinarService.Models.Entities.XWebinarSubscriber", b =>
|
|
{
|
|
b.Property<int>("Id")
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<bool>("Deleted")
|
|
.HasColumnType("INTEGER");
|
|
|
|
b.Property<DateTime>("SubscribedOn")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<string>("SubscriberId")
|
|
.IsRequired()
|
|
.HasColumnType("TEXT");
|
|
|
|
b.Property<Guid>("WebinarId")
|
|
.HasColumnType("TEXT");
|
|
|
|
b.HasKey("Id");
|
|
|
|
b.ToTable("WebinarSubscribers");
|
|
});
|
|
#pragma warning restore 612, 618
|
|
}
|
|
}
|
|
}
|