diff --git a/src/Services/auth/O2NextGen.Auth.Web/O2NextGen.Auth.Web.csproj b/src/Services/auth/O2NextGen.Auth.Web/O2NextGen.Auth.Web.csproj index eb2e1535..88c5d56c 100644 --- a/src/Services/auth/O2NextGen.Auth.Web/O2NextGen.Auth.Web.csproj +++ b/src/Services/auth/O2NextGen.Auth.Web/O2NextGen.Auth.Web.csproj @@ -1,7 +1,7 @@ - net6.0 + netcoreapp3.1 OutOfProcess ../../../docker-compose.dcproj adca6dac-ab6b-4a1a-b8c4-03f600c16f45 @@ -14,7 +14,6 @@ - @@ -27,6 +26,11 @@ + + + + + @@ -79,6 +83,12 @@ + + + + + + diff --git a/src/Services/auth/O2NextGen.Auth.Web/Services/ESenderService.cs b/src/Services/auth/O2NextGen.Auth.Web/Services/ESenderService.cs index 379dbaf0..0f93b4a7 100644 --- a/src/Services/auth/O2NextGen.Auth.Web/Services/ESenderService.cs +++ b/src/Services/auth/O2NextGen.Auth.Web/Services/ESenderService.cs @@ -1,11 +1,30 @@ using System; using System.Net.Http; +using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Options; +using Newtonsoft.Json; namespace O2NextGen.Auth.Web.Services { + public static class HttpClientExtensions + { + public static Task PostAsJsonAsync( + this HttpClient httpClient, string url, T data, CancellationToken cancellationToken) + { + var dataAsString = JsonConvert.SerializeObject(data); + var content = new StringContent(dataAsString); + content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); + return httpClient.PostAsync(url, content, cancellationToken); + } + + public static async Task ReadAsJsonAsync(this HttpContent content, CancellationToken cancellationToken) + { + var dataAsString = await content.ReadAsStringAsync(); + return JsonConvert.DeserializeObject(dataAsString); + } + } public interface IESenderService { Task Send(string email, string subject, string htmlMessage); @@ -30,7 +49,7 @@ public async Task Send(string email, string subject, string htmlMessage) Body = htmlMessage }; var response = await _httpClient.PostAsJsonAsync("api/emailsender",model,CancellationToken.None); - await response.Content.ReadAsAsync(CancellationToken.None); + await response.Content.ReadAsJsonAsync(CancellationToken.None); } } } \ No newline at end of file diff --git a/src/Services/auth/O2NextGen.Auth.Web/Startup.cs b/src/Services/auth/O2NextGen.Auth.Web/Startup.cs index e9d2f28e..2c015f15 100644 --- a/src/Services/auth/O2NextGen.Auth.Web/Startup.cs +++ b/src/Services/auth/O2NextGen.Auth.Web/Startup.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using O2NextGen.Auth.Web.Extensions; using O2NextGen.Auth.Web.Helpers; @@ -24,7 +25,7 @@ public Startup(IConfiguration configuration) public void ConfigureServices(IServiceCollection services) { services.AddMvc() - .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) + .SetCompatibilityVersion(CompatibilityVersion.Version_3_0) .AddRazorPagesOptions(options => { options.Conventions.AuthorizeFolder("/Account"); @@ -53,7 +54,7 @@ public void ConfigureServices(IServiceCollection services) services.AddSingleton(); } - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); @@ -71,7 +72,6 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) app.UseRequestLocalization(v); app.UseCookiePolicy(); app.UseAuthentication(); - app.UseMvcWithDefaultRoute(); } } diff --git a/src/Services/on-tracker/O2NextGen.OnTracker.Api/Controllers/GeoController.cs b/src/Services/on-tracker/O2NextGen.OnTracker.Api/Controllers/GeoController.cs index b80dc7b7..ac17eaf2 100644 --- a/src/Services/on-tracker/O2NextGen.OnTracker.Api/Controllers/GeoController.cs +++ b/src/Services/on-tracker/O2NextGen.OnTracker.Api/Controllers/GeoController.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; using System.Linq; using System.Net; using Microsoft.AspNetCore.Http.Features; @@ -11,21 +12,31 @@ namespace O2NextGen.OnTracker.Api.Controllers [ApiController] public class GeoController : ControllerBase { + #region Fields private readonly IGeoIpAddressResolver _geoIpAddressResolver; + #endregion + + #region Ctors public GeoController(IGeoIpAddressResolver geoIpAddressResolver) { _geoIpAddressResolver = geoIpAddressResolver; } + #endregion + + + #region Methods // GET api/values [HttpGet] public ActionResult Get() { - Debug.WriteLine("start"); + Console.WriteLine("start"); // var ip = HttpContext.Features.Get()?.RemoteIpAddress; - //IPAddress remoteIpAddress = HttpContext.Features.Get()?.RemoteIpAddress;//Request.HttpContext.Connection.RemoteIpAddress; + //IPAddress remoteIpAddress = HttpContext.Features.Get()?.RemoteIpAddress; + //Request.HttpContext.Connection.RemoteIpAddress; //IPAddress remoteIpAddress = Request.HttpContext.Connection.RemoteIpAddress;// - IPAddress remoteIpAddress = HttpContext.Features.Get()?.RemoteIpAddress; + //IPAddress remoteIpAddress = HttpContext.Features.Get()?.RemoteIpAddress; + IPAddress remoteIpAddress = Request.HttpContext.Connection.RemoteIpAddress; string result = ""; if (remoteIpAddress != null) { @@ -38,13 +49,13 @@ public ActionResult Get() } result = remoteIpAddress.ToString(); } - Debug.WriteLine(remoteIpAddress.ToString()); + Console.WriteLine(remoteIpAddress.ToString()); if (result.ToString() == "127.0.0.1") return Ok("request with localhost"); return Ok(_geoIpAddressResolver.ResolveAddress(IPAddress.Parse(result.ToString()))); - // return new string[] { "value1", "value2" }; } - + #endregion } + } diff --git a/src/Services/on-tracker/O2NextGen.OnTracker.Api/Controllers/VersionController.cs b/src/Services/on-tracker/O2NextGen.OnTracker.Api/Controllers/VersionController.cs index bbef0412..88873b56 100644 --- a/src/Services/on-tracker/O2NextGen.OnTracker.Api/Controllers/VersionController.cs +++ b/src/Services/on-tracker/O2NextGen.OnTracker.Api/Controllers/VersionController.cs @@ -1,20 +1,52 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; - -// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 +using Microsoft.Extensions.Logging; namespace O2NextGen.OnTracker.Api.Controllers { - public class VersionController : Controller + [AllowAnonymous] + public class VersionController : ControllerBase { - // GET: // - public IActionResult Index() + #region Fields + + private readonly IWebHostEnvironment _environment; + private readonly ILogger _logger; + + #endregion + + + #region Ctors + + public VersionController(IWebHostEnvironment environment, ILogger logger) { - return View(); + _environment = environment; + _logger = logger; } + + #endregion + + + #region Methods + + [HttpGet("[controller]")] + public object Index() + { + var exVersion = Assembly.GetExecutingAssembly().GetName().Version; + _logger.LogInformation($"get version - {exVersion}"); + return new + { + Environment = _environment.EnvironmentName, + Version = exVersion.ToString() + }; + } + + #endregion } }