From 9b467d9152632bda4d1e03e992a68142c5ab563b Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 11 Jun 2020 20:15:01 +0000 Subject: [PATCH] --- Controllers/RvfController.cs | 52 +++++++++++++++++------------------- Controllers/RvrController.cs | 44 +++++++++++++++++++++++++----- 2 files changed, 61 insertions(+), 35 deletions(-) diff --git a/Controllers/RvfController.cs b/Controllers/RvfController.cs index 5d11284..e520fb0 100644 --- a/Controllers/RvfController.cs +++ b/Controllers/RvfController.cs @@ -1,10 +1,7 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Authorization; using Microsoft.EntityFrameworkCore; using rockfishCore.Models; using rockfishCore.Util; @@ -25,8 +22,7 @@ namespace rockfishCore.Controllers [HttpGet("{dbid}")] public async Task Get([FromRoute] Guid dbid) - { - //this is called after a successful check says there is a key below so it's not hammered (in theory) + { if (!ModelState.IsValid) { return BadRequest(ModelState); @@ -81,32 +77,32 @@ namespace rockfishCore.Controllers } - [HttpGet("hello/{dbid}")] - public ActionResult Hello([FromRoute] Guid dbid) - { - //check to see if there is anything of note for this server like a new key or a message etc - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } + // [HttpGet("hello/{dbid}")] + // public ActionResult Hello([FromRoute] Guid dbid) + // { + // //check to see if there is anything of note for this server like a new key or a message etc + // if (!ModelState.IsValid) + // { + // return BadRequest(ModelState); + // } - //return a json object with results if anything to report + // //return a json object with results if anything to report - //This is to simulate the scenarios where there is no license to return - //either due to no current account / canceled or simply no license exists - //Changes here must be reflected in RAVEN Util.License.Fetch block - bool bTestStatusOtherThanOk = false; - if (bTestStatusOtherThanOk) - { - return Json(new { Status = "NONE", Reason = "No license" }); - //return Json(new {Status="Canceled", Reason="Non payment"}); - } - else - { - return Ok(RavenKeyFactory.GetRavenTestKey(dbid)); - } + // //This is to simulate the scenarios where there is no license to return + // //either due to no current account / canceled or simply no license exists + // //Changes here must be reflected in RAVEN Util.License.Fetch block + // bool bTestStatusOtherThanOk = false; + // if (bTestStatusOtherThanOk) + // { + // return Json(new { Status = "NONE", Reason = "No license" }); + // //return Json(new {Status="Canceled", Reason="Non payment"}); + // } + // else + // { + // return Ok(RavenKeyFactory.GetRavenTestKey(dbid)); + // } - } + // } diff --git a/Controllers/RvrController.cs b/Controllers/RvrController.cs index fa891f2..1a9e50b 100644 --- a/Controllers/RvrController.cs +++ b/Controllers/RvrController.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.EntityFrameworkCore; using rockfishCore.Models; using rockfishCore.Util; +using System.ComponentModel.DataAnnotations; namespace rockfishCore.Controllers { @@ -15,27 +16,56 @@ namespace rockfishCore.Controllers [Route("rvr")] public class RvrController : Controller //RAVEN trial license request { - private readonly rockfishContext _context; + private readonly rockfishContext ct; public RvrController(rockfishContext context) { - _context = context; + ct = context; } + public class dtoRequest + { + [Required] + public Guid DbId { get; set; } + [Required, EmailAddress] + public string Email { get; set; } + [Required] + public string Company { get; set; } + [Required] + public string Contact { get; set; } + } - [HttpGet] - public ActionResult Get([FromQuery] Guid dbid, [FromQuery] string email, [FromQuery] string regto) + [HttpPost] + public async Task Post([FromBody] dtoRequest r) { if (!ModelState.IsValid) { return BadRequest(ModelState); } - if (dbid == Guid.Empty) + if (r.DbId == Guid.Empty) { - return BadRequest("The requested DB ID was empty and not valid"); + return BadRequest("DBId invalid"); } + //can't do this if there is a purchased license with this dbid already + if (await ct.License.Where(z => z.DbId == r.DbId).AnyAsync()) + { + return BadRequest("E1000 - Can't trial; there is already a purchased license issued for this database ID"); + } + +//if there is an active trial then can't do this +var MustBeOlderThan=DateUtil.DateToEpoch(DateTime.Now.AddDays(-45)) +if (await ct.TrialRequest.Where(z => z.DbId == r.DbId && z.DtProcessed != null && z.DtProcessed < MustBeOlderThan).AnyAsync()) +{ + + // //is it a trial request + // var TrialRequest = await ct.TrialRequest.Where(z => z.DbId == dbid && z.DtFetched == null).FirstOrDefaultAsync(); + // LicenseKey = TrialRequest.Key; + // TrialRequest.DtFetched = DateUtil.NowAsEpoch(); + // await ct.SaveChangesAsync(); +} + //TODO: closer to release as ROCKFISH might change before then //Attempt to match customer by dbid if not then create new customer of trial type for the indicated dbid and regto @@ -46,7 +76,7 @@ namespace rockfishCore.Controllers //If it's a new customer or an existing one with non-matching email then send a verification email to the customer //When a response is spotted in email then Rockfish should see it and flag the customer as verified - //Probably some general purpose email Verify code would be helpful here as it would likely be useful for all manner of things + //Probably some general purpose email Verify code would be helpful here as it would likely be useful for all manner of things //When user releases trial in Rockfish a license key will be generated ready for the customers RAVEN to retrieve