diff --git a/server/AyaNova/Controllers/LicenseController.cs b/server/AyaNova/Controllers/LicenseController.cs index 36e22a32..cc1a0e63 100644 --- a/server/AyaNova/Controllers/LicenseController.cs +++ b/server/AyaNova/Controllers/LicenseController.cs @@ -148,8 +148,8 @@ namespace AyaNova.Api.Controllers /// /// /// HTTP 204 No Content result code on success or fail code with explanation - [HttpPost("trialrequest")] - public async Task RequestTrial([FromBody] dtoRequestTrial requestData) + [HttpPost("trialRequest")] + public async Task RequestTrial([FromBody] RequestTrial trialRequest) { if (serverState.IsClosed) return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); @@ -175,7 +175,7 @@ namespace AyaNova.Api.Controllers } //Send the request to RockFish here (or at least start the job to do it in which case return Accepted instead of no content and update comment above) - var ret = await Core.License.RequestTrialAsync(requestData.EmailAddress, requestData.RegisteredTo, log); + var ret = await Core.License.RequestTrialAsync(trialRequest, log); //Log await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseTrialRequest), ct); diff --git a/server/AyaNova/util/License.cs b/server/AyaNova/util/License.cs index 679905d3..89d1550c 100644 --- a/server/AyaNova/util/License.cs +++ b/server/AyaNova/util/License.cs @@ -13,6 +13,7 @@ using Microsoft.EntityFrameworkCore; //JSON KEY using Org.BouncyCastle.Security; using Org.BouncyCastle.OpenSsl; +using Newtonsoft.Json; @@ -27,8 +28,11 @@ namespace AyaNova.Core { //License server address - // private const string LICENSE_SERVER_URL = "https://rockfish.ayanova.com/"; +#if (DEBUG) private const string LICENSE_SERVER_URL = "http://localhost:3001/"; +#else + private const string LICENSE_SERVER_URL = "https://rockfish.ayanova.com/"; +#endif //Unlicensed token private const string UNLICENSED_TOKEN = "UNLICENSED"; @@ -436,20 +440,28 @@ namespace AyaNova.Core /// Request a key /// /// Result string - internal static async Task RequestTrialAsync(string email, string regto, ILogger log) + internal static async Task RequestTrialAsync(RequestTrial trialRequest, ILogger log) { Microsoft.AspNetCore.Http.Extensions.QueryBuilder q = new Microsoft.AspNetCore.Http.Extensions.QueryBuilder(); - q.Add("dbid", LicenseDbId.ToString()); - q.Add("email", email); - q.Add("regto", regto); + trialRequest.DbId = ServerDbId; log.LogDebug($"Requesting trial license for DBID {LicenseDbId.ToString()}"); string sUrl = $"{LICENSE_SERVER_URL}rvr" + q.ToQueryString(); try { - var res = await ServiceProviderProvider.HttpClientFactory.CreateClient().GetStringAsync(sUrl); - return res; + // var content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json"); + // var result = client.PostAsync(url, content).Result; + + var content = new StringContent(JsonConvert.SerializeObject(trialRequest), Encoding.UTF8, "application/json"); + + var client = ServiceProviderProvider.HttpClientFactory.CreateClient(); + var res = await client.PostAsync(sUrl, content); + if (res.IsSuccessStatusCode) + { + return "ok"; + } + else return res.Content.ToString(); } catch (Exception ex) { @@ -478,7 +490,7 @@ namespace AyaNova.Core //FUTURE: if there is any kind of error response or REASON or LicenseFetchStatus then here is //where to deal with it //todo: key should hang off json data object as text version of key - //that way we can put other objects on the data return object + //that way we can put other objects on the data return object AyaNovaLicenseKey ParsedKey = Parse(RawTextKeyFromRockfish, log); if (ParsedKey != null)